Class: Google::Auth::IAMCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/googleauth/iam.rb

Overview

Authenticates requests using IAM credentials.

Constant Summary collapse

SELECTOR_KEY =
"x-goog-iam-authority-selector".freeze
TOKEN_KEY =
"x-goog-iam-authorization-token".freeze

Instance Method Summary collapse

Constructor Details

#initialize(selector, token) ⇒ IAMCredentials

Initializes an IAMCredentials.

Parameters:

  • selector (String)

    The IAM selector.

  • token (String)

    The IAM token.

Raises:

  • (TypeError)

    If selector or token is not a String



33
34
35
36
37
38
# File 'lib/googleauth/iam.rb', line 33

def initialize selector, token
  raise TypeError unless selector.is_a? String
  raise TypeError unless token.is_a? String
  @selector = selector
  @token = token
end

Instance Method Details

#apply(a_hash) ⇒ Hash

Returns a clone of a_hash updated with the authorization header

Parameters:

  • a_hash (Hash)

    The hash to clone and update with credentials

Returns:

  • (Hash)

    A new hash with credentials



54
55
56
57
58
# File 'lib/googleauth/iam.rb', line 54

def apply a_hash
  a_copy = a_hash.clone
  apply! a_copy
  a_copy
end

#apply!(a_hash) ⇒ Hash

Adds the credential fields to the hash.

Parameters:

  • a_hash (Hash)

    The hash to update with credentials

Returns:

  • (Hash)

    The updated hash with credentials



44
45
46
47
48
# File 'lib/googleauth/iam.rb', line 44

def apply! a_hash
  a_hash[SELECTOR_KEY] = @selector
  a_hash[TOKEN_KEY] = @token
  a_hash
end

#updater_procProc

Returns a reference to the #apply method, suitable for passing as a closure

Returns:

  • (Proc)

    A procedure that updates a hash with credentials



64
65
66
# File 'lib/googleauth/iam.rb', line 64

def updater_proc
  proc { |a_hash, _opts = {}| apply a_hash }
end