Class: CpOraclecloud::SshKey
- Inherits:
-
Object
- Object
- CpOraclecloud::SshKey
- Extended by:
- ActiveModel::Naming
- Includes:
- ActiveModel::Conversion, ActiveModel::Validations
- Defined in:
- app/models/cp_oraclecloud/ssh_key.rb
Instance Attribute Summary collapse
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#id ⇒ Object
Returns the value of attribute id.
-
#key ⇒ Object
Returns the value of attribute key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#uri ⇒ Object
Returns the value of attribute uri.
Class Method Summary collapse
- .all ⇒ Object
- .connection ⇒ Object
- .create(params) ⇒ Object
- .delete(id) ⇒ Object
- .find_by_id(id) ⇒ Object
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ SshKey
constructor
A new instance of SshKey.
- #persisted? ⇒ Boolean
- #to_model ⇒ Object
- #to_s ⇒ Object
- #update(params) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ SshKey
Returns a new instance of SshKey.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 13 def initialize(attributes = {}) if !attributes[:name].blank? regex = attributes[:name].match(/\/.*\/(.*)/) if regex && regex.length > 1 clean_name = regex[1] attributes[:id] = clean_name attributes[:name] = clean_name end end attributes.each do |field, value| send("#{field}=", value) end end |
Instance Attribute Details
#enabled ⇒ Object
Returns the value of attribute enabled.
7 8 9 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 7 def enabled @enabled end |
#id ⇒ Object
Returns the value of attribute id.
7 8 9 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 7 def id @id end |
#key ⇒ Object
Returns the value of attribute key.
7 8 9 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 7 def key @key end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 7 def name @name end |
#uri ⇒ Object
Returns the value of attribute uri.
7 8 9 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 7 def uri @uri end |
Class Method Details
.all ⇒ Object
39 40 41 42 43 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 39 def self.all result = [] connection.ssh_keys.each { |k| result.push(CpOraclecloud::SshKey.new(k.attributes))} result end |
.connection ⇒ Object
69 70 71 72 73 74 75 76 77 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 69 def self.connection @connection ||= Fog::Compute.new( :provider => 'OracleCloud', :oracle_username => CpOraclecloud.username, :oracle_password => CpOraclecloud.password, :oracle_domain => CpOraclecloud.domain, :oracle_compute_api => CpOraclecloud.compute_api ) end |
.create(params) ⇒ Object
50 51 52 53 54 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 50 def self.create(params) connection.ssh_keys.create(:name => params[:name], :enabled => params[:enabled], :key => params[:key]) end |
.delete(id) ⇒ Object
65 66 67 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 65 def self.delete(id) connection.ssh_keys.get(id).destroy end |
.find_by_id(id) ⇒ Object
45 46 47 48 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 45 def self.find_by_id(id) data = connection.ssh_keys.get(id) CpOraclecloud::SshKey.new(data.attributes) end |
Instance Method Details
#persisted? ⇒ Boolean
35 36 37 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 35 def persisted? !id.blank? end |
#to_model ⇒ Object
31 32 33 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 31 def to_model self end |
#to_s ⇒ Object
27 28 29 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 27 def to_s name end |
#update(params) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'app/models/cp_oraclecloud/ssh_key.rb', line 56 def update(params) fog_key = self.class.connection.ssh_keys.get(id) [:name, :enabled, :key].each do |field| fog_key.attributes[field.to_sym] = params[field.to_sym] end fog_key.update end |