File: create_ec2_credential.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 (59 lines) | stat: -rw-r--r-- 1,755 bytes parent folder | download | duplicates (3)
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
module Fog
  module OpenStack
    class Identity
      class V2
        class Real
          ##
          # Create an EC2 credential for a user in a tenant.  Requires
          # administrator credentials.
          #
          # ==== Parameters
          # * user_id<~String>: The id of the user to create an EC2 credential
          #   for
          # * tenant_id<~String>: The id of the tenant to create the credential
          #   in
          #
          # ==== Returns
          # * response<~Excon::Response>:
          #   * body<~Hash>:
          #     * 'credential'<~Hash>: Created EC2 credential
          #       * 'access'<~String>: The access key
          #       * 'secret'<~String>: The secret key
          #       * 'user_id'<~String>: The user id
          #       * 'tenant_id'<~String>: The tenant id

          def create_ec2_credential(user_id, tenant_id)
            data = {'tenant_id' => tenant_id}

            request(
              :body    => Fog::JSON.encode(data),
              :expects => [200, 202],
              :method  => 'POST',
              :path    => "users/#{user_id}/credentials/OS-EC2"
            )
          end
        end

        class Mock
          def create_ec2_credential(user_id, tenant_id)
            response = Excon::Response.new
            response.status = 200

            data = {
              'access'    => Fog::Mock.random_hex(32),
              'secret'    => Fog::Mock.random_hex(32),
              'tenant_id' => tenant_id,
              'user_id'   => user_id,
            }

            self.data[:ec2_credentials][user_id][data['access']] = data

            response.body = {'credential' => data}

            response
          end
        end
      end
    end
  end
end