lib/tengine/resource/credential.rb in tengine_resource-0.5.15 vs lib/tengine/resource/credential.rb in tengine_resource-1.1.0

- old
+ new

@@ -1,12 +1,10 @@ # -*- coding: utf-8 -*- require 'mongoid' require 'selectable_attr' class Tengine::Resource::Credential - autoload :Ec2, 'tengine/resource/credential/ec2' - include Mongoid::Document include Mongoid::Timestamps include Tengine::Core::SelectableAttr include Tengine::Core::CollectionAccessible include Tengine::Core::Validation @@ -22,26 +20,27 @@ # see http://github.com/akm/selectable_attr # http://github.com/akm/selectable_attr_rails # EC2での認証については以下などを参照してください。 # http://builder.japan.zdnet.com/member/u502383/blog/2008/08/08/entry_27012840/ selectable_attr :auth_type_cd do - entry "01", :ssh_password , "SSHパスワード認証" , :for_launch => false - entry "02", :ssh_public_key, "SSH公開鍵認証" , :for_launch => false - # entry "03", :ec2_access_key, "EC2 アクセスキー認証", :for_launch => true + entry "01", :ssh_password , "SSHパスワード認証" + entry "02", :ssh_public_key, "SSH公開鍵認証" + # entry "03", :ec2_access_key, "EC2 アクセスキー認証" # entry "04", :ec2_x509_cert, "EC2 X.509認証" - # entry "05", :tama, "Tama", :for_launch => true + # entry "05", :tama, "Tama" + entry "06", :ssh_public_key_file, "SSH公開鍵認証(ファイル)" end validates :name, :presence => true, :uniqueness => true, :format => BASE_NAME.options validates :auth_type_cd, :presence => true - index :name, :unique => true + index({ name: 1 }, { unique: true }) - index([ [:_id, Mongo::ASCENDING], [:auth_type_cd, Mongo::ASCENDING], ]) - index([ [:_id, Mongo::ASCENDING], [:auth_type_cd, Mongo::DESCENDING], ]) - index([ [:_id, Mongo::ASCENDING], [:description, Mongo::ASCENDING], ]) - index([ [:_id, Mongo::ASCENDING], [:description, Mongo::DESCENDING], ]) + index _id: 1, auth_type_cd: 1 + index _id: 1, auth_type_cd: -1 + index _id: 1, description: 1 + index _id: 1, description: -1 before_validation :prepare_auth_values_default # auth_valuesの各値がnilならデフォルト値を設定します validate{|c| c.validate_auth_values} SECRET_AUTH_VALUES_KEYS = %w[password passphrase private_keys secret_access_key] @@ -96,15 +95,15 @@ AuthField.new(:username , :string), AuthField.new(:private_keys, :text), AuthField.new(:passphrase , :secret, :optional => true), ].freeze, - # {:access_key => "xxxxx", :secret_access_key =>"xxxxx"} - :ec2_access_key => [ - AuthField.new(:access_key, :string), - AuthField.new(:secret_access_key, :string), - AuthField.new(:default_region, :string, :default => "us-east-1"), + # {: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 def validate_auth_values if auth_type_key @@ -145,10 +144,10 @@ raise NotImplementedError, "deprecated API" end class << self def find_or_create_by_name!(attrs = {}, &block) - result = self.first(:conditions => {:name => attrs[:name]}) + result = self.where({:name => attrs[:name]}).first result ||= self.create!(attrs) result end end