Class: Oceanarium::SSHKey
- Inherits:
-
Object
- Object
- Oceanarium::SSHKey
- Defined in:
- lib/oceanarium/resources/sshkey.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ssh_pub_key ⇒ Object
Returns the value of attribute ssh_pub_key.
Class Method Summary collapse
-
.all ⇒ Object
Core API.
- .create(name, key) ⇒ Object
- .destroy(id) ⇒ Object
- .find(id) ⇒ Object
- .update(id, key) ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
- #edit(key) ⇒ Object
-
#initialize(option, api_key, client_id) ⇒ SSHKey
constructor
A new instance of SSHKey.
-
#new(name, key) ⇒ Object
User API.
Constructor Details
#initialize(option, api_key, client_id) ⇒ SSHKey
Returns a new instance of SSHKey.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/oceanarium/resources/sshkey.rb', line 7 def initialize(option, api_key, client_id) if api_key.nil? || client_id.nil? raise 'No API key/client ID!' else if option.is_a?(Hash) @object = option else @object = Oceanarium::SSHKey.find(option) end if @object.nil? self.id = nil else self.id = @object['id'] self.name = @object['name'] self.ssh_pub_key = @object['ssh_pub_key'] end end end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/oceanarium/resources/sshkey.rb', line 5 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/oceanarium/resources/sshkey.rb', line 5 def name @name end |
#ssh_pub_key ⇒ Object
Returns the value of attribute ssh_pub_key.
5 6 7 |
# File 'lib/oceanarium/resources/sshkey.rb', line 5 def ssh_pub_key @ssh_pub_key end |
Class Method Details
.all ⇒ Object
Core API
48 49 50 51 52 53 54 55 |
# File 'lib/oceanarium/resources/sshkey.rb', line 48 def self.all # Returns all ssh keys in Array @request = Oceanarium::Request.new @get = @request.get('/ssh_keys/') if @get.parsed_response['status'] == 'OK' @get.parsed_response['ssh_keys'] end end |
.create(name, key) ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/oceanarium/resources/sshkey.rb', line 57 def self.create(name, key) # Creates ssh_key @request = Oceanarium::Request.new @get = @request.get(URI::encode("/ssh_keys/new?name=#{name}&ssh_pub_key=#{key}")) if @get.parsed_response['status'] == 'OK' @get.parsed_response['ssh_key']['id'] else @get.parsed_response['status'] end end |
.destroy(id) ⇒ Object
86 87 88 89 90 91 |
# File 'lib/oceanarium/resources/sshkey.rb', line 86 def self.destroy(id) # Destroys ssh key @request = Oceanarium::Request.new @get = @request.get("/ssh_keys/#{id}/destroy") @get.parsed_response['status'] end |
.find(id) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/oceanarium/resources/sshkey.rb', line 68 def self.find(id) # Returns ssh key @request = Oceanarium::Request.new @get = @request.get("/ssh_keys/#{id}/") if @get.parsed_response['status'] == 'OK' @get.parsed_response['ssh_key'] end end |
.update(id, key) ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/oceanarium/resources/sshkey.rb', line 77 def self.update(id, key) # Updates ssh key @request = Oceanarium::Request.new @get = @request.get(URI::encode("/ssh_keys/#{id}/edit?ssh_key_pub=#{key}")) if @get.parsed_response['status'] == 'OK' @get.parsed_response['ssh_key'] end end |
Instance Method Details
#destroy ⇒ Object
42 43 44 |
# File 'lib/oceanarium/resources/sshkey.rb', line 42 def destroy Oceanarium::SSHKey.destroy(self.id) end |
#edit(key) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/oceanarium/resources/sshkey.rb', line 35 def edit(key) @update = Oceanarium::SSHKey.update(self.id, key) unless @update.nil? Oceanarium::ssh_key(self.id) end end |
#new(name, key) ⇒ Object
User API
28 29 30 31 32 33 |
# File 'lib/oceanarium/resources/sshkey.rb', line 28 def new(name, key) @new_id = Oceanarium::SSHKey.create(name, key) unless @new_id == 'ERROR' Oceanarium::ssh_key(@new_id) end end |