Class: CloudInteractor::Authentication
- Inherits:
-
Object
- Object
- CloudInteractor::Authentication
- Defined in:
- lib/cloud_interactor/authentication.rb
Instance Method Summary collapse
- #auth_service(interaction_class) ⇒ Object
-
#initialize(auth_hash, options = {}) ⇒ Authentication
constructor
A new instance of Authentication.
- #parse_cloud_hash ⇒ Object
- #parse_dns_cloud_hash(cloud_hash) ⇒ Object
- #parse_interaction_class(interaction_class, except_keys = []) ⇒ Object
Constructor Details
#initialize(auth_hash, options = {}) ⇒ Authentication
Returns a new instance of Authentication.
4 5 6 7 |
# File 'lib/cloud_interactor/authentication.rb', line 4 def initialize auth_hash, ={} @auth_hash = auth_hash @options = end |
Instance Method Details
#auth_service(interaction_class) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/cloud_interactor/authentication.rb', line 9 def auth_service interaction_class interaction_class, except_keys = parse_interaction_class(interaction_class) classes_to_inject = interaction_class.split('::') classes_to_inject = classes_to_inject.map { |str| str.camelcase } cloud_hash = parse_cloud_hash if interaction_class == 'DNS' cloud_hash = parse_dns_cloud_hash cloud_hash end Fog.class_eval(classes_to_inject.join('::')).new(cloud_hash.delete_if { |key, value| except_keys.flatten.include?(key) }) end |
#parse_cloud_hash ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cloud_interactor/authentication.rb', line 53 def parse_cloud_hash case @options['preferred_cloud'] when 'rackspace' { provider: 'Rackspace', rackspace_username: @auth_hash['cloud_authentication'][@options['preferred_cloud']]['username'], rackspace_api_key: @auth_hash['cloud_authentication'][@options['preferred_cloud']]['api_key'], version: :v2, rackspace_region: @options['preferred_cloud_region'].to_sym, connection_options: {} } when 'digitalocean' { provider: 'DigitalOcean', digitalocean_token: @auth_hash['cloud_authentication'][@options['preferred_cloud']]['api_key'], version: :v2 } else raise "CloudInteractor Does not currently support #{ @options['preferred_cloud'] } at this time" end end |
#parse_dns_cloud_hash(cloud_hash) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/cloud_interactor/authentication.rb', line 74 def parse_dns_cloud_hash cloud_hash if @options['route_dns_changes_via'] == @options['preferred_cloud'] cloud_hash else case @options['route_dns_changes_via'] when 'rackspace' cloud_hash when 'dnsimple' { provider: 'dnsimple', dnsimple_email: @auth_hash['cloud_authentication'][@options['route_dns_changes_via']]['email'], dnsimple_password: @auth_hash['cloud_authentication'][@options['route_dns_changes_via']]['password'], dnsimple_token: @auth_hash['cloud_authentication'][@options['route_dns_changes_via']]['token'] } else raise "CloudInteractor does not currently support #{ @options['route_dns_changes_via'] } as a DNS creation provider at this time" end end end |
#parse_interaction_class(interaction_class, except_keys = []) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/cloud_interactor/authentication.rb', line 24 def parse_interaction_class interaction_class, except_keys = [] return_class = case interaction_class.downcase when 'volume' case @options['preferred_cloud'] when 'rackspace' except_keys << [:provider, :version] 'Rackspace::BlockStorage' else raise "CloudInteractor Does not currently support this #{ @options['preferred_cloud'] }'s' volume creation at this time" end when 'dns' case @options['route_dns_changes_via'] when 'rackspace' except_keys << [:version, :rackspace_region] interaction_class else except_keys << [:version] interaction_class end else interaction_class end [return_class, except_keys.flatten] end |