You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 26, 2022. It is now read-only.
Copy file name to clipboardExpand all lines: lib/backends/vault-backend.js
+23-9
Original file line number
Diff line number
Diff line change
@@ -53,6 +53,29 @@ class VaultBackend extends KVBackend {
53
53
this._clients.set(clientCacheKey,client)
54
54
}
55
55
56
+
// If we already have a cached token then inspect it...
57
+
if(client.token){
58
+
try{
59
+
this._logger.debug(`checking vault token expiry for role ${vaultRoleGet} on ${vaultMountPointGet}`)
60
+
consttokenStatus=awaitclient.tokenLookupSelf()
61
+
this._logger.debug(`vault token (role ${vaultRoleGet} on ${vaultMountPointGet}) valid for ${tokenStatus.data.ttl} seconds, renews at ${this._tokenRenewThreshold}`)
this._logger.debug(`renewing role ${vaultRoleGet} on ${vaultMountPointGet} vault token`)
66
+
if(!(awaitclient.tokenRenewSelf())){
67
+
this._logger.debug(`cached token renewal failed. Clearing cached token for role ${vaultRoleGet} on ${vaultMountPointGet}`)
68
+
client.token=null
69
+
}
70
+
}
71
+
}catch{
72
+
// If it can't be inspected/renewed, we clear the token.
73
+
this._logger.debug(`cached token operation failed. Clearing cached token for role ${vaultRoleGet} on ${vaultMountPointGet}`)
74
+
client.token=null
75
+
}
76
+
}
77
+
78
+
// If we don't have a token here we either never had one or we just failed to renew it, so get a new one by logging-in
56
79
if(!client.token){
57
80
constjwt=this._fetchServiceAccountToken()
58
81
this._logger.debug(`fetching new token from vault for role ${vaultRoleGet} on ${vaultMountPointGet}`)
@@ -61,15 +84,6 @@ class VaultBackend extends KVBackend {
61
84
role: vaultRoleGet,
62
85
jwt: jwt
63
86
})
64
-
}else{
65
-
this._logger.debug(`checking vault token expiry for role ${vaultRoleGet} on ${vaultMountPointGet}`)
66
-
consttokenStatus=awaitclient.tokenLookupSelf()
67
-
this._logger.debug(`vault token (role ${vaultRoleGet} on ${vaultMountPointGet}) valid for ${tokenStatus.data.ttl} seconds, renews at ${this._tokenRenewThreshold}`)
0 commit comments