Class: Tengine::Resource::Credential
- Inherits:
-
Object
- Object
- Tengine::Resource::Credential
- Includes:
- Mongoid::Document, Mongoid::Timestamps, Core::CollectionAccessible, Core::FindByName, Core::SelectableAttr, Core::Validation
- Defined in:
- lib/tengine/resource/credential.rb
Defined Under Namespace
Classes: AuthField
Constant Summary collapse
- SECRET_AUTH_VALUES_KEYS =
%w[password passphrase private_keys secret_access_key]
- AUTH_TYPE_KEY_TO_FIELDS =
{ # Net::SSHにはたくさんのオプションがあります # http://net-ssh.rubyforge.org/ssh/v2/api/classes/Net/SSH.html # {:username => "goku", :password =>"xxx"} :ssh_password => [ AuthField.new(:username, :string), AuthField.new(:password, :secret), ].freeze, # {:username => "goku", :private_keys =>"xxx", :passphrase => "xxxx"} :ssh_public_key => [ AuthField.new(:username , :string), AuthField.new(:private_keys, :text), AuthField.new(:passphrase , :secret, :optional => true), ].freeze, # {:username => "goku", :private_key_file =>"xxx", :passphrase => "xxxx"} :ssh_public_key_file => [ AuthField.new(:username , :string), AuthField.new(:private_key_file, :string), AuthField.new(:passphrase , :secret, :optional => true), ].freeze, }.freeze
- ALL_FILED_NAMES =
AUTH_TYPE_KEY_TO_FIELDS.values.flatten.map(&:name)
Class Method Summary collapse
Instance Method Summary collapse
- #connect(*args, &block) ⇒ Object
- #for_launch? ⇒ Boolean
- #launch_options(connect_options = {}) ⇒ Object
- #prepare_auth_values_default ⇒ Object
- #secure_auth_values ⇒ Object
- #validate_auth_values ⇒ Object
Class Method Details
.find_or_create_by_name!(attrs = {}, &block) ⇒ Object
148 149 150 151 152 |
# File 'lib/tengine/resource/credential.rb', line 148 def find_or_create_by_name!(attrs = {}, &block) result = self.where({:name => attrs[:name]}).first result ||= self.create!(attrs) result end |
Instance Method Details
#connect(*args, &block) ⇒ Object
143 144 145 |
# File 'lib/tengine/resource/credential.rb', line 143 def connect(*args, &block) raise NotImplementedError, "deprecated API" end |
#for_launch? ⇒ Boolean
135 136 137 |
# File 'lib/tengine/resource/credential.rb', line 135 def for_launch? raise NotImplementedError, "deprecated API" end |
#launch_options(connect_options = {}) ⇒ Object
139 140 141 |
# File 'lib/tengine/resource/credential.rb', line 139 def ( = {}) raise NotImplementedError, "deprecated API" end |
#prepare_auth_values_default ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/tengine/resource/credential.rb', line 119 def prepare_auth_values_default if auth_type_key hash = self.auth_values.stringify_keys! fields = AUTH_TYPE_KEY_TO_FIELDS[auth_type_key] fields.each do |field| if default_value = field.default hash[field.name] ||= default_value end end (ALL_FILED_NAMES - AUTH_TYPE_KEY_TO_FIELDS[auth_type_key].map(&:name)).each do |field_name| hash.delete(field_name) hash.delete(field_name.to_s) end end end |
#secure_auth_values ⇒ Object
48 49 50 51 52 53 |
# File 'lib/tengine/resource/credential.rb', line 48 def secure_auth_values if result = auth_values.stringify_keys! SECRET_AUTH_VALUES_KEYS.each{|key| result.delete(key)} end result end |
#validate_auth_values ⇒ Object
108 109 110 111 112 113 114 115 116 |
# File 'lib/tengine/resource/credential.rb', line 108 def validate_auth_values if auth_type_key hash = self.auth_values.stringify_keys! fields = AUTH_TYPE_KEY_TO_FIELDS[auth_type_key] fields.each do |field| field.validate(self, hash) end end end |