node-vault-client 2.1.1 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/auth/VaultBaseAuth.js +40 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-vault-client",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.2",
|
|
4
4
|
"description": "A Vault Client implemented in pure javascript for HashiCorp Vault. It supports variety of Auth Backends and performs lease renewal for issued auth token.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "git+https://github.com/namecheap/node-vault-client.git"
|
|
@@ -38,8 +38,17 @@ class VaultBaseAuth {
|
|
|
38
38
|
this._log = logger;
|
|
39
39
|
this._mount = mount;
|
|
40
40
|
|
|
41
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The currently held token, or `null` when none has been obtained yet.
|
|
43
|
+
* @type {AuthToken|null}
|
|
44
|
+
*/
|
|
42
45
|
this.__authToken = null;
|
|
46
|
+
/**
|
|
47
|
+
* The in-flight login, or `null` when no login is running. Concurrent
|
|
48
|
+
* `getAuthToken()` callers await this same promise (single-flight).
|
|
49
|
+
* @type {Promise<AuthToken>|null}
|
|
50
|
+
*/
|
|
51
|
+
this.__pendingLogin = null;
|
|
43
52
|
this.__refreshTimeout = null;
|
|
44
53
|
}
|
|
45
54
|
|
|
@@ -52,7 +61,12 @@ class VaultBaseAuth {
|
|
|
52
61
|
}
|
|
53
62
|
|
|
54
63
|
getAuthToken() {
|
|
55
|
-
|
|
64
|
+
if (this.__pendingLogin !== null) {
|
|
65
|
+
this._log.debug('login already in flight');
|
|
66
|
+
return this.__pendingLogin;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const tokenExpired = this.__authToken !== null && this.__authToken.isExpired();
|
|
56
70
|
|
|
57
71
|
if (tokenExpired && !this._reauthenticationAllowed()) {
|
|
58
72
|
return Promise.reject(new errors.AuthTokenExpiredError(
|
|
@@ -60,32 +74,34 @@ class VaultBaseAuth {
|
|
|
60
74
|
));
|
|
61
75
|
}
|
|
62
76
|
|
|
63
|
-
if (this.__authToken
|
|
64
|
-
this._log.
|
|
77
|
+
if (this.__authToken !== null && !tokenExpired) {
|
|
78
|
+
this._log.debug('token already exist');
|
|
79
|
+
return Promise.resolve(this.__authToken);
|
|
80
|
+
}
|
|
65
81
|
|
|
66
|
-
|
|
67
|
-
this.__authToken = authToken;
|
|
82
|
+
this._log.info('getting auth token (mount=%s)', this._mount);
|
|
68
83
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
authToken.getAccessor()
|
|
73
|
-
);
|
|
74
|
-
this.__setupTokenRefreshTimer(this.__authToken);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
return this.__authToken;
|
|
78
|
-
}).catch(e => {
|
|
79
|
-
this.__authToken = null;
|
|
80
|
-
throw e;
|
|
81
|
-
});
|
|
84
|
+
const pendingLogin = this._authenticate().then(authToken => {
|
|
85
|
+
this.__pendingLogin = null;
|
|
86
|
+
this.__authToken = authToken;
|
|
82
87
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
88
|
+
if (authToken.isRenewable()) {
|
|
89
|
+
this._log.debug(
|
|
90
|
+
'setting refresh timer for token (accessor=%s)',
|
|
91
|
+
authToken.getAccessor()
|
|
92
|
+
);
|
|
93
|
+
this.__setupTokenRefreshTimer(authToken);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return authToken;
|
|
97
|
+
}).catch(e => {
|
|
98
|
+
this.__pendingLogin = null;
|
|
99
|
+
this.__authToken = null;
|
|
100
|
+
throw e;
|
|
101
|
+
});
|
|
86
102
|
|
|
87
|
-
this.
|
|
88
|
-
return
|
|
103
|
+
this.__pendingLogin = pendingLogin;
|
|
104
|
+
return pendingLogin;
|
|
89
105
|
}
|
|
90
106
|
|
|
91
107
|
/**
|