Sha256: 23f7461bd61ddaa45f62849cbbd4d9fed92010c13d2ce647cb0a4ec70d722073

Contents?: true

Size: 1.33 KB

Versions: 91

Compression:

Stored size: 1.33 KB

Contents

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

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

        attribute :user

        def all
          user_id = user ? user.id : nil

          ec2_credentials = service.list_ec2_credentials(user_id)

          load(ec2_credentials.body['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::EC2Credential.new(body)
          end

          ec2_credential
        end
      end
    end
  end
end

Version data entries

91 entries across 91 versions & 10 rubygems

Version Path
vagrant-cloudstack-1.1.0 vendor/bundle/gems/fog-1.22.1/lib/fog/openstack/models/identity/ec2_credentials.rb
fog-1.30.0 lib/fog/openstack/models/identity/ec2_credentials.rb
fog-1.29.0 lib/fog/openstack/models/identity/ec2_credentials.rb
fog-1.28.0 lib/fog/openstack/models/identity/ec2_credentials.rb
fog-1.27.0 lib/fog/openstack/models/identity/ec2_credentials.rb
fog-1.26.0 lib/fog/openstack/models/identity/ec2_credentials.rb
fog-1.25.0 lib/fog/openstack/models/identity/ec2_credentials.rb
nsidc-fog-1.24.1 lib/fog/openstack/models/identity/ec2_credentials.rb
fog-1.24.0 lib/fog/openstack/models/identity/ec2_credentials.rb
ns-fog-1.22.11 lib/fog/openstack/models/identity/ec2_credentials.rb
ns-fog-1.22.10 lib/fog/openstack/models/identity/ec2_credentials.rb
ns-fog-1.22.9 lib/fog/openstack/models/identity/ec2_credentials.rb
ns-fog-1.22.8 lib/fog/openstack/models/identity/ec2_credentials.rb
ns-fog-1.22.7 lib/fog/openstack/models/identity/ec2_credentials.rb
ns-fog-1.22.6 lib/fog/openstack/models/identity/ec2_credentials.rb
fog-1.23.0 lib/fog/openstack/models/identity/ec2_credentials.rb
ns-fog-1.22.4 lib/fog/openstack/models/identity/ec2_credentials.rb
ns-fog-1.22.3 lib/fog/openstack/models/identity/ec2_credentials.rb
ns-fog-1.22.2 lib/fog/openstack/models/identity/ec2_credentials.rb
fog-1.22.1 lib/fog/openstack/models/identity/ec2_credentials.rb