Sha256: c9c3e09e3f61fd1d15a48ea6d0269d2b7341f1533a7c0c8b270a0a7fe25a49c5

Contents?: true

Size: 1.82 KB

Versions: 21

Compression:

Stored size: 1.82 KB

Contents

# Copyright 2015 Google, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require "googleauth/signet"
require "googleauth/credentials_loader"
require "multi_json"

module Google
  # Module Auth provides classes that provide Google-specific authorization
  # used to access Google APIs.
  module Auth
    # Authenticates requests using IAM credentials.
    class IAMCredentials
      SELECTOR_KEY = "x-goog-iam-authority-selector".freeze
      TOKEN_KEY = "x-goog-iam-authorization-token".freeze

      # Initializes an IAMCredentials.
      #
      # @param selector the IAM selector.
      # @param token the IAM token.
      def initialize selector, token
        raise TypeError unless selector.is_a? String
        raise TypeError unless token.is_a? String
        @selector = selector
        @token = token
      end

      # Adds the credential fields to the hash.
      def apply! a_hash
        a_hash[SELECTOR_KEY] = @selector
        a_hash[TOKEN_KEY] = @token
        a_hash
      end

      # Returns a clone of a_hash updated with the authoriation header
      def apply a_hash
        a_copy = a_hash.clone
        apply! a_copy
        a_copy
      end

      # Returns a reference to the #apply method, suitable for passing as
      # a closure
      def updater_proc
        proc { |a_hash, _opts = {}| apply a_hash }
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
googleauth-1.11.2 lib/googleauth/iam.rb
googleauth-1.11.1 lib/googleauth/iam.rb
googleauth-1.11.0 lib/googleauth/iam.rb
googleauth-1.10.0 lib/googleauth/iam.rb
googleauth-1.9.2 lib/googleauth/iam.rb
googleauth-1.9.1 lib/googleauth/iam.rb
googleauth-1.8.1 lib/googleauth/iam.rb
googleauth-1.8.0 lib/googleauth/iam.rb
googleauth-1.7.0 lib/googleauth/iam.rb
googleauth-1.6.0 lib/googleauth/iam.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/googleauth-1.5.2/lib/googleauth/iam.rb
googleauth-1.5.2 lib/googleauth/iam.rb
googleauth-1.5.1 lib/googleauth/iam.rb
googleauth-1.5.0 lib/googleauth/iam.rb
googleauth-1.3.0 lib/googleauth/iam.rb
googleauth-1.2.0 lib/googleauth/iam.rb
googleauth-1.1.3 lib/googleauth/iam.rb
googleauth-1.1.2 lib/googleauth/iam.rb
googleauth-1.1.1 lib/googleauth/iam.rb
googleauth-1.1.0 lib/googleauth/iam.rb