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.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/oceanarium/resources/sshkey.rb', line 8 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.
6 7 8 |
# File 'lib/oceanarium/resources/sshkey.rb', line 6 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/oceanarium/resources/sshkey.rb', line 6 def name @name end |
#ssh_pub_key ⇒ Object
Returns the value of attribute ssh_pub_key.
6 7 8 |
# File 'lib/oceanarium/resources/sshkey.rb', line 6 def ssh_pub_key @ssh_pub_key end |
Class Method Details
.all ⇒ Object
Core API
49 50 51 52 53 54 55 56 |
# File 'lib/oceanarium/resources/sshkey.rb', line 49 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
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/oceanarium/resources/sshkey.rb', line 58 def self.create(name, key) # Creates ssh_key @request = Oceanarium::Request.new @get = @request.get("/ssh_keys/new?name=#{CGI::escape(name.to_s)}&ssh_pub_key=#{CGI::escape(key.to_s)}") if @get.parsed_response['status'] == 'OK' @get.parsed_response['ssh_key']['id'] else @get.parsed_response['status'] end end |
.destroy(id) ⇒ Object
87 88 89 90 91 92 |
# File 'lib/oceanarium/resources/sshkey.rb', line 87 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
69 70 71 72 73 74 75 76 |
# File 'lib/oceanarium/resources/sshkey.rb', line 69 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
78 79 80 81 82 83 84 85 |
# File 'lib/oceanarium/resources/sshkey.rb', line 78 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
43 44 45 |
# File 'lib/oceanarium/resources/sshkey.rb', line 43 def destroy Oceanarium::SSHKey.destroy(self.id) end |
#edit(key) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/oceanarium/resources/sshkey.rb', line 36 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
29 30 31 32 33 34 |
# File 'lib/oceanarium/resources/sshkey.rb', line 29 def new(name, key) @new_id = Oceanarium::SSHKey.create(name, key) unless @new_id == 'ERROR' Oceanarium::ssh_key(@new_id) end end |