Class: Asteroid::SSHKey

Inherits:
Object
  • Object
show all
Defined in:
lib/asteroid/ssh_key.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SSHKey



8
9
10
11
# File 'lib/asteroid/ssh_key.rb', line 8

def initialize(options = {})
  @id = options[:id]
  @name = options[:name]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/asteroid/ssh_key.rb', line 6

def id
  @id
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/asteroid/ssh_key.rb', line 6

def name
  @name
end

#ssh_pub_keyObject

Returns the value of attribute ssh_pub_key.



6
7
8
# File 'lib/asteroid/ssh_key.rb', line 6

def ssh_pub_key
  @ssh_pub_key
end

Class Method Details

.allObject



23
24
25
26
27
28
# File 'lib/asteroid/ssh_key.rb', line 23

def self.all
  keys = Provider.all.ssh_keys
  keys.map do |key|
    new id: key[:id], name: key[:name]
  end
end

.find(name) ⇒ Object



18
19
20
21
# File 'lib/asteroid/ssh_key.rb', line 18

def self.find(name)
  name = name.to_s
  all.select{|k| k.name == name}.first
end

Instance Method Details

#exists?Boolean



13
14
15
16
# File 'lib/asteroid/ssh_key.rb', line 13

def exists?
  names = self.class.all.map{|k| k.name }
  names.include? @name
end

#saveObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/asteroid/ssh_key.rb', line 30

def save
  if exists?
    puts "Key exists"
  else 
    Digitalocean::SshKey.create(
      name: @name, 
      ssh_pub_key: URI::escape(@ssh_pub_key)
    )
  end
end