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@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
- File.open("#{default_yaml_dir}/#{account}.yaml", 'a') do |file|
#{account} => account
I mean literal 'account.yaml'
Thanks, Fengguang
- %x(chown -R #{account}:#{account} "/home/#{account}/.config")
That function variable $account can better be $login_name
man ssh
-l login_name Specifies the user to log in as on the remote machine. This also may be specified on a per-host basis in the configuration file.
Thanks, Fengguang
On Tue, Nov 03, 2020 at 08:51:28AM +0800, Wu Fengguang wrote:
- File.open("#{default_yaml_dir}/#{account}.yaml", 'a') do |file|
#{account} => account
I mean literal 'account.yaml'
I got it
Thanks, Fengguang
- %x(chown -R #{account}:#{account} "/home/#{account}/.config")
That function variable $account can better be $login_name
I got it I will fix it later
Thanks Luan Shengde
man ssh
-l login_name Specifies the user to log in as on the remote machine. This also may be specified on a per-host basis in the configuration file.
Thanks, Fengguang