Class: KubernetesDeploy::KubeclientBuilder::GoogleFriendlyConfig

Inherits:
Kubeclient::Config
  • Object
show all
Defined in:
lib/kubernetes-deploy/kubeclient_builder/google_friendly_config.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.read(filename) ⇒ Object



15
16
17
# File 'lib/kubernetes-deploy/kubeclient_builder/google_friendly_config.rb', line 15

def self.read(filename)
  new(YAML.load_file(filename), File.dirname(filename))
end

Instance Method Details

#fetch_user_auth_options(user) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/kubernetes-deploy/kubeclient_builder/google_friendly_config.rb', line 7

def fetch_user_auth_options(user)
  if user.dig('auth-provider', 'name') == 'gcp'
    { bearer_token: new_token }
  else
    super
  end
end

#new_tokenObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kubernetes-deploy/kubeclient_builder/google_friendly_config.rb', line 19

def new_token
  scopes = ['https://www.googleapis.com/auth/cloud-platform']
  authorization = Google::Auth.get_application_default(scopes)

  authorization.apply({})

  authorization.access_token

rescue Signet::AuthorizationError => e
  err_message = json_error_message(e.response.body) || e.message
  raise KubeException.new(e.response.status, err_message, e.response.body)
end