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

    the IAM selector.

  • token

    the IAM token.

Raises:

  • (TypeError)


47
48
49
50
51
52
# File 'lib/googleauth/iam.rb', line 47

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) ⇒ Object

Returns a clone of a_hash updated with the authoriation header



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

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

#apply!(a_hash) ⇒ Object

Adds the credential fields to the hash.



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

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

#updater_procObject

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



70
71
72
# File 'lib/googleauth/iam.rb', line 70

def updater_proc
  lambda(&method(:apply))
end