Skip to content
This repository has been archived by the owner on Jul 26, 2022. It is now read-only.

Commit

Permalink
Fix to vault-backend merge
Browse files Browse the repository at this point in the history
  • Loading branch information
megakid committed Sep 25, 2020
1 parent 07220a7 commit 6bb23f0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions lib/backends/vault-backend.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ class VaultBackend extends KVBackend {
* @returns {Promise} Promise object representing secret property values.
*/
async _get ({ key, specOptions: { vaultMountPoint = null, vaultRole = null, kvVersion = 2 } }) {
vaultMountPoint = vaultMountPoint || this._defaultVaultMountPoint
vaultRole = vaultRole || this._defaultVaultRole
const vaultMountPointGet = vaultMountPoint || this._defaultVaultMountPoint
const vaultRoleGet = vaultRole || this._defaultVaultRole
// Create cache key for auth specific client
const clientCacheKey = `|m${vaultMountPoint}|r${vaultRole}|`
const clientCacheKey = `|m${vaultMountPointGet}|r${vaultRoleGet}|`
// Lookup existing or create new vault client
let client = this._clients.get(clientCacheKey)
if (!client) {
Expand All @@ -55,19 +55,19 @@ class VaultBackend extends KVBackend {

if (!client.token) {
const jwt = this._fetchServiceAccountToken()
this._logger.debug(`fetching new token from vault for role ${vaultRole} on ${vaultMountPoint}`)
this._logger.debug(`fetching new token from vault for role ${vaultRoleGet} on ${vaultMountPointGet}`)
await client.kubernetesLogin({
mount_point: vaultMountPoint,
role: vaultRole,
mount_point: vaultMountPointGet,
role: vaultRoleGet,
jwt: jwt
})
} else {
this._logger.debug(`checking vault token expiry for role ${vaultRole} on ${vaultMountPoint}`)
this._logger.debug(`checking vault token expiry for role ${vaultRoleGet} on ${vaultMountPointGet}`)
const tokenStatus = await client.tokenLookupSelf()
this._logger.debug(`vault token (role ${vaultRole} on ${vaultMountPoint}) valid for ${tokenStatus.data.ttl} seconds, renews at ${this._tokenRenewThreshold}`)
this._logger.debug(`vault token (role ${vaultRoleGet} on ${vaultMountPointGet}) valid for ${tokenStatus.data.ttl} seconds, renews at ${this._tokenRenewThreshold}`)

if (Number(tokenStatus.data.ttl) <= this._tokenRenewThreshold) {
this._logger.debug(`renewing role ${vaultRole} on ${vaultMountPoint} vault token`)
this._logger.debug(`renewing role ${vaultRoleGet} on ${vaultMountPointGet} vault token`)
await client.tokenRenewSelf()
}
}
Expand Down

0 comments on commit 6bb23f0

Please sign in to comment.