Sha256: 30d1c894828b868009c41d66be22f8f24950deda6db8c746e842b897f87bed6c

Contents?: true

Size: 1.48 KB

Versions: 20

Compression:

Stored size: 1.48 KB

Contents

require 'fog/openstack/models/collection'
require 'fog/openstack/identity/v2/models/ec2_credential'

module Fog
  module OpenStack
    class Identity
      class V2
        class Ec2Credentials < Fog::OpenStack::Collection
          model Fog::OpenStack::Identity::V2::Ec2Credential

          attribute :user

          def all(options = {})
            user_id = user ? user.id : nil

            options[:user_id] = user_id
            ec2_credentials = service.list_ec2_credentials(options)

            load_response(ec2_credentials, 'credentials')
          end

          def create(attributes = {})
            if user
              attributes[:user_id] ||= user.id
              attributes[:tenant_id] ||= user.tenant_id
            end

            super attributes
          end

          def destroy(access_key)
            ec2_credential = find_by_access_key(access_key)
            ec2_credential.destroy
          end

          def find_by_access_key(access_key)
            user_id = user ? user.id : nil

            ec2_credential =
              find { |ec2_cred| ec2_cred.access == access_key }

            unless ec2_credential
              response = service.get_ec2_credential(user_id, access_key)
              body = response.body['credential']
              body = body.merge 'service' => service

              ec2_credential = Fog::OpenStack::Identity::V2::EC2Credential.new(body)
            end

            ec2_credential
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 3 rubygems

Version Path
fog-openstack-1.1.3 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.1.2 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-fork-99 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.1.0 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.1.0.pre lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-apibank-1.0.102 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.11 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-apibank-1.0.101 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.10 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.9 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.8 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.7 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.6 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.5 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.4 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.3 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.2 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.1 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-1.0.0 lib/fog/openstack/identity/v2/models/ec2_credentials.rb
fog-openstack-0.3.1 lib/fog/openstack/identity/v2/models/ec2_credentials.rb