blob: 89209ed8bfa52e7be35ece06841f407e08393766 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# frozen_string_literal: true
module Clusters
module Gcp
module Kubernetes
class FetchKubernetesTokenService
attr_reader :kubeclient, :namespace
def initialize(kubeclient, namespace)
@kubeclient = kubeclient
@namespace = namespace
end
def execute
token_base64 = get_secret&.dig('data', 'token')
Base64.decode64(token_base64) if token_base64
end
private
def get_secret
kubeclient.get_secret(service_account_token_name, namespace).as_json
rescue Kubeclient::HttpError => err
raise err unless err.error_code == 404
nil
end
def service_account_token_name
SERVICE_ACCOUNT_TOKEN_NAME
end
end
end
end
end
|