@ibm-cloud/secrets-manager 0.0.1 → 0.0.5
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/auth/index.js +8 -9
- package/auth/index.js.map +1 -1
- package/ibm-cloud-secrets-manager-api/v1.js +1 -1
- package/lib/common.js +1 -2
- package/lib/common.js.map +1 -1
- package/package.json +6 -6
- package/readme.md +216 -0
package/auth/index.js
CHANGED
|
@@ -15,14 +15,13 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getAuthenticatorFromEnvironment = exports.Cp4dTokenManager = exports.IamTokenManager = exports.CloudPakForDataAuthenticator = exports.IamAuthenticator = exports.BearerTokenAuthenticator = exports.BasicAuthenticator = exports.NoAuthAuthenticator = void 0;
|
|
19
18
|
var ibm_cloud_sdk_core_1 = require("ibm-cloud-sdk-core");
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
exports.NoAuthAuthenticator = ibm_cloud_sdk_core_1.NoAuthAuthenticator;
|
|
20
|
+
exports.BasicAuthenticator = ibm_cloud_sdk_core_1.BasicAuthenticator;
|
|
21
|
+
exports.BearerTokenAuthenticator = ibm_cloud_sdk_core_1.BearerTokenAuthenticator;
|
|
22
|
+
exports.IamAuthenticator = ibm_cloud_sdk_core_1.IamAuthenticator;
|
|
23
|
+
exports.CloudPakForDataAuthenticator = ibm_cloud_sdk_core_1.CloudPakForDataAuthenticator;
|
|
24
|
+
exports.IamTokenManager = ibm_cloud_sdk_core_1.IamTokenManager;
|
|
25
|
+
exports.Cp4dTokenManager = ibm_cloud_sdk_core_1.Cp4dTokenManager;
|
|
26
|
+
exports.getAuthenticatorFromEnvironment = ibm_cloud_sdk_core_1.getAuthenticatorFromEnvironment;
|
|
28
27
|
//# sourceMappingURL=index.js.map
|
package/auth/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../auth/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../auth/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAEH,yDAS4B;AAR1B,mDAAA,mBAAmB,CAAA;AACnB,kDAAA,kBAAkB,CAAA;AAClB,wDAAA,wBAAwB,CAAA;AACxB,gDAAA,gBAAgB,CAAA;AAChB,4DAAA,4BAA4B,CAAA;AAC5B,+CAAA,eAAe,CAAA;AACf,gDAAA,gBAAgB,CAAA;AAChB,+DAAA,+BAA+B,CAAA"}
|
|
@@ -18,7 +18,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
|
18
18
|
var extendStatics = function (d, b) {
|
|
19
19
|
extendStatics = Object.setPrototypeOf ||
|
|
20
20
|
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
21
|
-
function (d, b) { for (var p in b) if (
|
|
21
|
+
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
|
22
22
|
return extendStatics(d, b);
|
|
23
23
|
};
|
|
24
24
|
return function (d, b) {
|
package/lib/common.js
CHANGED
|
@@ -15,10 +15,9 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.getSdkHeaders = void 0;
|
|
19
18
|
var os = require("os");
|
|
20
19
|
// tslint:disable-next-line:no-var-requires
|
|
21
|
-
var pkg = require('
|
|
20
|
+
var pkg = require('../package.json');
|
|
22
21
|
function getSdkHeaders(serviceName, serviceVersion, operationId) {
|
|
23
22
|
var sdkName = 'secrets-manager-nodejs-sdk';
|
|
24
23
|
var sdkVersion = pkg.version;
|
package/lib/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../lib/common.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../lib/common.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;AAEH,uBAA0B;AAE1B,2CAA2C;AAC3C,IAAM,GAAG,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAMvC,SAAgB,aAAa,CAAC,WAAmB,EAAE,cAAsB,EAAE,WAAmB;IAC5F,IAAM,OAAO,GAAG,4BAA4B,CAAC;IAC7C,IAAM,UAAU,GAAG,GAAG,CAAC,OAAO,CAAC;IAC/B,IAAM,MAAM,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC7B,IAAM,SAAS,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC/B,IAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAEpC,IAAM,OAAO,GAAG;QACd,YAAY,EAAK,OAAO,SAAI,UAAU,gCAA2B,MAAM,oBAAe,SAAS,sBAAiB,WAAW,MAAG;KAC/H,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC;AAZD,sCAYC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibm-cloud/secrets-manager",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Client library
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"description": "Client library for IBM Cloud Secrets Manager",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/IBM/secrets-manager-nodejs-sdk"
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"lint": "npm run eslint:check && npm run tslint:check",
|
|
20
20
|
"lint-fix": "npm run eslint:fix && npm run tslint:fix",
|
|
21
21
|
"jest": "jest",
|
|
22
|
-
"test": "npm run build && npm run lint && jest test/",
|
|
22
|
+
"test": "npm run build && cp package.json dist/ && npm run lint && jest test/",
|
|
23
23
|
"test-unit": "npm run build && jest test/unit/",
|
|
24
24
|
"test-integration": "npm run build && jest test/integration",
|
|
25
25
|
"report-coverage": "codecov",
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
"build": "tsc",
|
|
28
28
|
"prepublishOnly": "npm run build",
|
|
29
29
|
"postversion": "tsc-publish --no-checks --dry-run",
|
|
30
|
-
"publishDist": "cp package.json dist/ && cd dist && npm publish"
|
|
30
|
+
"publishDist": "cp {package.json,readme.md} dist/ && cd dist && npm publish --access public"
|
|
31
31
|
},
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"engines": {
|
|
34
|
-
"node": ">=
|
|
34
|
+
"node": ">=12.0.0"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@types/node": "^12.0.8",
|
|
@@ -65,4 +65,4 @@
|
|
|
65
65
|
],
|
|
66
66
|
"testEnvironment": "node"
|
|
67
67
|
}
|
|
68
|
-
}
|
|
68
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# IBM Cloud Secrets Manager Node.js SDK
|
|
4
|
+
|
|
5
|
+
A Node.js client library to use the IBM Cloud® Secrets Manager APIs.
|
|
6
|
+
|
|
7
|
+
<details>
|
|
8
|
+
<summary>Table of Contents</summary>
|
|
9
|
+
|
|
10
|
+
* [Overview](#overview)
|
|
11
|
+
* [Prerequisites](#prerequisites)
|
|
12
|
+
* [Installation](#installation)
|
|
13
|
+
* [Authentication](#authentication)
|
|
14
|
+
* [Using the SDK](#using-the-sdk)
|
|
15
|
+
* [Documentation](#documentation)
|
|
16
|
+
* [Tests](#tests)
|
|
17
|
+
</details>
|
|
18
|
+
|
|
19
|
+
## Overview
|
|
20
|
+
|
|
21
|
+
The IBM Cloud Secrets Manager Node.js SDK allows developers to programmatically interact with IBM Cloud Secrets Manager.
|
|
22
|
+
|
|
23
|
+
## Prerequisites
|
|
24
|
+
- You need an [IBM Cloud account](https://cloud.ibm.com/registration).
|
|
25
|
+
|
|
26
|
+
- **Node >=12**: This SDK is tested with Node versions 12 and up. It may work on previous versions but this is not officially supported.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npm install @ibm-cloud/secrets-manager
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Authentication
|
|
35
|
+
|
|
36
|
+
IBM Cloud Secrets Manager uses token-based Identity and Access Management (IAM) authentication.
|
|
37
|
+
|
|
38
|
+
IAM authentication uses a service API key to get an access token that is passed with the call.
|
|
39
|
+
Access tokens are valid for a limited amount of time and must be regenerated.
|
|
40
|
+
|
|
41
|
+
Authentication is accomplished using dedicated Authenticators for each authentication scheme. Import authenticators from `@ibm-cloud/secrets-manager/auth`.
|
|
42
|
+
|
|
43
|
+
### Examples
|
|
44
|
+
#### Programmatic credentials
|
|
45
|
+
```js
|
|
46
|
+
import { IamAuthenticator } from '@ibm-cloud/secrets-manager/auth';
|
|
47
|
+
|
|
48
|
+
const authenticator = new IamAuthenticator({
|
|
49
|
+
apikey: '{apikey}',
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
#### External configuration
|
|
54
|
+
```js
|
|
55
|
+
import { getAuthenticatorFromEnvironment } from '@ibm-cloud/secrets-manager/auth';
|
|
56
|
+
|
|
57
|
+
// env vars
|
|
58
|
+
// SECRETS_MANAGER_API_AUTH_TYPE=iam
|
|
59
|
+
// SECRETS_MANAGER_API_APIKEY==<apikey>
|
|
60
|
+
const iamAuthenticator = getAuthenticatorFromEnvironment('SECRETS_MANAGER_API');
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
To learn more about the Authenticators and how to use them with your services, see [the detailed documentation](https://github.com/IBM/node-sdk-core/blob/master/AUTHENTICATION.md).
|
|
64
|
+
|
|
65
|
+
## Using the SDK
|
|
66
|
+
### Basic usage
|
|
67
|
+
|
|
68
|
+
- All methods return a Promise that either resolves with the response from the service or rejects with an Error. The response contains the body, the headers, the status code, and the status text.
|
|
69
|
+
If using async/await, use try/catch for handling errors.
|
|
70
|
+
|
|
71
|
+
- Use the `serviceUrl` parameter to pass the URL of your Secrets Manager to `IbmCloudSecretsManagerApiV1`.
|
|
72
|
+
|
|
73
|
+
#### Examples
|
|
74
|
+
Create an instance of the Secrets Manager API and then use it to create and retrieve a secret.
|
|
75
|
+
```js
|
|
76
|
+
const IbmCloudSecretsManagerApiV1 = require('@ibm-cloud/secrets-manager/ibm-cloud-secrets-manager-api/v1');
|
|
77
|
+
const { IamAuthenticator } = require('@ibm-cloud/secrets-manager/auth');
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
async function secretsManagerSdkExample() {
|
|
81
|
+
// Authenticate with IAM using your IBM Cloud API key
|
|
82
|
+
const authenticator = new IamAuthenticator({
|
|
83
|
+
apikey: process.env.SECRETS_MANAGER_API_APIKEY,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Create an instance of the SDK by providing an authentication mechanism and your Secrets Manager instance URL
|
|
87
|
+
const secretsManagerApi = new IbmCloudSecretsManagerApiV1({
|
|
88
|
+
authenticator,
|
|
89
|
+
serviceUrl:
|
|
90
|
+
'https://example-instance.us-south.secrets-manager.appdomain.cloud',
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// Use the Secrets Manager API to create a secret
|
|
94
|
+
let res = await secretsManagerApi.createSecret({
|
|
95
|
+
secretType: 'username_password',
|
|
96
|
+
'metadata': {
|
|
97
|
+
'collection_type': 'application/vnd.ibm.secrets-manager.secret+json',
|
|
98
|
+
'collection_total': 1,
|
|
99
|
+
},
|
|
100
|
+
'resources': [
|
|
101
|
+
{
|
|
102
|
+
'name': 'example-username-password-secret',
|
|
103
|
+
'description': 'text describing the secret',
|
|
104
|
+
'username': 'user123',
|
|
105
|
+
'password': '123456789',
|
|
106
|
+
'labels': ['label1', 'label2'],
|
|
107
|
+
'expiration_date': '2030-04-01T09:30:00Z',
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
console.log('Secret created:\n' + JSON.stringify(res.result.resources[0], null, 2));
|
|
113
|
+
|
|
114
|
+
// Get the ID of the newly created secret
|
|
115
|
+
const secretId = res.result.resources[0].id;
|
|
116
|
+
|
|
117
|
+
// Use the Secrets Manager API to get the secret using the secret ID
|
|
118
|
+
res = await secretsManagerApi.getSecret({
|
|
119
|
+
secretType: 'username_password',
|
|
120
|
+
id: secretId,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
console.log('Get Secret:\n', JSON.stringify(res.result.resources, null, 2));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
secretsManagerSdkExample();
|
|
127
|
+
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
To delete a secret, specify the `secretType` and its `id`.
|
|
131
|
+
```js
|
|
132
|
+
res = await secretsManagerApi.deleteSecret({
|
|
133
|
+
secretType: 'username_password',
|
|
134
|
+
id: secretId,
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
console.log('Secret deleted.');
|
|
138
|
+
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Create a secret group, and then add a new secret to this group.
|
|
142
|
+
```js
|
|
143
|
+
// Create a secret group
|
|
144
|
+
const createGroupParams = {
|
|
145
|
+
metadata: {
|
|
146
|
+
collection_type: 'application/vnd.ibm.secrets-manager.secret.group+json',
|
|
147
|
+
collection_total: 1,
|
|
148
|
+
},
|
|
149
|
+
resources: [{ name: 'Test Group', description: 'Group my test secrets' }],
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
let res = await ibmCloudSecretsManagerApiService.createSecretGroup(createGroupParams);
|
|
153
|
+
const secretGroupId = res.result.resources[0].id;
|
|
154
|
+
|
|
155
|
+
// Create a secret and associate it with your secret group
|
|
156
|
+
res = await ibmCloudSecretsManagerApiService.createSecret({
|
|
157
|
+
metadata: {
|
|
158
|
+
collection_type: 'application/vnd.ibm.secrets-manager.secret+json',
|
|
159
|
+
collection_total: 1,
|
|
160
|
+
},
|
|
161
|
+
secretType: 'username_password',
|
|
162
|
+
resources: [
|
|
163
|
+
{
|
|
164
|
+
secret_group_id: secretGroupId,
|
|
165
|
+
name: "Test secret",
|
|
166
|
+
description: 'Secret used for testing',
|
|
167
|
+
username: 'test_user',
|
|
168
|
+
password: 'test_password',
|
|
169
|
+
labels: ['label1'],
|
|
170
|
+
expiration_date: '2030-04-01T09:30:00Z',
|
|
171
|
+
},
|
|
172
|
+
],
|
|
173
|
+
});
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Create a rotation policy of one month for a secret.
|
|
177
|
+
```js
|
|
178
|
+
let res = await ibmCloudSecretsManagerApiService.putPolicy({
|
|
179
|
+
metadata: {
|
|
180
|
+
collection_type: 'application/vnd.ibm.secrets-manager.secret.policy+json',
|
|
181
|
+
collection_total: 1,
|
|
182
|
+
},
|
|
183
|
+
secretType: 'username_password',
|
|
184
|
+
id: secretId,
|
|
185
|
+
resources: [
|
|
186
|
+
{
|
|
187
|
+
type: 'application/vnd.ibm.secrets-manager.secret.policy+json',
|
|
188
|
+
rotation: {
|
|
189
|
+
interval: 1,
|
|
190
|
+
unit: 'month',
|
|
191
|
+
},
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
});
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Documentation
|
|
198
|
+
|
|
199
|
+
For more information about Secrets Manager, check out the [Secrets Manager documentation](https://cloud.ibm.com/docs/secrets-manager) and [API reference](https://cloud.ibm.com/apidocs/secrets-manager).
|
|
200
|
+
|
|
201
|
+
## Tests
|
|
202
|
+
|
|
203
|
+
This project includes unit tests `test/unit` and integration tests `test/integration`.
|
|
204
|
+
|
|
205
|
+
The integration test are running against an actual instance of a Secrets Manager and require the following environment variables to be set:
|
|
206
|
+
```
|
|
207
|
+
SECRETS_MANAGER_API_AUTH_TYPE=iam;
|
|
208
|
+
SECRETS_MANAGER_API_APIKEY=<api key>
|
|
209
|
+
SERVICE_URL=<url to a secrets manager instance>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Running all the tests:
|
|
213
|
+
```sh
|
|
214
|
+
npm test
|
|
215
|
+
```
|
|
216
|
+
|