node-vault-client 0.6.1 → 1.0.1

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,10 +1,12 @@
1
1
  {
2
2
  "name": "node-vault-client",
3
- "version": "0.6.1",
3
+ "version": "1.0.1",
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
- "repository": "github:namecheap/node-vault-client",
5
+ "repository": {
6
+ "url": "git+https://github.com/namecheap/node-vault-client.git"
7
+ },
6
8
  "engines": {
7
- "node": ">=6.0.0"
9
+ "node": ">=14.0.0"
8
10
  },
9
11
  "main": "src/VaultClient.js",
10
12
  "files": [
@@ -17,6 +19,7 @@
17
19
  "author": "Namecheap <opensource@namecheap.com>",
18
20
  "license": "Apache-2.0",
19
21
  "dependencies": {
22
+ "@aws-sdk/credential-providers": "^3.382.0",
20
23
  "assign-deep": "^1.0.1",
21
24
  "aws4": "^1.8.0",
22
25
  "bluebird": "^3.7.0",
@@ -28,11 +31,9 @@
28
31
  "url-join": "^2.0.5"
29
32
  },
30
33
  "peerDependencies": {
31
- "config": ">=1 <4",
32
- "aws-sdk": "^2.67.0"
34
+ "config": ">=1 <4"
33
35
  },
34
36
  "devDependencies": {
35
- "aws-sdk": "^2.544.0",
36
37
  "chai": "^3.5.0",
37
38
  "co-mocha": "^1.2.2",
38
39
  "deep-freeze": "^0.0.1",
@@ -63,11 +63,8 @@ class VaultClient {
63
63
  let instance = vaultInstances[name];
64
64
  if (instance === undefined) {
65
65
  vaultInstances[name] = instance = new VaultClient(options);
66
-
67
- return instance;
68
66
  }
69
-
70
- throw new errors.InvalidArgumentsError('Instance with such name already booted');
67
+ return instance;
71
68
  }
72
69
 
73
70
  /**
@@ -2,6 +2,7 @@
2
2
 
3
3
  const VaultBaseAuth = require('./VaultBaseAuth');
4
4
  const aws4 = require('aws4');
5
+ const { fromNodeProviderChain } = require('@aws-sdk/credential-providers');
5
6
  const _ = require('lodash');
6
7
  const errors = require('../errors');
7
8
 
@@ -28,47 +29,44 @@ const errors = require('../errors');
28
29
  * role: 'my_iam_role',
29
30
  * iam_server_id_header_value: VAULT_ADDR, // Optional
30
31
  * namespace: 'some_namespace', // Optional
31
- * credentials: new AWS.Credentials({
32
+ * credentials: { // Optional
32
33
  * accessKeyId: AWS_ACCESS_KEY,
33
34
  * secretAccessKey: AWS_SECRET_KEY,
34
- * })
35
+ * },
35
36
  * }
36
37
  * }
37
38
  * })
38
- *
39
39
  * ```
40
40
  *
41
41
  */
42
42
  class VaultIAMAuth extends VaultBaseAuth {
43
43
  /**
44
+ * @typedef AWSCredentials
45
+ * @property {String} accessKeyId
46
+ * @property {String} secretAccessKey
47
+ *
48
+ * @typedef {Object} VaultIAMAuthConfig
49
+ * @property {String} role - Role name of the auth/{mount}/role/{name} backend.
50
+ * @property [AWSCredentials] [credentials] - Optional. AWS Credentials
51
+ * @property {String} [iam_server_id_header_value] - Optional. Header's value X-Vault-AWS-IAM-Server-ID.
52
+ *
44
53
  * @param {VaultApiClient} api - see {@link VaultBaseAuth#constructor}
45
54
  * @param {Object} logger
46
- * @param {Object} config
47
- * @param {String} config.role - Role name of the auth/{mount}/role/{name} backend.
48
- * @param {AWS.Credentials|AWS.Credentials[]} config.credentials {@see AWS.CredentialProviderChain providers}
49
- * @param {String} [config.iam_server_id_header_value] - Optional. Header's value X-Vault-AWS-IAM-Server-ID.
55
+ * @param {VaultIAMAuthConfig} config
50
56
  * @param {String} mount - Vault's AWS Auth Backend mount point ("aws" by default)
51
57
  */
52
58
  constructor(api, logger, config, mount) {
53
59
  super(api, logger, mount || 'aws');
54
60
 
55
- const AWS = require('aws-sdk');
56
-
57
61
  this.__role = config.role;
58
62
  this.__iam_server_id_header_value = config.iam_server_id_header_value;
59
63
  this.__namespace = config.namespace;
60
64
 
61
- if (!(config.credentials instanceof AWS.Credentials) && !_.isArray(config.credentials)) {
62
- throw new errors.InvalidAWSCredentialsError('Credentials must be provided. {AWS.Credentials|AWS.Credentials[]} or function-providers, which return them.')
63
- }
64
65
 
65
- const credentialsProviders = _.isArray(config.credentials)
66
- ? config.credentials
67
- : [config.credentials];
66
+ const { credentials } = config;
67
+ this._validateCredentialsConfig(credentials);
68
68
 
69
- this.__credentialChain = new AWS.CredentialProviderChain(
70
- credentialsProviders
71
- );
69
+ this.__credentialChain = credentials ? () => Promise.resolve(credentials) : fromNodeProviderChain();
72
70
  }
73
71
 
74
72
  /**
@@ -109,17 +107,13 @@ class VaultIAMAuth extends VaultBaseAuth {
109
107
  }
110
108
 
111
109
  /**
112
- * Credentials resolved by {@see AWS.CredentialProviderChain}
110
+ * Credentials resolved by {@see @aws-sdk/credential-providers}
113
111
  *
114
- * @returns {Promise<AWS.Credentials>}
112
+ * @returns {Promise<AwsCredentialIdentity>}
115
113
  * @private
116
114
  */
117
115
  __getCredentials() {
118
- return new Promise((resolve, reject) =>
119
- this.__credentialChain.resolve((err, credentials) =>
120
- err ? reject(err) : resolve(credentials)
121
- )
122
- );
116
+ return this.__credentialChain();
123
117
  }
124
118
 
125
119
  /**
@@ -177,6 +171,17 @@ class VaultIAMAuth extends VaultBaseAuth {
177
171
  __headersLikeGolangStyle(headers) {
178
172
  return _.mapValues(headers, (value) => [`${value}`]);
179
173
  }
174
+
175
+ _validateCredentialsConfig(credentials) {
176
+ if (Array.isArray(credentials)) {
177
+ throw new errors.InvalidAWSCredentialsError('Invalid AWS credentials provided in config. See CHANGELOG if migating from 0.x.x');
178
+ }
179
+ if (credentials && typeof credentials === 'object') {
180
+ if (!credentials.secretAccessKey || !credentials.accessKeyId) {
181
+ throw new errors.InvalidAWSCredentialsError('Invalid AWS credentials provided in config: accessKeyId and secretAccessKey are required.');
182
+ }
183
+ }
184
+ }
180
185
  }
181
186
 
182
- module.exports = VaultIAMAuth;
187
+ module.exports = VaultIAMAuth;