-
Notifications
You must be signed in to change notification settings - Fork 0
/
gke.clj
34 lines (28 loc) · 978 Bytes
/
gke.clj
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
(ns clj-k8s.gke
(:import (com.google.auth.oauth2 GoogleCredentials)
(java.util List)))
;;; =====================================
;;; Google Kubernetes Engine
;;; ====================================
;;; See: https://developers.google.com/identity/protocols/googlescopes#containerv1
(defonce gke-scopes
["https://www.googleapis.com/auth/cloud-platform"])
(def ^GoogleCredentials creds
(delay
(let [app-creds (GoogleCredentials/getApplicationDefault)]
(if (.createScopedRequired app-creds)
(.createScoped app-creds ^List gke-scopes)
app-creds))))
(defn refresh-goog-token!
"Refresh the token by discarding the cached token and
metadata and requesting the new ones if expired"
[^GoogleCredentials creds]
(.refreshIfExpired creds)
creds)
(def get-google-access-token
"Fetches the google access token"
(fn []
(some-> @creds
refresh-goog-token!
.getAccessToken
.getTokenValue)))