Class: Kontena::Machine::DigitalOcean::SshKeyManager
- Inherits:
-
Object
- Object
- Kontena::Machine::DigitalOcean::SshKeyManager
- Defined in:
- lib/kontena/machine/digital_ocean/ssh_key_manager.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #create(public_key) ⇒ Object
- #find_by_public_key(public_key) ⇒ Object
- #find_or_create_by_public_key(public_key) ⇒ Object
-
#initialize(token) ⇒ SshKeyManager
constructor
A new instance of SshKeyManager.
- #list ⇒ Object
Constructor Details
#initialize(token) ⇒ SshKeyManager
Returns a new instance of SshKeyManager.
9 10 11 |
# File 'lib/kontena/machine/digital_ocean/ssh_key_manager.rb', line 9 def initialize(token) @client = DropletKit::Client.new(access_token: token) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/kontena/machine/digital_ocean/ssh_key_manager.rb', line 6 def client @client end |
Instance Method Details
#create(public_key) ⇒ Object
21 22 23 |
# File 'lib/kontena/machine/digital_ocean/ssh_key_manager.rb', line 21 def create(public_key) client.ssh_keys.create(DropletKit::SSHKey.new(public_key: public_key, name: public_key.split(/\s+/).last)) end |
#find_by_public_key(public_key) ⇒ Object
13 14 15 |
# File 'lib/kontena/machine/digital_ocean/ssh_key_manager.rb', line 13 def find_by_public_key(public_key) list.find { |key| key.public_key == public_key } end |
#find_or_create_by_public_key(public_key) ⇒ Object
25 26 27 |
# File 'lib/kontena/machine/digital_ocean/ssh_key_manager.rb', line 25 def find_or_create_by_public_key(public_key) find_by_public_key(public_key) || create(public_key) end |
#list ⇒ Object
17 18 19 |
# File 'lib/kontena/machine/digital_ocean/ssh_key_manager.rb', line 17 def list client.ssh_keys.all.to_a end |