Sha256: 1a1e00a7319dfd0583b90ba43464990a0de548df800d081b0d9384957cb2c458

Contents?: true

Size: 1.48 KB

Versions: 39

Compression:

Stored size: 1.48 KB

Contents

require 'fog/openstack/models/collection'
require 'fog/identity/openstack/v2/models/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
              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::Identity::OpenStack::V2::EC2Credential.new(body)
            end

            ec2_credential
          end
        end
      end
    end
  end
end

Version data entries

39 entries across 37 versions & 3 rubygems

Version Path
fog-openstack-0.1.27 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-openstack-0.1.26/lib/fog/identity/openstack/v2/models/ec2_credentials.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-openstack-0.1.26/lib/fog/identity/openstack/v2/models/ec2_credentials.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-openstack-0.1.26/lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.26 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.25 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.24 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.23 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.22 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.21 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.20 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.19 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.18 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.17 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.15 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.14 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.13 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.12 lib/fog/identity/openstack/v2/models/ec2_credentials.rb
fog-openstack-0.1.11 lib/fog/identity/openstack/v2/models/ec2_credentials.rb