class Caco::Ssh::AuthorizedKeysAdd

Public Instance Methods

add_key(ctx, key:, identifier:, output:, **) click to toggle source
# File lib/caco/ssh/authorized_keys_add.rb, line 43
def add_key(ctx, key:, identifier:, output:, **)
  output << "#{key} #{identifier}\n"
  ctx[:created] = true
  ctx[:content] = output
end
change_key(ctx, key:, identifier:, output:, **) click to toggle source
# File lib/caco/ssh/authorized_keys_add.rb, line 37
def change_key(ctx, key:, identifier:, output:, **)
  output.gsub!(/^.*#{identifier}$/, "#{key} #{identifier}")
  ctx[:content] = output
end
check_user_ssh_authorized_keys(ctx, ssh_home:, user:, **) click to toggle source
# File lib/caco/ssh/authorized_keys_add.rb, line 68
def check_user_ssh_authorized_keys(ctx, ssh_home:, user:, **)
  ctx[:authorized_keys_path] = authorized_keys_path = "#{ssh_home}/authorized_keys"
  unless File.exist?(authorized_keys_path)
    FileUtils.touch(authorized_keys_path)
    File.chmod(0600, authorized_keys_path)
    begin
      FileUtils.chown user, nil, authorized_keys_path
    rescue Errno::EPERM
      true
    end
  else
    true
  end
end
check_user_ssh_folder(ctx, user:, user_home:, **) click to toggle source
# File lib/caco/ssh/authorized_keys_add.rb, line 59
def check_user_ssh_folder(ctx, user:, user_home:, **)
  ctx[:ssh_home] = ssh_home = "#{Caco.config.write_files_root}#{user_home}/.ssh"
  FileUtils.mkdir_p(ssh_home)
  File.chmod(0700, ssh_home)
  FileUtils.chown user, nil, ssh_home
rescue Errno::EPERM
  true
end