@ibm-cloud/secrets-manager 2.0.0 → 2.0.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/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## [2.0.2](https://github.com/IBM/secrets-manager-node-sdk/compare/v2.0.1...v2.0.2) (2023-12-11)
2
+
3
+ ## [2.0.1](https://github.com/IBM/secrets-manager-node-sdk/compare/v2.0.0...v2.0.1) (2023-09-19)
4
+
1
5
  # [2.0.0](https://github.com/IBM/secrets-manager-node-sdk/compare/v1.0.44...v2.0.0) (2023-04-17)
2
6
 
3
7
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ![tests](https://github.com/IBM/secrets-manager-node-sdk/workflows/run-tests/badge.svg)
2
2
 
3
- # IBM Cloud Secrets Manager Node.js SDK v2
3
+ # IBM Cloud Secrets Manager Node SDK
4
4
 
5
5
  A Node.js client library to interact with
6
6
  the [IBM Cloud® Secrets Manager APIs](https://cloud.ibm.com/apidocs/secrets-manager).
@@ -28,7 +28,7 @@ services:
28
28
 
29
29
  | Service name | Import path |
30
30
  |------------------------------------------------------------------|-----------------------------------------------|
31
- | [Secrets Manager](https://cloud.ibm.com/apidocs/secrets-manager) | @ibm-cloud/secrets-manager/secrets-manager/v1 |
31
+ | [Secrets Manager](https://cloud.ibm.com/apidocs/secrets-manager) | @ibm-cloud/secrets-manager/secrets-manager/v2 |
32
32
 
33
33
  ## Prerequisites
34
34
 
@@ -98,7 +98,7 @@ the [IBM Node.js SDK Core documentation](https://github.com/IBM/node-sdk-core/bl
98
98
  Construct a service client and use it to create and retrieve a secret from your Secrets Manager instance.
99
99
 
100
100
  ```js
101
- const SecretsManager = require('@ibm-cloud/secrets-manager/secrets-manager/v1');
101
+ const SecretsManager = require('@ibm-cloud/secrets-manager/secrets-manager/v2');
102
102
  const { IamAuthenticator } = require('@ibm-cloud/secrets-manager/auth');
103
103
 
104
104
 
@@ -117,46 +117,40 @@ async function secretsManagerSdkExample() {
117
117
 
118
118
  // Use the Secrets Manager API to create a secret
119
119
  let res = await secretsManager.createSecret({
120
- secretType: 'username_password',
121
- 'metadata': {
122
- 'collection_type': 'application/vnd.ibm.secrets-manager.secret+json',
123
- 'collection_total': 1,
124
- },
125
- 'resources': [
126
- {
127
- 'name': 'example-username-password-secret',
128
- 'description': 'Extended description for this secret.',
129
- 'username': 'user123',
130
- 'password': '123456789',
131
- 'labels': ['label1', 'label2'],
132
- 'expiration_date': '2030-04-01T09:30:00Z',
133
- },
134
- ],
120
+ secretPrototype: {
121
+ custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
122
+ description: 'Description of my arbitrary secret.',
123
+ expiration_date: '2023-10-05T11:49:42Z',
124
+ labels: ['dev', 'us-south'],
125
+ name: 'example-arbitrary-secret',
126
+ secret_group_id: 'default',
127
+ secret_type: 'arbitrary',
128
+ payload: 'secret-data',
129
+ version_custom_metadata: { custom_version_key: 'custom_version_value' },
130
+ }
135
131
  });
136
132
 
137
- console.log('Secret created:\n' + JSON.stringify(res.result.resources[0], null, 2));
133
+ console.log('Secret created:\n' + JSON.stringify(res.result, null, 2));
138
134
 
139
135
  // Get the ID of the newly created secret
140
- const secretId = res.result.resources[0].id;
136
+ const secretId = res.result.id;
141
137
 
142
138
  // Use the Secrets Manager API to get the secret using the secret ID
143
139
  res = await secretsManager.getSecret({
144
- secretType: 'username_password',
145
140
  id: secretId,
146
141
  });
147
142
 
148
- console.log('Get secret:\n', JSON.stringify(res.result.resources, null, 2));
143
+ console.log('Get secret:\n', JSON.stringify(res.result, null, 2));
149
144
  }
150
145
 
151
146
  secretsManagerSdkExample();
152
147
 
153
148
  ```
154
149
 
155
- To delete a secret, specify the `secretType` and its `id`.
150
+ To delete a secret, specify its `id`.
156
151
 
157
152
  ```js
158
153
  res = await secretsManager.deleteSecret({
159
- secretType: 'username_password',
160
154
  id: secretId,
161
155
  });
162
156
 
@@ -168,26 +162,14 @@ Create a secret group, and then add a new secret to this group.
168
162
 
169
163
  ```js
170
164
  // Create a secret group
171
- const createGroupParams = {
172
- metadata: {
173
- collection_type: 'application/vnd.ibm.secrets-manager.secret.group+json',
174
- collection_total: 1,
175
- },
176
- resources: [{ name: 'Test Group', description: 'Group my test secrets' }],
177
- };
165
+ const createGroupParams = { name: 'Test Group', description: 'Group my test secrets' };
178
166
 
179
167
  let res = await secretsManager.createSecretGroup(createGroupParams);
180
- const secretGroupId = res.result.resources[0].id;
168
+ const secretGroupId = res.result.id;
181
169
 
182
170
  // Create a secret and associate it with your secret group
183
171
  res = await secretsManager.createSecret({
184
- metadata: {
185
- collection_type: 'application/vnd.ibm.secrets-manager.secret+json',
186
- collection_total: 1,
187
- },
188
- secretType: 'username_password',
189
- resources: [
190
- {
172
+ secretPrototype: {
191
173
  secret_group_id: secretGroupId,
192
174
  name: "Test secret",
193
175
  description: 'Secret used for testing.',
@@ -195,31 +177,31 @@ Create a secret group, and then add a new secret to this group.
195
177
  password: 'test_password',
196
178
  labels: ['label1'],
197
179
  expiration_date: '2030-04-01T09:30:00Z',
198
- },
199
- ],
180
+ }
200
181
  });
201
182
  ```
202
183
 
203
184
  Create a rotation policy of one month for a secret.
204
185
 
205
186
  ```js
206
- let res = await secretsManager.putPolicy({
207
- metadata: {
208
- collection_type: 'application/vnd.ibm.secrets-manager.secret.policy+json',
209
- collection_total: 1,
210
- },
211
- secretType: 'username_password',
212
- id: secretId,
213
- resources: [
214
- {
215
- type: 'application/vnd.ibm.secrets-manager.secret.policy+json',
216
- rotation: {
217
- interval: 1,
218
- unit: 'month',
219
- },
220
- },
221
- ],
222
- });
187
+ let res = await secretsManager.createSecret({
188
+ secretPrototype: {
189
+ custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
190
+ description: 'Description of my arbitrary secret.',
191
+ expiration_date: '2023-10-05T11:49:42Z',
192
+ labels: ['dev', 'us-south'],
193
+ name: 'example-arbitrary-secret',
194
+ secret_group_id: 'default',
195
+ secret_type: 'arbitrary',
196
+ payload: 'secret-data',
197
+ version_custom_metadata: { custom_version_key: 'custom_version_value' },
198
+ rotation: {
199
+ auto_rotate: true,
200
+ interval: 1,
201
+ unit: month,
202
+ }
203
+ }
204
+ });
223
205
  ```
224
206
 
225
207
  For more information and IBM Cloud SDK usage examples for Node.js, see
@@ -264,5 +246,3 @@ For general contribution guidelines, see [CONTRIBUTING](CONTRIBUTING.md).
264
246
  ## License
265
247
 
266
248
  This SDK project is released under the Apache 2.0 license. The license's full text can be found in [LICENSE](LICENSE).
267
-
268
- dummy PR #1
@@ -64,6 +64,7 @@ describe('SecretsManagerV2', () => {
64
64
  let secretIdForGetSecretVersionLink;
65
65
  let secretIdForListSecretLocksLink;
66
66
  let secretIdForListSecretVersionLocksLink;
67
+ let secretNameLink;
67
68
  let secretVersionIdForCreateSecretVersionLocksLink;
68
69
  let secretVersionIdForDeleteSecretVersionLocksLink;
69
70
  let secretVersionIdForGetSecretVersionLink;
@@ -131,7 +132,7 @@ describe('SecretsManagerV2', () => {
131
132
  const secretPrototypeModel = {
132
133
  custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
133
134
  description: 'Description of my arbitrary secret.',
134
- expiration_date: '2023-10-05T11:49:42Z',
135
+ expiration_date: '2030-10-05T11:49:42Z',
135
136
  labels: ['dev', 'us-south'],
136
137
  name: 'example-arbitrary-secret',
137
138
  secret_group_id: 'default',
@@ -158,6 +159,47 @@ describe('SecretsManagerV2', () => {
158
159
  secretIdForGetSecretVersionLink = responseBody.id;
159
160
  });
160
161
 
162
+ test('updateSecretMetadata request example', async () => {
163
+ consoleLogMock.mockImplementation((output) => {
164
+ originalLog(output);
165
+ });
166
+ consoleWarnMock.mockImplementation((output) => {
167
+ // if an error occurs, display the message and then fail the test
168
+ originalWarn(output);
169
+ expect(true).toBeFalsy();
170
+ });
171
+
172
+ originalLog('updateSecretMetadata() result:');
173
+ // begin-update_secret_metadata
174
+
175
+ // Request models needed by this operation.
176
+
177
+ // ArbitrarySecretMetadataPatch
178
+ const secretMetadataPatchModel = {
179
+ name: 'updated-arbitrary-secret-name-example',
180
+ description: 'updated Arbitrary Secret description',
181
+ labels: ['dev', 'us-south'],
182
+ custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
183
+ };
184
+
185
+ const params = {
186
+ id: secretIdForGetSecretLink,
187
+ secretMetadataPatch: secretMetadataPatchModel,
188
+ };
189
+
190
+ let res;
191
+ try {
192
+ res = await secretsManagerService.updateSecretMetadata(params);
193
+ console.log(JSON.stringify(res.result, null, 2));
194
+ } catch (err) {
195
+ console.warn(err);
196
+ }
197
+
198
+ // end-update_secret_metadata
199
+ const responseBody = res.result;
200
+ secretNameLink = responseBody.name;
201
+ });
202
+
161
203
  test('listSecretVersions request example', async () => {
162
204
  consoleLogMock.mockImplementation((output) => {
163
205
  originalLog(output);
@@ -388,7 +430,7 @@ describe('SecretsManagerV2', () => {
388
430
  limit: 10,
389
431
  sort: 'created_at',
390
432
  search: 'example',
391
- groups: ['default'],
433
+ groups: ['default', 'cac40995-c37a-4dcb-9506-472869077634'],
392
434
  };
393
435
 
394
436
  const allResults = [];
@@ -463,7 +505,7 @@ describe('SecretsManagerV2', () => {
463
505
  // end-get_secret_metadata
464
506
  });
465
507
 
466
- test('updateSecretMetadata request example', async () => {
508
+ test('createSecretAction request example', async () => {
467
509
  consoleLogMock.mockImplementation((output) => {
468
510
  originalLog(output);
469
511
  });
@@ -473,36 +515,33 @@ describe('SecretsManagerV2', () => {
473
515
  expect(true).toBeFalsy();
474
516
  });
475
517
 
476
- originalLog('updateSecretMetadata() result:');
477
- // begin-update_secret_metadata
518
+ originalLog('createSecretAction() result:');
519
+ // begin-create_secret_action
478
520
 
479
521
  // Request models needed by this operation.
480
522
 
481
- // ArbitrarySecretMetadataPatch
482
- const secretMetadataPatchModel = {
483
- name: 'updated-arbitrary-secret-name',
484
- description: 'updated Arbitrary Secret description',
485
- labels: ['dev', 'us-south'],
486
- custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
523
+ // PrivateCertificateActionRevokePrototype
524
+ const secretActionPrototypeModel = {
525
+ action_type: 'private_cert_action_revoke_certificate',
487
526
  };
488
527
 
489
528
  const params = {
490
529
  id: secretIdForGetSecretLink,
491
- secretMetadataPatch: secretMetadataPatchModel,
530
+ secretActionPrototype: secretActionPrototypeModel,
492
531
  };
493
532
 
494
533
  let res;
495
534
  try {
496
- res = await secretsManagerService.updateSecretMetadata(params);
535
+ res = await secretsManagerService.createSecretAction(params);
497
536
  console.log(JSON.stringify(res.result, null, 2));
498
537
  } catch (err) {
499
538
  console.warn(err);
500
539
  }
501
540
 
502
- // end-update_secret_metadata
541
+ // end-create_secret_action
503
542
  });
504
543
 
505
- test('createSecretAction request example', async () => {
544
+ test('getSecretByNameType request example', async () => {
506
545
  consoleLogMock.mockImplementation((output) => {
507
546
  originalLog(output);
508
547
  });
@@ -512,30 +551,24 @@ describe('SecretsManagerV2', () => {
512
551
  expect(true).toBeFalsy();
513
552
  });
514
553
 
515
- originalLog('createSecretAction() result:');
516
- // begin-create_secret_action
517
-
518
- // Request models needed by this operation.
519
-
520
- // PublicCertificateActionValidateManualDNSPrototype
521
- const secretActionPrototypeModel = {
522
- action_type: 'private_cert_action_revoke_certificate',
523
- };
554
+ originalLog('getSecretByNameType() result:');
555
+ // begin-get_secret_by_name_type
524
556
 
525
557
  const params = {
526
- id: secretIdForGetSecretLink,
527
- secretActionPrototype: secretActionPrototypeModel,
558
+ secretType: 'arbitrary',
559
+ name: secretNameLink,
560
+ secretGroupName: 'default',
528
561
  };
529
562
 
530
563
  let res;
531
564
  try {
532
- res = await secretsManagerService.createSecretAction(params);
565
+ res = await secretsManagerService.getSecretByNameType(params);
533
566
  console.log(JSON.stringify(res.result, null, 2));
534
567
  } catch (err) {
535
568
  console.warn(err);
536
569
  }
537
570
 
538
- // end-create_secret_action
571
+ // end-get_secret_by_name_type
539
572
  });
540
573
 
541
574
  test('createSecretVersion request example', async () => {
@@ -561,7 +594,7 @@ describe('SecretsManagerV2', () => {
561
594
  };
562
595
 
563
596
  const params = {
564
- secretId: secretIdForCreateSecretVersionLink,
597
+ secretId: secretIdForGetSecretLink,
565
598
  secretVersionPrototype: secretVersionPrototypeModel,
566
599
  };
567
600
 
@@ -590,7 +623,7 @@ describe('SecretsManagerV2', () => {
590
623
  // begin-get_secret_version
591
624
 
592
625
  const params = {
593
- secretId: secretIdForGetSecretVersionLink,
626
+ secretId: secretIdForGetSecretLink,
594
627
  id: secretVersionIdForGetSecretVersionLink,
595
628
  };
596
629
 
@@ -620,7 +653,7 @@ describe('SecretsManagerV2', () => {
620
653
 
621
654
  const params = {
622
655
  secretId: secretIdForGetSecretLink,
623
- id: secretVersionIdForGetSecretVersionMetadataLink,
656
+ id: secretVersionIdForGetSecretVersionLink,
624
657
  };
625
658
 
626
659
  let res;
@@ -649,7 +682,7 @@ describe('SecretsManagerV2', () => {
649
682
 
650
683
  const params = {
651
684
  secretId: secretIdForGetSecretLink,
652
- id: secretVersionIdForUpdateSecretVersionMetadataLink,
685
+ id: secretVersionIdForGetSecretVersionLink,
653
686
  };
654
687
 
655
688
  let res;
@@ -685,7 +718,7 @@ describe('SecretsManagerV2', () => {
685
718
 
686
719
  const params = {
687
720
  secretId: secretIdForGetSecretLink,
688
- id: secretIdForGetSecretLink,
721
+ id: secretVersionIdForGetSecretVersionLink,
689
722
  secretVersionActionPrototype: secretVersionActionPrototypeModel,
690
723
  };
691
724
 
@@ -716,7 +749,7 @@ describe('SecretsManagerV2', () => {
716
749
  const params = {
717
750
  limit: 10,
718
751
  search: 'example',
719
- groups: ['default'],
752
+ groups: ['default', 'cac40995-c37a-4dcb-9506-472869077634'],
720
753
  };
721
754
 
722
755
  const allResults = [];
@@ -749,7 +782,7 @@ describe('SecretsManagerV2', () => {
749
782
  // begin-list_secret_locks
750
783
 
751
784
  const params = {
752
- id: secretIdForListSecretLocksLink,
785
+ id: secretIdForGetSecretLink,
753
786
  limit: 10,
754
787
  sort: 'name',
755
788
  search: 'example',
@@ -794,8 +827,8 @@ describe('SecretsManagerV2', () => {
794
827
  };
795
828
 
796
829
  const params = {
797
- secretId: secretIdForCreateSecretVersionLocksLink,
798
- id: secretVersionIdForCreateSecretVersionLocksLink,
830
+ secretId: secretIdForGetSecretLink,
831
+ id: secretVersionIdForGetSecretVersionLink,
799
832
  locks: [secretLockPrototypeModel],
800
833
  };
801
834
 
@@ -824,8 +857,8 @@ describe('SecretsManagerV2', () => {
824
857
  // begin-list_secret_version_locks
825
858
 
826
859
  const params = {
827
- secretId: secretIdForListSecretVersionLocksLink,
828
- id: secretVersionIdForListSecretVersionLocksLink,
860
+ secretId: secretIdForGetSecretLink,
861
+ id: secretVersionIdForGetSecretVersionLink,
829
862
  limit: 10,
830
863
  sort: 'name',
831
864
  search: 'example',
@@ -1099,7 +1132,7 @@ describe('SecretsManagerV2', () => {
1099
1132
 
1100
1133
  const params = {
1101
1134
  secretId: secretIdForGetSecretLink,
1102
- id: secretIdForGetSecretLink,
1135
+ id: secretVersionIdForGetSecretVersionLink,
1103
1136
  };
1104
1137
 
1105
1138
  try {
@@ -1155,7 +1188,7 @@ describe('SecretsManagerV2', () => {
1155
1188
 
1156
1189
  const params = {
1157
1190
  secretId: secretIdForGetSecretLink,
1158
- id: secretVersionIdForDeleteSecretVersionLocksLink,
1191
+ id: secretVersionIdForGetSecretVersionLink,
1159
1192
  name: ['lock-example-1'],
1160
1193
  };
1161
1194
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibm-cloud/secrets-manager",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Client library for IBM Cloud Secrets Manager",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,11 +32,11 @@
32
32
  },
33
33
  "license": "Apache-2.0",
34
34
  "engines": {
35
- "node": ">=12.0.0"
35
+ "node": ">=14.0.0"
36
36
  },
37
37
  "dependencies": {
38
38
  "extend": "^3.0.2",
39
- "ibm-cloud-sdk-core": "^4.0.2"
39
+ "ibm-cloud-sdk-core": "^4.1.2"
40
40
  },
41
41
  "jest": {
42
42
  "collectCoverage": true,