purpose:
for user build their infos when installing compassci
- store my_info to ES
- write my_info to default/lab yaml file
if not, job will fail for verification problems for user private environment
Signed-off-by: Luan Shengde <shdluan(a)163.com>
---
lib/build_my_info_client.rb | 79 +++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
create mode 100755 lib/build_my_info_client.rb
diff --git a/lib/build_my_info_client.rb b/lib/build_my_info_client.rb
new file mode 100755
index 0000000..e4a4335
--- /dev/null
+++ b/lib/build_my_info_client.rb
@@ -0,0 +1,79 @@
+#!/usr/bin/env ruby
+# SPDX-License-Identifier: MulanPSL-2.0+
+# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved.
+# frozen_string_literal: true
+
+require 'json'
+require 'fileutils'
+require 'io/console'
+require_relative '../lib/es_client'
+
+# purpose:
+# build my_info
+# store my_info to ES
+# write my_info to default/lab yaml file
+# for user install compass-ci at their local server
+# user meet verification problems when submit jobs
+# add calling in installing script to meet the verification function
+# usage:
+# require_relative 'build_my_info_client'
+#
+# build_my_info = BuildMyInfo.new(email, name, lab)
+# build_my_info.config_my_info
+class BuildMyInfo
+ def initialize(my_email, my_name, lab)
+ @lab = lab || 'z9'
+ @my_info = {
+ 'my_email' => my_email,
+ 'my_name' => my_name,
+ 'my_token' => %x(uuidgen).chomp
+ }
+ end
+
+ def config_default_yaml
+ default_yaml_dir = "#{ENV['HOME']}/.config/compass-ci/defaults"
+ FileUtils.mkdir_p default_yaml_dir unless File.directory? default_yaml_dir
+ default_yaml_file = "#{default_yaml_dir}/account.yaml"
+ FileUtils.touch(default_yaml_file) unless File.exist? default_yaml_file
+
+ default_yaml_info = YAML.load_file(default_yaml_file) || {}
+ default_yaml_info['my_email'] = @my_info['my_email']
+ default_yaml_info['my_name'] = @my_info['my_name']
+
+ File.open(default_yaml_file, 'w') do |f|
+ f.puts default_yaml_info.to_yaml
+ end
+ end
+
+ def config_lab_yaml
+ lab_yaml_dir = "#{ENV['HOME']}/.config/compass-ci/include/lab"
+ FileUtils.mkdir_p lab_yaml_dir unless File.directory? lab_yaml_dir
+ lab_yaml_file = "#{lab_yaml_dir}/#{(a)lab}.yaml"
+ FileUtils.touch(lab_yaml_file) unless File.exist? lab_yaml_file
+
+ lab_yaml_info = YAML.load_file(lab_yaml_file) || {}
+ lab_yaml_info['my_token'] = @my_info['my_token']
+
+ File.open(lab_yaml_file, 'w') do |f|
+ f.puts lab_yaml_info.to_yaml
+ end
+ end
+
+ def complete_my_info
+ @my_info['my_login_name'] = ''
+ @my_info['my_commit_url'] = ''
+ @my_info['my_ssh_pubkey'] = []
+ end
+
+ def store_account_info
+ es = ESClient.new(index: 'accounts')
+ es.put_source_by_id(@my_info['my_email'], @my_info)
+ end
+
+ def config_my_info
+ config_default_yaml
+ config_lab_yaml
+ complete_my_info
+ store_account_info
+ end
+end
--
2.23.0