add new function to config default yaml file
[why]:
easier for user to config the default yaml file
[how]:
when get request data, parse the data and write the user infos to
default yaml file: ~/.config/compass-ci/default/account.yaml
include:
- my_email
- my_name
- my_uuid
Signed-off-by: Luan Shengde <luanshengde2(a)huawei.com>
---
container/assign-account/get_account_info.rb | 18 +++++++++++++++++-
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/container/assign-account/get_account_info.rb b/container/assign-account/get_account_info.rb
index 2f93d5b..ae55dcb 100755
--- a/container/assign-account/get_account_info.rb
+++ b/container/assign-account/get_account_info.rb
@@ -44,6 +44,8 @@ the returned data for setup_jumper_account_info like:
=end
+require 'fileutils'
+
# get jumper and account info
class AccountStorage
ACCOUNT_DIR = '/opt/account_data/'
@@ -93,7 +95,7 @@ class AccountStorage
def setup_jumper_account_info
account_info = read_account_info
jumper_info = read_jumper_info
- pub_key = @data['pub_key'] unless @data.nil?
+ pub_key = @data['my_ssh_pubkey'] unless @data['my_ssh_pubkey'].nil?
jumper_ip = jumper_info[0].chomp
jumper_port = jumper_info[1].chomp
@@ -111,9 +113,23 @@ class AccountStorage
}
setup_authorized_key(account, pub_key)
+ setup_default_yaml(account)
+
return jumper_account_info
end
+ def setup_default_yaml(account)
+ default_yaml_dir = File.join('/home', account, '.config/compass-ci/defaults')
+ FileUtils.mkdir_p default_yaml_dir
+
+ File.open("#{default_yaml_dir}/#{account}.yaml", 'a') do |file|
+ file.puts "my_email: #{@data['my_email']}"
+ file.puts "my_name: #{@data['my_name']}"
+ file.puts "my_uuid: #{@data['my_uuid']}"
+ end
+ %x(chown -R #{account}:#{account} "/home/#{account}/.config")
+ end
+
def setup_authorized_key(account, pub_key)
ssh_dir = File.join('/home/', account, '.ssh')
Dir.mkdir ssh_dir, 0o700
--
2.23.0