@ibm-cloud/secrets-manager 2.1.0 → 2.1.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/dist/README.md DELETED
@@ -1,240 +0,0 @@
1
- ![tests](https://github.com/IBM/secrets-manager-node-sdk/workflows/run-tests/badge.svg)
2
-
3
- # IBM Cloud Secrets Manager Node SDK
4
- A Node.js client library to interact with the [IBM Cloud® Secrets Manager APIs](https://cloud.ibm.com/apidocs/secrets-manager).
5
-
6
- <details>
7
- <summary>Table of Contents</summary>
8
-
9
- * [Overview](#overview)
10
- * [Prerequisites](#prerequisites)
11
- * [Installation](#installation)
12
- * [Authentication](#authentication)
13
- * [Using the SDK](#using-the-sdk)
14
- * [Tests](#tests)
15
- * [Questions](#questions)
16
- * [Issues](#issues)
17
- * [Contributing](#contributing)
18
- * [License](#license)
19
-
20
- </details>
21
-
22
- ## Overview
23
- The IBM Cloud Secrets Manager Node.js SDK allows developers to programmatically interact with the following IBM Cloud
24
- services:
25
-
26
- | Service name | Import path |
27
- |------------------------------------------------------------------|-----------------------------------------------|
28
- | [Secrets Manager](https://cloud.ibm.com/apidocs/secrets-manager) | @ibm-cloud/secrets-manager/secrets-manager/v2 |
29
-
30
- ## Prerequisites
31
-
32
- - An [IBM Cloud account](https://cloud.ibm.com/registration).
33
- - A [Secrets Manager service instance](https://cloud.ibm.com/catalog/services/secrets-manager).
34
- - An [IBM Cloud API key](https://cloud.ibm.com/iam/apikeys) that allows the SDK to access your account.
35
- - Node.js version 16 or above.
36
-
37
- This SDK is tested with Node versions 14 and up. The SDK may work on previous versions, but this is not supported
38
- officially.
39
-
40
- ## Installation
41
-
42
- ```sh
43
- npm install @ibm-cloud/secrets-manager
44
- ```
45
-
46
- ## Authentication
47
- Secrets Manager uses token-based Identity and Access Management (IAM) authentication.
48
-
49
- With IAM authentication, you supply an API key that is used to generate an access token. Then, the access token is
50
- included in each API request to Secrets Manager. Access tokens are valid for a limited amount of time and must be
51
- regenerated.
52
-
53
- Authentication for this SDK is accomplished by using [IAM authenticators](https://github.com/IBM/ibm-cloud-sdk-common/blob/master/README.md#authentication). Import
54
- authenticators from `@ibm-cloud/secrets-manager/auth`.
55
-
56
- ### Examples
57
- #### Programmatic credentials
58
-
59
- ```js
60
- import { IamAuthenticator } from '@ibm-cloud/secrets-manager/auth';
61
-
62
- const authenticator = new IamAuthenticator({
63
- apikey: '{apikey}',
64
- });
65
- ```
66
-
67
- #### External configuration
68
-
69
- ```js
70
- import { getAuthenticatorFromEnvironment } from '@ibm-cloud/secrets-manager/auth';
71
-
72
- // env vars
73
- // SECRETS_MANAGER_API_APIKEY==<apikey>
74
- const iamAuthenticator = getAuthenticatorFromEnvironment('SECRETS_MANAGER_API');
75
- ```
76
-
77
- To learn more about IAM authenticators and how to use them in your Node.js application, see
78
- the [IBM Node.js SDK Core documentation](https://github.com/IBM/node-sdk-core/blob/master/Authentication.md).
79
-
80
- ## Using the SDK
81
- ### Basic usage
82
-
83
- - All methods return a Promise that either resolves with the response from the service or rejects with an Error. The
84
- response contains the body, the headers, the status code, and the status text. If using async/await, use try/catch for
85
- handling errors.
86
- - Use the `serviceUrl` parameter to set the endpoint URL that is specific to your Secrets Manager service instance. To
87
- find your endpoint URL, you can copy it from the **Endpoints** page in the Secrets Manager UI.
88
-
89
- #### Examples
90
- Construct a service client and use it to create and retrieve a secret from your Secrets Manager instance.
91
-
92
- ```js
93
- const SecretsManager = require('@ibm-cloud/secrets-manager/secrets-manager/v2');
94
- const { IamAuthenticator } = require('@ibm-cloud/secrets-manager/auth');
95
-
96
-
97
- async function secretsManagerSdkExample() {
98
- // Authenticate with IAM using your IBM Cloud API key
99
- const authenticator = new IamAuthenticator({
100
- apikey: process.env.SECRETS_MANAGER_API_APIKEY,
101
- });
102
-
103
- // Create an instance of the SDK by providing an authentication mechanism and your Secrets Manager instance URL
104
- const secretsManager = new SecretsManager({
105
- authenticator,
106
- serviceUrl:
107
- 'https://example-instance.us-south.secrets-manager.appdomain.cloud',
108
- });
109
-
110
- // Use the Secrets Manager API to create a secret
111
- let res = await secretsManager.createSecret({
112
- secretPrototype: {
113
- custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
114
- description: 'Description of my arbitrary secret.',
115
- expiration_date: '2023-10-05T11:49:42Z',
116
- labels: ['dev', 'us-south'],
117
- name: 'example-arbitrary-secret',
118
- secret_group_id: 'default',
119
- secret_type: 'arbitrary',
120
- payload: 'secret-data',
121
- version_custom_metadata: { custom_version_key: 'custom_version_value' },
122
- }
123
- });
124
-
125
- console.log('Secret created:\n' + JSON.stringify(res.result, null, 2));
126
-
127
- // Get the ID of the newly created secret
128
- const secretId = res.result.id;
129
-
130
- // Use the Secrets Manager API to get the secret using the secret ID
131
- res = await secretsManager.getSecret({
132
- id: secretId,
133
- });
134
-
135
- console.log('Get secret:\n', JSON.stringify(res.result, null, 2));
136
- }
137
-
138
- secretsManagerSdkExample();
139
-
140
- ```
141
-
142
- To delete a secret, specify its `id`.
143
-
144
- ```js
145
- res = await secretsManager.deleteSecret({
146
- id: secretId,
147
- });
148
-
149
- console.log('Secret deleted.');
150
-
151
- ```
152
-
153
- Create a secret group, and then add a new secret to this group.
154
-
155
- ```js
156
- // Create a secret group
157
- const createGroupParams = { name: 'Test Group', description: 'Group my test secrets' };
158
-
159
- let res = await secretsManager.createSecretGroup(createGroupParams);
160
- const secretGroupId = res.result.id;
161
-
162
- // Create a secret and associate it with your secret group
163
- res = await secretsManager.createSecret({
164
- secretPrototype: {
165
- secret_group_id: secretGroupId,
166
- name: "Test secret",
167
- description: 'Secret used for testing.',
168
- username: 'test_user',
169
- password: 'test_password',
170
- labels: ['label1'],
171
- expiration_date: '2030-04-01T09:30:00Z',
172
- }
173
- });
174
- ```
175
-
176
- Create a rotation policy of one month for a secret.
177
-
178
- ```js
179
- let res = await secretsManager.createSecret({
180
- secretPrototype: {
181
- custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
182
- description: 'Description of my arbitrary secret.',
183
- expiration_date: '2023-10-05T11:49:42Z',
184
- labels: ['dev', 'us-south'],
185
- name: 'example-arbitrary-secret',
186
- secret_group_id: 'default',
187
- secret_type: 'arbitrary',
188
- payload: 'secret-data',
189
- version_custom_metadata: { custom_version_key: 'custom_version_value' },
190
- rotation: {
191
- auto_rotate: true,
192
- interval: 1,
193
- unit: month,
194
- }
195
- }
196
- });
197
- ```
198
-
199
- For more information and IBM Cloud SDK usage examples for Node.js, see
200
- the [IBM Cloud SDK Common documentation](https://github.com/IBM/ibm-cloud-sdk-common/blob/master/README.md)
201
-
202
- ## Tests
203
-
204
- This project includes unit tests `test/unit` and integration tests `test/integration`.
205
-
206
- The integration tests are run against an actual Secrets Manager instance and require the following environment variables
207
- to be set:
208
-
209
- ```
210
- SECRETS_MANAGER_API_APIKEY=<API_KEY>
211
- SERVICE_URL=<SECRETS_MANAGER_ENDPOINT_URL>
212
- ```
213
-
214
- To run the tests:
215
-
216
- ```sh
217
- npm test
218
- ```
219
-
220
- ## Questions
221
-
222
- If you're having difficulties using this SDK, you can ask questions about this project by using [Stack Overflow](https://stackoverflow.com/questions/tagged/ibm-secrets-manager). Be sure to include
223
- the `ibm-cloud` and `ibm-secrets-manager` tags.
224
-
225
- You can also check out the [Secrets Manager documentation](https://cloud.ibm.com/docs/secrets-manager)
226
- and [API reference](https://cloud.ibm.com/apidocs/secrets-manager) for more information about the service.
227
-
228
- ## Issues
229
-
230
- If you encounter an issue with the project, you're welcome to submit
231
- a [bug report](https://github.com/IBM/secrets-manager-node-sdk/issues) to help us improve.
232
-
233
- ## Contributing
234
-
235
- For general contribution guidelines, see [CONTRIBUTING](CONTRIBUTING.md).
236
-
237
- ## License
238
-
239
- This SDK project is released under the Apache 2.0 license. The license's full text can be found in [LICENSE](LICENSE).
240
-