Sha256: 077ebb658ea00956ec8b3b6e6795bc1d934790d95fce119c59db6d59f905667a

Contents?: true

Size: 1.51 KB

Versions: 17

Compression:

Stored size: 1.51 KB

Contents

require 'fog/openstack/models/collection'
require 'fog/openstack/models/identity_v2/ec2_credential'

module Fog
  module Identity
    class OpenStack
      class V2
        class Ec2Credentials < Fog::OpenStack::Collection
          model Fog::Identity::OpenStack::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 then
              attributes[:user_id] ||= user.id
              attributes[:tenant_id] ||= user.tenant_id
            end

            super attributes
          end

          def destroy(access_key)
            ec2_credential = self.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 =
                self.find { |ec2_credential| ec2_credential.access == access_key }

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

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

            ec2_credential
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
fog-openstack-0.1.10 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-openstack-0.1.9 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-openstack-0.1.8 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-openstack-0.1.7 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-openstack-0.1.6 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-openstack-0.1.5 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-openstack-0.1.4 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-openstack-0.1.3 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-openstack-0.1.2 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-openstack-0.1.1 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-openstack-0.1.0 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-1.37.0 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-1.36.0 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-1.35.0 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-2.0.0.pre.0 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-1.34.0 lib/fog/openstack/models/identity_v2/ec2_credentials.rb
fog-1.33.0 lib/fog/openstack/models/identity_v2/ec2_credentials.rb