File: get_federation_token.rb

package info (click to toggle)
ruby-fog-aws 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,816 kB
  • sloc: ruby: 68,587; makefile: 6
file content (62 lines) | stat: -rw-r--r-- 2,467 bytes parent folder | download | duplicates (5)
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
module Fog
  module AWS
    class STS
      class Real
        require 'fog/aws/parsers/sts/get_session_token'

        # Get federation token
        #
        # ==== Parameters
        # * name<~String>: The name of the federated user.
        #                  Minimum length of 2. Maximum length of 32.
        # * policy<~String>: Optional policy that specifies the permissions
        #                    that are granted to the federated user
        #                    Minimum length of 1. Maximum length of 2048.
        # * duration<~Integer>: Optional duration, in seconds, that the session
        #                       should last.
        # ==== Returns
        # * response<~Excon::Response>:
        #   * body<~Hash>:
        #     * 'SessionToken'<~String> -
        #     * 'SecretAccessKey'<~String> -
        #     * 'Expiration'<~String> -
        #     * 'AccessKeyId'<~String> -
        #     * 'Arn'<~String> -
        #     * 'FederatedUserId'<~String> -
        #     * 'PackedPolicySize'<~String> -
        #     * 'RequestId'<~String> - Id of the request
        #
        # ==== See Also
        # http://docs.aws.amazon.com/STS/latest/APIReference/API_GetFederationToken.html

        def get_federation_token(name, policy, duration=43200)
          request({
            'Action'          => 'GetFederationToken',
            'Name'            => name,
            'Policy'          => Fog::JSON.encode(policy),
            'DurationSeconds' => duration,
            :idempotent       => true,
            :parser           => Fog::Parsers::AWS::STS::GetSessionToken.new
          })
        end
      end
      class Mock
        def get_federation_token(name, policy, duration=43200)
          Excon::Response.new.tap do |response|
            response.status = 200
            response.body = {
            'SessionToken'     => Fog::Mock.random_base64(580),
            'SecretAccessKey'  => Fog::Mock.random_base64(40),
            'Expiration'       => (DateTime.now + duration).strftime('%FT%TZ'),
            'AccessKeyId'      => Fog::AWS::Mock.key_id(20),
            'Arn'              => "arn:aws:sts::#{Fog::AWS::Mock.owner_id}:federated-user/#{name}",
            'FederatedUserId'  => "#{Fog::AWS::Mock.owner_id}:#{name}",
            'PackedPolicySize' => Fog::Mock.random_numbers(2),
            'RequestId'        => Fog::AWS::Mock.request_id
            }
          end
        end
      end
    end
  end
end