Class: Kubeclient::GoogleApplicationDefaultCredentials

Inherits:
Object
  • Object
show all
Defined in:
lib/kubeclient/google_application_default_credentials.rb

Overview

Get a bearer token from the Google’s application default credentials.

Defined Under Namespace

Classes: GoogleDependencyError

Class Method Summary collapse

Class Method Details

.tokenObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/kubeclient/google_application_default_credentials.rb', line 10

def token
  begin
    require 'googleauth'
  rescue LoadError => e
    raise GoogleDependencyError,
          'Error requiring googleauth gem. Kubeclient itself does not include the ' \
          'googleauth gem. To support auth-provider gcp, you must include it in your ' \
          "calling application. Failed with: #{e.message}"
  end

  scopes = [
    'https://www.googleapis.com/auth/cloud-platform',
    'https://www.googleapis.com/auth/userinfo.email'
  ]

  authorization = Google::Auth.get_application_default(scopes)
  authorization.apply({})
  authorization.access_token
end