node-vault-client 2.1.0 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-vault-client",
3
- "version": "2.1.0",
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"
@@ -40,30 +40,30 @@
40
40
  "author": "Namecheap <opensource@namecheap.com>",
41
41
  "license": "Apache-2.0",
42
42
  "dependencies": {
43
- "@aws-sdk/credential-providers": "^3.382.0",
44
- "aws4": "^1.8.0",
43
+ "@aws-sdk/credential-providers": "^3.1100.0",
44
+ "aws4": "^1.13.2",
45
45
  "long-timeout": "^0.1.1"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "config": ">=1 <4"
49
49
  },
50
50
  "overrides": {
51
- "serialize-javascript": "^7.0.5",
51
+ "serialize-javascript": "^7.0.7",
52
52
  "glob": "^13.0.0",
53
53
  "diff": "^8.0.3",
54
- "brace-expansion": "^5.0.8",
54
+ "brace-expansion": "^5.0.9",
55
55
  "js-yaml": "^4.3.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@eslint/js": "^9.0.0",
59
- "c8": "^11.0.0",
60
- "chai": "^6.0.0",
58
+ "@eslint/js": "^9.39.5",
59
+ "c8": "^10.1.3",
60
+ "chai": "^6.2.2",
61
61
  "deep-freeze": "^0.0.1",
62
- "eslint": "^9.39.4",
63
- "globals": "^17.6.0",
64
- "lodash": "^4.17.21",
62
+ "eslint": "^9.39.5",
63
+ "globals": "^17.8.0",
64
+ "lodash": "^4.18.1",
65
65
  "mocha": "^11.7.6",
66
- "sinon": "^22.0.0",
67
- "sinon-chai": "^4.0.0"
66
+ "sinon": "^22.1.0",
67
+ "sinon-chai": "^4.0.1"
68
68
  }
69
69
  }
@@ -38,8 +38,17 @@ class VaultBaseAuth {
38
38
  this._log = logger;
39
39
  this._mount = mount;
40
40
 
41
- /** @type AuthToken */
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
- const tokenExpired = this.__authToken instanceof AuthToken && this.__authToken.isExpired();
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 === null || tokenExpired) {
64
- this._log.info('getting auth token (mount=%s)', this._mount);
77
+ if (this.__authToken !== null && !tokenExpired) {
78
+ this._log.debug('token already exist');
79
+ return Promise.resolve(this.__authToken);
80
+ }
65
81
 
66
- const tokenPromise = this._authenticate().then(authToken => {
67
- this.__authToken = authToken;
82
+ this._log.info('getting auth token (mount=%s)', this._mount);
68
83
 
69
- if (this.__authToken.isRenewable()) {
70
- this._log.debug(
71
- 'setting refresh timer for token (accessor=%s)',
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
- this.__authToken = tokenPromise;
84
- return tokenPromise;
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._log.debug('token already exist');
88
- return Promise.resolve(this.__authToken);
103
+ this.__pendingLogin = pendingLogin;
104
+ return pendingLogin;
89
105
  }
90
106
 
91
107
  /**