node-vault-client 0.6.1 → 1.0.0
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/LICENSE.txt +200 -200
- package/README.md +153 -153
- package/package.json +42 -43
- package/src/Lease.js +57 -57
- package/src/VaultApiClient.js +55 -55
- package/src/VaultClient.js +266 -266
- package/src/VaultNodeConfig.js +105 -105
- package/src/auth/AuthToken.js +94 -94
- package/src/auth/VaultAppRoleAuth.js +40 -40
- package/src/auth/VaultBaseAuth.js +140 -140
- package/src/auth/VaultIAMAuth.js +187 -182
- package/src/auth/VaultKubernetesAuth.js +48 -48
- package/src/auth/VaultTokenAuth.js +34 -34
- package/src/errors.js +21 -21
package/README.md
CHANGED
|
@@ -1,154 +1,154 @@
|
|
|
1
|
-
# Node.js Vault Client
|
|
2
|
-
|
|
3
|
-
[](https://travis-ci.org/namecheap/node-vault-client)
|
|
4
|
-

|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
A Vault Client implemented in pure javascript for [HashiCorp Vault](https://github.com/hashicorp/vault).
|
|
8
|
-
It supports variety of Auth Backends and performs lease renewal for issued auth token.
|
|
9
|
-
|
|
10
|
-
## Install
|
|
11
|
-
```
|
|
12
|
-
npm install --save node-vault-client
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
## Example
|
|
16
|
-
|
|
17
|
-
```javascript
|
|
18
|
-
const VaultClient = require('node-vault-client');
|
|
19
|
-
|
|
20
|
-
const vaultClient = VaultClient.boot('main', {
|
|
21
|
-
api: { url: 'https://vault.example.com:8200/' },
|
|
22
|
-
auth: {
|
|
23
|
-
type: 'appRole', // or 'token', 'iam'
|
|
24
|
-
config: { role_id: '637c065f-c644-5e12-d3d1-e9fa4363af61' }
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
vaultClient.read('secret/tst').then(v => {
|
|
29
|
-
console.log(v);
|
|
30
|
-
}).catch(e => console.error(e));
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
## Supported Auth Backends
|
|
34
|
-
|
|
35
|
-
* [AWS IAM](https://www.vaultproject.io/docs/auth/aws.html#iam-auth-method)
|
|
36
|
-
* [AppRole](https://www.vaultproject.io/docs/auth/approle.html)
|
|
37
|
-
* [Token](https://www.vaultproject.io/docs/auth/token.html)
|
|
38
|
-
|
|
39
|
-
## API
|
|
40
|
-
|
|
41
|
-
<a name="VaultClient"></a>
|
|
42
|
-
|
|
43
|
-
### VaultClient
|
|
44
|
-
|
|
45
|
-
* [VaultClient](#VaultClient)
|
|
46
|
-
* [new VaultClient(options)](#new_VaultClient_new)
|
|
47
|
-
* _instance_
|
|
48
|
-
* [.fillNodeConfig()](#VaultClient+fillNodeConfig)
|
|
49
|
-
* [.read(path)](#VaultClient+read) ⇒ <code>Promise.<Lease></code>
|
|
50
|
-
* [.list(path)](#VaultClient+list) ⇒ <code>Promise.<Lease></code>
|
|
51
|
-
* [.write(path, data)](#VaultClient+write) ⇒ <code>Promise.<(T\|never)></code>
|
|
52
|
-
* _static_
|
|
53
|
-
* [.boot(name, [options])](#VaultClient.boot) ⇒
|
|
54
|
-
* [.get(name)](#VaultClient.get) ⇒
|
|
55
|
-
* [.clear([name])](#VaultClient.clear)
|
|
56
|
-
|
|
57
|
-
<a name="new_VaultClient_new"></a>
|
|
58
|
-
|
|
59
|
-
#### new VaultClient(options)
|
|
60
|
-
Client constructor function.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
| Param | Type | Default | Description |
|
|
64
|
-
| --- | --- | --- | --- |
|
|
65
|
-
| options | `Object` | | |
|
|
66
|
-
| options.api | <code>Object</code> | | |
|
|
67
|
-
| options.api.url | <code>String</code> | | the url of the vault server |
|
|
68
|
-
| [options.api.apiVersion] | <code>String</code> | `v1` | |
|
|
69
|
-
| options.auth | <code>Object</code> | | |
|
|
70
|
-
| options.auth.type | <code>String</code> | | |
|
|
71
|
-
| options.auth.config | <code>Object</code> | | auth configuration variables |
|
|
72
|
-
| options.logger | <code>Object</code> | `false` | | Logger that supports "error", "info", "warn", "trace", "debug" methods. Uses `console` by default. Pass `false` to disable logging. |
|
|
73
|
-
|
|
74
|
-
#### vaultClient.fillNodeConfig()
|
|
75
|
-
Populates Vault's values to NPM "config" module
|
|
76
|
-
|
|
77
|
-
**Kind**: instance method of [<code>VaultClient</code>](#VaultClient)
|
|
78
|
-
<a name="VaultClient+read"></a>
|
|
79
|
-
|
|
80
|
-
#### vaultClient.read(path) ⇒ <code>Promise.<Lease></code>
|
|
81
|
-
Read secret from Vault
|
|
82
|
-
|
|
83
|
-
**Kind**: instance method of [<code>VaultClient</code>](#VaultClient)
|
|
84
|
-
|
|
85
|
-
| Param | Type | Description |
|
|
86
|
-
| --- | --- | --- |
|
|
87
|
-
| path | <code>string</code> | path to the secret |
|
|
88
|
-
|
|
89
|
-
<a name="VaultClient+list"></a>
|
|
90
|
-
|
|
91
|
-
#### vaultClient.list(path) ⇒ <code>Promise.<Lease></code>
|
|
92
|
-
Retrieves secrets list
|
|
93
|
-
|
|
94
|
-
**Kind**: instance method of [<code>VaultClient</code>](#VaultClient)
|
|
95
|
-
|
|
96
|
-
| Param | Type | Description |
|
|
97
|
-
| --- | --- | --- |
|
|
98
|
-
| path | <code>string</code> | path to the secret |
|
|
99
|
-
|
|
100
|
-
<a name="VaultClient+write"></a>
|
|
101
|
-
|
|
102
|
-
#### vaultClient.write(path, data) ⇒ <code>Promise.<(T\|never)></code>
|
|
103
|
-
Writes data to Vault
|
|
104
|
-
|
|
105
|
-
**Kind**: instance method of [<code>VaultClient</code>](#VaultClient)
|
|
106
|
-
|
|
107
|
-
| Param | Type | Description |
|
|
108
|
-
| --- | --- | --- |
|
|
109
|
-
| path | | path used to write data |
|
|
110
|
-
| data | <code>object</code> | data to write |
|
|
111
|
-
|
|
112
|
-
<a name="VaultClient.boot"></a>
|
|
113
|
-
|
|
114
|
-
#### VaultClient.boot(name, [options]) ⇒
|
|
115
|
-
Boot an instance of Vault
|
|
116
|
-
|
|
117
|
-
The instance will be stored in a local hash. Calling Vault.boot multiple
|
|
118
|
-
times with the same name will return the same instance.
|
|
119
|
-
|
|
120
|
-
**Kind**: static method of [<code>VaultClient</code>](#VaultClient)
|
|
121
|
-
**Returns**: Vault
|
|
122
|
-
|
|
123
|
-
| Param | Type | Description |
|
|
124
|
-
| --- | --- | --- |
|
|
125
|
-
| name | <code>String</code> | Vault instance name |
|
|
126
|
-
| [options] | <code>Object</code> | options for [Vault#constructor](#new_VaultClient_new). |
|
|
127
|
-
|
|
128
|
-
<a name="VaultClient.get"></a>
|
|
129
|
-
|
|
130
|
-
#### VaultClient.get(name) ⇒
|
|
131
|
-
Get an instance of Vault
|
|
132
|
-
|
|
133
|
-
The instance will be stored in a local hash. Calling Vault.pop multiple
|
|
134
|
-
times with the same name will return the same instance.
|
|
135
|
-
|
|
136
|
-
**Kind**: static method of [<code>VaultClient</code>](#VaultClient)
|
|
137
|
-
**Returns**: Vault
|
|
138
|
-
|
|
139
|
-
| Param | Type | Description |
|
|
140
|
-
| --- | --- | --- |
|
|
141
|
-
| name | <code>String</code> | Vault instance name |
|
|
142
|
-
|
|
143
|
-
<a name="VaultClient.clear"></a>
|
|
144
|
-
|
|
145
|
-
#### VaultClient.clear([name])
|
|
146
|
-
Clear named Vault instance
|
|
147
|
-
|
|
148
|
-
If no name passed all named instances will be cleared.
|
|
149
|
-
|
|
150
|
-
**Kind**: static method of [<code>VaultClient</code>](#VaultClient)
|
|
151
|
-
|
|
152
|
-
| Param | Type | Description |
|
|
153
|
-
| --- | --- | --- |
|
|
1
|
+
# Node.js Vault Client
|
|
2
|
+
|
|
3
|
+
[](https://travis-ci.org/namecheap/node-vault-client)
|
|
4
|
+

|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
A Vault Client implemented in pure javascript for [HashiCorp Vault](https://github.com/hashicorp/vault).
|
|
8
|
+
It supports variety of Auth Backends and performs lease renewal for issued auth token.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
```
|
|
12
|
+
npm install --save node-vault-client
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Example
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
const VaultClient = require('node-vault-client');
|
|
19
|
+
|
|
20
|
+
const vaultClient = VaultClient.boot('main', {
|
|
21
|
+
api: { url: 'https://vault.example.com:8200/' },
|
|
22
|
+
auth: {
|
|
23
|
+
type: 'appRole', // or 'token', 'iam'
|
|
24
|
+
config: { role_id: '637c065f-c644-5e12-d3d1-e9fa4363af61' }
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
vaultClient.read('secret/tst').then(v => {
|
|
29
|
+
console.log(v);
|
|
30
|
+
}).catch(e => console.error(e));
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Supported Auth Backends
|
|
34
|
+
|
|
35
|
+
* [AWS IAM](https://www.vaultproject.io/docs/auth/aws.html#iam-auth-method)
|
|
36
|
+
* [AppRole](https://www.vaultproject.io/docs/auth/approle.html)
|
|
37
|
+
* [Token](https://www.vaultproject.io/docs/auth/token.html)
|
|
38
|
+
|
|
39
|
+
## API
|
|
40
|
+
|
|
41
|
+
<a name="VaultClient"></a>
|
|
42
|
+
|
|
43
|
+
### VaultClient
|
|
44
|
+
|
|
45
|
+
* [VaultClient](#VaultClient)
|
|
46
|
+
* [new VaultClient(options)](#new_VaultClient_new)
|
|
47
|
+
* _instance_
|
|
48
|
+
* [.fillNodeConfig()](#VaultClient+fillNodeConfig)
|
|
49
|
+
* [.read(path)](#VaultClient+read) ⇒ <code>Promise.<Lease></code>
|
|
50
|
+
* [.list(path)](#VaultClient+list) ⇒ <code>Promise.<Lease></code>
|
|
51
|
+
* [.write(path, data)](#VaultClient+write) ⇒ <code>Promise.<(T\|never)></code>
|
|
52
|
+
* _static_
|
|
53
|
+
* [.boot(name, [options])](#VaultClient.boot) ⇒
|
|
54
|
+
* [.get(name)](#VaultClient.get) ⇒
|
|
55
|
+
* [.clear([name])](#VaultClient.clear)
|
|
56
|
+
|
|
57
|
+
<a name="new_VaultClient_new"></a>
|
|
58
|
+
|
|
59
|
+
#### new VaultClient(options)
|
|
60
|
+
Client constructor function.
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
| Param | Type | Default | Description |
|
|
64
|
+
| --- | --- | --- | --- |
|
|
65
|
+
| options | `Object` | | |
|
|
66
|
+
| options.api | <code>Object</code> | | |
|
|
67
|
+
| options.api.url | <code>String</code> | | the url of the vault server |
|
|
68
|
+
| [options.api.apiVersion] | <code>String</code> | `v1` | |
|
|
69
|
+
| options.auth | <code>Object</code> | | |
|
|
70
|
+
| options.auth.type | <code>String</code> | | |
|
|
71
|
+
| options.auth.config | <code>Object</code> | | auth configuration variables |
|
|
72
|
+
| options.logger | <code>Object</code> | `false` | | Logger that supports "error", "info", "warn", "trace", "debug" methods. Uses `console` by default. Pass `false` to disable logging. |
|
|
73
|
+
|
|
74
|
+
#### vaultClient.fillNodeConfig()
|
|
75
|
+
Populates Vault's values to NPM "config" module
|
|
76
|
+
|
|
77
|
+
**Kind**: instance method of [<code>VaultClient</code>](#VaultClient)
|
|
78
|
+
<a name="VaultClient+read"></a>
|
|
79
|
+
|
|
80
|
+
#### vaultClient.read(path) ⇒ <code>Promise.<Lease></code>
|
|
81
|
+
Read secret from Vault
|
|
82
|
+
|
|
83
|
+
**Kind**: instance method of [<code>VaultClient</code>](#VaultClient)
|
|
84
|
+
|
|
85
|
+
| Param | Type | Description |
|
|
86
|
+
| --- | --- | --- |
|
|
87
|
+
| path | <code>string</code> | path to the secret |
|
|
88
|
+
|
|
89
|
+
<a name="VaultClient+list"></a>
|
|
90
|
+
|
|
91
|
+
#### vaultClient.list(path) ⇒ <code>Promise.<Lease></code>
|
|
92
|
+
Retrieves secrets list
|
|
93
|
+
|
|
94
|
+
**Kind**: instance method of [<code>VaultClient</code>](#VaultClient)
|
|
95
|
+
|
|
96
|
+
| Param | Type | Description |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| path | <code>string</code> | path to the secret |
|
|
99
|
+
|
|
100
|
+
<a name="VaultClient+write"></a>
|
|
101
|
+
|
|
102
|
+
#### vaultClient.write(path, data) ⇒ <code>Promise.<(T\|never)></code>
|
|
103
|
+
Writes data to Vault
|
|
104
|
+
|
|
105
|
+
**Kind**: instance method of [<code>VaultClient</code>](#VaultClient)
|
|
106
|
+
|
|
107
|
+
| Param | Type | Description |
|
|
108
|
+
| --- | --- | --- |
|
|
109
|
+
| path | | path used to write data |
|
|
110
|
+
| data | <code>object</code> | data to write |
|
|
111
|
+
|
|
112
|
+
<a name="VaultClient.boot"></a>
|
|
113
|
+
|
|
114
|
+
#### VaultClient.boot(name, [options]) ⇒
|
|
115
|
+
Boot an instance of Vault
|
|
116
|
+
|
|
117
|
+
The instance will be stored in a local hash. Calling Vault.boot multiple
|
|
118
|
+
times with the same name will return the same instance.
|
|
119
|
+
|
|
120
|
+
**Kind**: static method of [<code>VaultClient</code>](#VaultClient)
|
|
121
|
+
**Returns**: Vault
|
|
122
|
+
|
|
123
|
+
| Param | Type | Description |
|
|
124
|
+
| --- | --- | --- |
|
|
125
|
+
| name | <code>String</code> | Vault instance name |
|
|
126
|
+
| [options] | <code>Object</code> | options for [Vault#constructor](#new_VaultClient_new). |
|
|
127
|
+
|
|
128
|
+
<a name="VaultClient.get"></a>
|
|
129
|
+
|
|
130
|
+
#### VaultClient.get(name) ⇒
|
|
131
|
+
Get an instance of Vault
|
|
132
|
+
|
|
133
|
+
The instance will be stored in a local hash. Calling Vault.pop multiple
|
|
134
|
+
times with the same name will return the same instance.
|
|
135
|
+
|
|
136
|
+
**Kind**: static method of [<code>VaultClient</code>](#VaultClient)
|
|
137
|
+
**Returns**: Vault
|
|
138
|
+
|
|
139
|
+
| Param | Type | Description |
|
|
140
|
+
| --- | --- | --- |
|
|
141
|
+
| name | <code>String</code> | Vault instance name |
|
|
142
|
+
|
|
143
|
+
<a name="VaultClient.clear"></a>
|
|
144
|
+
|
|
145
|
+
#### VaultClient.clear([name])
|
|
146
|
+
Clear named Vault instance
|
|
147
|
+
|
|
148
|
+
If no name passed all named instances will be cleared.
|
|
149
|
+
|
|
150
|
+
**Kind**: static method of [<code>VaultClient</code>](#VaultClient)
|
|
151
|
+
|
|
152
|
+
| Param | Type | Description |
|
|
153
|
+
| --- | --- | --- |
|
|
154
154
|
| [name] | <code>String</code> | Vault instance name, all instances will be cleared if no name were passed |
|
package/package.json
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "node-vault-client",
|
|
3
|
-
"version": "0.
|
|
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",
|
|
6
|
-
"engines": {
|
|
7
|
-
"node": ">=
|
|
8
|
-
},
|
|
9
|
-
"main": "src/VaultClient.js",
|
|
10
|
-
"files": [
|
|
11
|
-
"src"
|
|
12
|
-
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"test": "mocha test/**/*.test.js",
|
|
15
|
-
"version": "git add -A ."
|
|
16
|
-
},
|
|
17
|
-
"author": "Namecheap <opensource@namecheap.com>",
|
|
18
|
-
"license": "Apache-2.0",
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"request
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
},
|
|
34
|
-
"devDependencies": {
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"sinon": "^2.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "node-vault-client",
|
|
3
|
+
"version": "1.0.0",
|
|
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",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=14.0.0"
|
|
8
|
+
},
|
|
9
|
+
"main": "src/VaultClient.js",
|
|
10
|
+
"files": [
|
|
11
|
+
"src"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "mocha test/**/*.test.js",
|
|
15
|
+
"version": "git add -A ."
|
|
16
|
+
},
|
|
17
|
+
"author": "Namecheap <opensource@namecheap.com>",
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@aws-sdk/credential-providers": "^3.382.0",
|
|
21
|
+
"assign-deep": "^1.0.1",
|
|
22
|
+
"aws4": "^1.8.0",
|
|
23
|
+
"bluebird": "^3.7.0",
|
|
24
|
+
"lodash": "^4.17.15",
|
|
25
|
+
"long-timeout": "^0.1.1",
|
|
26
|
+
"pretty-ms": "^2.1.0",
|
|
27
|
+
"request": "^2.88.0",
|
|
28
|
+
"request-promise": "^4.2.4",
|
|
29
|
+
"url-join": "^2.0.5"
|
|
30
|
+
},
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"config": ">=1 <4"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"chai": "^3.5.0",
|
|
36
|
+
"co-mocha": "^1.2.2",
|
|
37
|
+
"deep-freeze": "^0.0.1",
|
|
38
|
+
"mocha": "^3.5.3",
|
|
39
|
+
"sinon": "^2.4.1",
|
|
40
|
+
"sinon-chai": "^2.14.0"
|
|
41
|
+
}
|
|
42
|
+
}
|
package/src/Lease.js
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const _ = require('lodash');
|
|
4
|
-
|
|
5
|
-
class Lease {
|
|
6
|
-
constructor(
|
|
7
|
-
requestId,
|
|
8
|
-
leaseId,
|
|
9
|
-
leaseDuration,
|
|
10
|
-
renewable,
|
|
11
|
-
data
|
|
12
|
-
) {
|
|
13
|
-
this.__requestId = requestId;
|
|
14
|
-
this.__leaseId = leaseId;
|
|
15
|
-
this.__leaseDuration = leaseDuration;
|
|
16
|
-
this.__renewable = renewable;
|
|
17
|
-
this.__data = data === undefined ? {} : data;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
static fromResponse(response) {
|
|
21
|
-
return new Lease(
|
|
22
|
-
response.request_id,
|
|
23
|
-
response.lease_id,
|
|
24
|
-
response.lease_duration,
|
|
25
|
-
response.renewable,
|
|
26
|
-
response.data
|
|
27
|
-
);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @param {String} key
|
|
32
|
-
* @returns {String}
|
|
33
|
-
*/
|
|
34
|
-
getValue(key) {
|
|
35
|
-
if (this.__data[key] === undefined) {
|
|
36
|
-
throw new Error('Requested key does not exist');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return this.__data[key];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* @returns {Object}
|
|
44
|
-
*/
|
|
45
|
-
getData() {
|
|
46
|
-
return _.cloneDeep(this.__data);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* @returns {bool}
|
|
51
|
-
*/
|
|
52
|
-
isRenewable() {
|
|
53
|
-
return this.__renewable;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
module.exports = Lease;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const _ = require('lodash');
|
|
4
|
+
|
|
5
|
+
class Lease {
|
|
6
|
+
constructor(
|
|
7
|
+
requestId,
|
|
8
|
+
leaseId,
|
|
9
|
+
leaseDuration,
|
|
10
|
+
renewable,
|
|
11
|
+
data
|
|
12
|
+
) {
|
|
13
|
+
this.__requestId = requestId;
|
|
14
|
+
this.__leaseId = leaseId;
|
|
15
|
+
this.__leaseDuration = leaseDuration;
|
|
16
|
+
this.__renewable = renewable;
|
|
17
|
+
this.__data = data === undefined ? {} : data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static fromResponse(response) {
|
|
21
|
+
return new Lease(
|
|
22
|
+
response.request_id,
|
|
23
|
+
response.lease_id,
|
|
24
|
+
response.lease_duration,
|
|
25
|
+
response.renewable,
|
|
26
|
+
response.data
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {String} key
|
|
32
|
+
* @returns {String}
|
|
33
|
+
*/
|
|
34
|
+
getValue(key) {
|
|
35
|
+
if (this.__data[key] === undefined) {
|
|
36
|
+
throw new Error('Requested key does not exist');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return this.__data[key];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @returns {Object}
|
|
44
|
+
*/
|
|
45
|
+
getData() {
|
|
46
|
+
return _.cloneDeep(this.__data);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @returns {bool}
|
|
51
|
+
*/
|
|
52
|
+
isRenewable() {
|
|
53
|
+
return this.__renewable;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = Lease;
|
package/src/VaultApiClient.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const rp = require('request-promise');
|
|
4
|
-
const urljoin = require('url-join');
|
|
5
|
-
const _ = require('lodash');
|
|
6
|
-
|
|
7
|
-
class VaultApiClient {
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @param {Object} config
|
|
11
|
-
* @param {String} config.url - the url of the vault server
|
|
12
|
-
* @param {String} [config.apiVersion='v1']
|
|
13
|
-
* @param {Object} logger
|
|
14
|
-
*/
|
|
15
|
-
constructor(config, logger) {
|
|
16
|
-
this.__config = _.defaultsDeep(_.cloneDeep(config), {
|
|
17
|
-
apiVersion: 'v1',
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
this._logger = logger;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
makeRequest(method, path, data, headers) {
|
|
24
|
-
data = data === undefined ? null : data;
|
|
25
|
-
headers = headers === undefined ? {} : headers;
|
|
26
|
-
|
|
27
|
-
const requestOptions = {
|
|
28
|
-
method: method,
|
|
29
|
-
body: data === null ? undefined : data,
|
|
30
|
-
uri: urljoin(this.__config.url, this.__config.apiVersion, path),
|
|
31
|
-
followRedirects: true,
|
|
32
|
-
followAllRedirects: true,
|
|
33
|
-
headers,
|
|
34
|
-
json: true,
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
this._logger.debug(
|
|
38
|
-
'making request: %s %s',
|
|
39
|
-
requestOptions.method,
|
|
40
|
-
requestOptions.uri
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
return rp(requestOptions)
|
|
44
|
-
.then((response) => {
|
|
45
|
-
this._logger.debug('%s %s response body:\n%s',
|
|
46
|
-
requestOptions.method,
|
|
47
|
-
requestOptions.uri,
|
|
48
|
-
JSON.stringify(response, null, ' ')
|
|
49
|
-
);
|
|
50
|
-
return response;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
module.exports = VaultApiClient;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const rp = require('request-promise');
|
|
4
|
+
const urljoin = require('url-join');
|
|
5
|
+
const _ = require('lodash');
|
|
6
|
+
|
|
7
|
+
class VaultApiClient {
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {Object} config
|
|
11
|
+
* @param {String} config.url - the url of the vault server
|
|
12
|
+
* @param {String} [config.apiVersion='v1']
|
|
13
|
+
* @param {Object} logger
|
|
14
|
+
*/
|
|
15
|
+
constructor(config, logger) {
|
|
16
|
+
this.__config = _.defaultsDeep(_.cloneDeep(config), {
|
|
17
|
+
apiVersion: 'v1',
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
this._logger = logger;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
makeRequest(method, path, data, headers) {
|
|
24
|
+
data = data === undefined ? null : data;
|
|
25
|
+
headers = headers === undefined ? {} : headers;
|
|
26
|
+
|
|
27
|
+
const requestOptions = {
|
|
28
|
+
method: method,
|
|
29
|
+
body: data === null ? undefined : data,
|
|
30
|
+
uri: urljoin(this.__config.url, this.__config.apiVersion, path),
|
|
31
|
+
followRedirects: true,
|
|
32
|
+
followAllRedirects: true,
|
|
33
|
+
headers,
|
|
34
|
+
json: true,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
this._logger.debug(
|
|
38
|
+
'making request: %s %s',
|
|
39
|
+
requestOptions.method,
|
|
40
|
+
requestOptions.uri
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
return rp(requestOptions)
|
|
44
|
+
.then((response) => {
|
|
45
|
+
this._logger.debug('%s %s response body:\n%s',
|
|
46
|
+
requestOptions.method,
|
|
47
|
+
requestOptions.uri,
|
|
48
|
+
JSON.stringify(response, null, ' ')
|
|
49
|
+
);
|
|
50
|
+
return response;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
module.exports = VaultApiClient;
|