Object
Manage a user (gear/container) SSH authorized_keys file and entries
# File lib/openshift-origin-node/model/application_container_ext/ssh_authorized_keys.rb, line 21 def initialize(container, filename=nil) @container = container @username = container.uuid @filename = filename || @container.container_dir + "/.ssh/authorized_keys" # override for testing user = Etc.getpwnam('root') @owner = user.uid # root begin @group = Etc.getpwnam(@username).gid rescue ArgumentError => e @group = @@default_group end @mode = @@default_mode @lockfile = "/var/lock/oo-modify-ssh-keys.#{@username}" end
Bodies from environment.rb globals
Public: Append an SSH key to a users authorized_keys file
key_string - The String value of the ssh key. key_type - The String value of the key type ssh-(rsa|dss)). comment - The String value of the comment to append to the key.
Examples
add_key('AAAAB3NzaC1yc2EAAAADAQABAAABAQDE0DfenPIHn5Bq/...', 'ssh-rsa', 'example@example.com') # => nil
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/application_container_ext/ssh_authorized_keys.rb, line 61 def add_key(key_string, key_type=nil, comment=nil) #@container.logger.info "Adding new key #{key_string} #{key_type} #{comment}" comment = "" unless comment modify do |keys| keys[key_id(comment)] = key_entry(key_string, key_type, comment) end end
Bodies from environment.rb globals
Public: Append SSH keys to a users authorized_keys file
keys - An Array of keys
Examples
add_keys([{"content"=>'AAAAB3NzaC1yc2EAAAADAQABAAABAQDE0DfenPIHn5Bq/...', "type" => 'ssh-rsa', "comment" => 'example@example.com'}]) # => nil
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/application_container_ext/ssh_authorized_keys.rb, line 86 def add_keys(new_keys) #@container.logger.info "Adding these new keys #{new_keys}" modify do |keys| new_keys.each do |k| comment = k["comment"] || "" keys[key_id(comment)] = key_entry(k["content"], k["type"], comment) end end end
Public: Remove an SSH key from a users authorized_keys file
key_string - The String value of the ssh key. key_type - The String value of the key type ssh-(rsa|dss)). comment - The String value of the comment to append to the key.
Examples
remove_ssh_key('AAAAB3NzaC1yc2EAAAADAQABAAABAQDE0DfenPIHn5Bq/...', 'ssh-rsa', 'example@example.com') # => nil
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/application_container_ext/ssh_authorized_keys.rb, line 111 def remove_key(key_string, key_type=nil, comment=nil) modify do |keys| if comment keys.delete_if{ |k, v| v.end_with?(key_id(comment)) } else keys.delete_if{ |k,v| v.include?(key_string) } end end end
Public: Remove SSH keys from a users authorized_keys file
keys - An Array of keys
Examples
remove_keys([{"content"=>'AAAAB3NzaC1yc2EAAAADAQABAAABAQDE0DfenPIHn5Bq/...', "type" => 'ssh-rsa', "comment" => 'example@example.com'}]) # => nil
Returns nil on Success or raises on Failure
# File lib/openshift-origin-node/model/application_container_ext/ssh_authorized_keys.rb, line 134 def remove_keys(old_keys) modify do |keys| old_keys.each do |key| if key["comment"] keys.delete_if{ |k, v| v.end_with?(key_id(key["comment"])) } else keys.delete_if{ |k,v| v.include?(key["content"]) } end end end end
Public: Replace all of the SSH authorized_keys file entries
new_keys - an Array of Hashes, each containing
key => String, type => String comment => String
Examples:
k = [ {'key' => 'AAA...', 'type' => 'ssh-rsa', 'comment' => 'String' }, {'key' => 'bar...', 'type' => 'ssh-rsa', 'comment' => 'more' }, {'key' => 'AAA...', 'type' => 'ssh-rsa', 'comment' => 'String'}, ] replace_keys(k)
Returns: nil on Success
# File lib/openshift-origin-node/model/application_container_ext/ssh_authorized_keys.rb, line 171 def replace_keys(new_keys) modify do |keys| # remove all keys keys.delete_if{ |k, v| true } # add the new keys in new_keys.each do |key| id = key_id(key['comment']) entry = key_entry(key['key'], key['type'], key['comment']) keys[id] = entry end end end
Generated with the Darkfish Rdoc Generator 2.