File: name.rb

package info (click to toggle)
ruby-fog-openstack 1.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,784 kB
  • sloc: ruby: 47,937; makefile: 5; sh: 4
file content (65 lines) | stat: -rw-r--r-- 1,530 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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