[why] key my_uuid is renamed to my_token. key my_token will be stored in file: ~/.config/compass-ci/include/lab/${lab}.yaml
for this change with no sense: for old user(update account): keep my_uuid in the default yaml add my_token to ~/.config/compass-ci/include/lab/${lab}.yaml for new user: add my_email, my_name to the default yaml add my_token to ~/.config/compass-ci/include/lab/${lab}.yaml
Signed-off-by: Luan Shengde shdluan@163.com --- container/assign-account/get_account_info.rb | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/container/assign-account/get_account_info.rb b/container/assign-account/get_account_info.rb index 95bec14..7471c61 100755 --- a/container/assign-account/get_account_info.rb +++ b/container/assign-account/get_account_info.rb @@ -111,6 +111,7 @@ class AccountStorage
config_authorized_key(login_name) config_default_yaml(login_name) + config_lab_yaml(login_name) permit_login_config(login_name) if @data.key?('gen_sshkey') && @data['gen_sshkey'] my_jumper_pubkey = generate_ssh_key(login_name) @@ -162,11 +163,10 @@ class AccountStorage default_yaml = touch_default_yaml(login_name)
account_yaml = YAML.load_file(default_yaml) || {} - # my_email, my_name, my_uuid is required to config default yaml file + # my_email, my_name is required to config default yaml file # they are added along with 'my_ssh_pubkey' when sending assign account request account_yaml['my_email'] = @data['my_email'] account_yaml['my_name'] = @data['my_name'] - account_yaml['my_uuid'] = @data['my_uuid']
f = File.new(default_yaml, 'w') f.puts account_yaml.to_yaml @@ -174,6 +174,27 @@ class AccountStorage FileUtils.chown_R(login_name, login_name, "/home/#{login_name}/.config") end
+ def touch_lab_yaml(login_name) + lab_yaml_dir = File.join('/home', login_name, '.config/compass-ci/include/lab') + FileUtils.mkdir_p lab_yaml_dir unless File.exist? lab_yaml_dir + + lab_yaml = File.join(lab_yaml_dir, "#{@data['lab']}.yaml") + FileUtils.touch lab_yaml unless File.exist? lab_yaml + lab_yaml + end + + def config_lab_yaml(login_name) + lab_yaml = touch_lab_yaml(login_name) + + lab_yaml_info = YAML.load_file(lab_yaml) || {} + lab_yaml_info['my_token'] = @data['my_token'] + + f = File.new(lab_yaml, 'w') + f.puts lab_yaml_info.to_yaml + f.close + FileUtils.chown_R(login_name, login_name, "/home/#{login_name}/.config") + end + def config_authorized_key(login_name) pub_key = @data['my_ssh_pubkey'][0]
On Sat, Dec 12, 2020 at 09:51:09AM +0800, Luan Shengde wrote:
[why] key my_uuid is renamed to my_token. key my_token will be stored in file: ~/.config/compass-ci/include/lab/${lab}.yaml
for this change with no sense: for old user(update account): keep my_uuid in the default yaml add my_token to ~/.config/compass-ci/include/lab/${lab}.yaml for new user: add my_email, my_name to the default yaml add my_token to ~/.config/compass-ci/include/lab/${lab}.yaml
Signed-off-by: Luan Shengde shdluan@163.com
container/assign-account/get_account_info.rb | 25 ++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/container/assign-account/get_account_info.rb b/container/assign-account/get_account_info.rb index 95bec14..7471c61 100755 --- a/container/assign-account/get_account_info.rb +++ b/container/assign-account/get_account_info.rb @@ -111,6 +111,7 @@ class AccountStorage
config_authorized_key(login_name) config_default_yaml(login_name)
- config_lab_yaml(login_name) permit_login_config(login_name) if @data.key?('gen_sshkey') && @data['gen_sshkey'] my_jumper_pubkey = generate_ssh_key(login_name)
@@ -162,11 +163,10 @@ class AccountStorage default_yaml = touch_default_yaml(login_name)
account_yaml = YAML.load_file(default_yaml) || {}
- # my_email, my_name, my_uuid is required to config default yaml file
- # my_email, my_name is required to config default yaml file # they are added along with 'my_ssh_pubkey' when sending assign account request account_yaml['my_email'] = @data['my_email'] account_yaml['my_name'] = @data['my_name']
account_yaml['my_uuid'] = @data['my_uuid']
f = File.new(default_yaml, 'w') f.puts account_yaml.to_yaml
@@ -174,6 +174,27 @@ class AccountStorage FileUtils.chown_R(login_name, login_name, "/home/#{login_name}/.config") end
- def touch_lab_yaml(login_name)
- lab_yaml_dir = File.join('/home', login_name, '.config/compass-ci/include/lab')
- FileUtils.mkdir_p lab_yaml_dir unless File.exist? lab_yaml_dir
- lab_yaml = File.join(lab_yaml_dir, "#{@data['lab']}.yaml")
- FileUtils.touch lab_yaml unless File.exist? lab_yaml
- lab_yaml
- end
- def config_lab_yaml(login_name)
- lab_yaml = touch_lab_yaml(login_name)
- lab_yaml_info = YAML.load_file(lab_yaml) || {}
- lab_yaml_info['my_token'] = @data['my_token']
- f = File.new(lab_yaml, 'w')
- f.puts lab_yaml_info.to_yaml
- f.close
Use block to write a file.
Thanks, Xueliang
- FileUtils.chown_R(login_name, login_name, "/home/#{login_name}/.config")
- end
- def config_authorized_key(login_name) pub_key = @data['my_ssh_pubkey'][0]
-- 2.23.0
- lab_yaml_info['my_token'] = @data['my_token']
- f = File.new(lab_yaml, 'w')
- f.puts lab_yaml_info.to_yaml
- f.close
Use block to write a file.
OK, I will use block for it
Thanks, Luan Shengde
Thanks, Xueliang
- FileUtils.chown_R(login_name, login_name, "/home/#{login_name}/.config")
- end
- def config_authorized_key(login_name) pub_key = @data['my_ssh_pubkey'][0]
-- 2.23.0