Sha256: 540fc6c4d73fe34c3c7f07f821a36944a9630b0399d04332035b84d6430356d5

Contents?: true

Size: 1.49 KB

Versions: 6

Compression:

Stored size: 1.49 KB

Contents

module Fog
  module OpenStack
    module Auth
      class CredentialsError < RuntimeError; end

      module Domain
        attr_accessor :domain

        def identity
          data = {}
          if !id.nil?
            data.merge!(to_h(:id))
          elsif !name.nil? && !domain.nil?
            data.merge!(to_h(:name))
            data[:domain] = @domain.identity
          else
            raise Fog::OpenStack::Auth::CredentialsError,
                  "#{self.class}: An Id, or a name with its domain, must be provided"
          end
          data
        end
      end

      Name = Struct.new(:id, :name)
      class Name
        def identity
          return to_h(:id) unless id.nil?
          return to_h(:name) unless name.nil?
          raise Fog::OpenStack::Auth::CredentialsError, "#{self.class}: No available id or name"
        end

        def to_h(var)
          {var => send(var).to_s}
        end
      end

      class DomainScope < Name
        def identity
          {:domain => super}
        end
      end

      class ProjectScope < Name
        include Fog::OpenStack::Auth::Domain

        def identity
          {:project => super}
        end
      end

      class User < Name
        include Fog::OpenStack::Auth::Domain

        attr_accessor :password

        def identity
          data = super
          raise CredentialsError, "#{self.class}: No password available" if password.nil?
          data.merge!(to_h(:password))
          {:user => data}
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
fog-openstack-1.1.3 lib/fog/openstack/auth/name.rb
fog-openstack-1.1.2 lib/fog/openstack/auth/name.rb
fog-openstack-fork-99 lib/fog/openstack/auth/name.rb
fog-openstack-1.1.0 lib/fog/openstack/auth/name.rb
fog-openstack-1.1.0.pre lib/fog/openstack/auth/name.rb
fog-openstack-1.0.11 lib/fog/openstack/auth/name.rb