@ibm-cloud/secrets-manager 1.0.44 → 2.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.
@@ -0,0 +1,1277 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+ /**
5
+ * (C) Copyright IBM Corp. 2023.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+
20
+ /* eslint-disable no-console */
21
+ /* eslint-disable no-await-in-loop */
22
+
23
+ const SecretsManagerV2 = require('../dist/secrets-manager/v2');
24
+ // eslint-disable-next-line node/no-unpublished-require
25
+ const authHelper = require('../test/resources/auth-helper.js');
26
+ // You can use the readExternalSources method to access additional configuration values
27
+ // const { readExternalSources } = require('ibm-cloud-sdk-core');
28
+
29
+ //
30
+ // This file provides an example of how to use the secrets-manager service.
31
+ //
32
+ // The following configuration properties are assumed to be defined:
33
+ // SECRETS_MANAGER_URL=<service base url>
34
+ // SECRETS_MANAGER_AUTH_TYPE=iam
35
+ // SECRETS_MANAGER_APIKEY=<IAM apikey>
36
+ // SECRETS_MANAGER_AUTH_URL=<IAM token service base URL - omit this if using the production environment>
37
+ //
38
+ // These configuration properties can be exported as environment variables, or stored
39
+ // in a configuration file and then:
40
+ // export IBM_CREDENTIALS_FILE=<name of configuration file>
41
+ //
42
+ const configFile = 'secrets_manager_v2.env';
43
+
44
+ const describe = authHelper.prepareTests(configFile);
45
+
46
+ // Save original console.log
47
+ const originalLog = console.log;
48
+ const originalWarn = console.warn;
49
+
50
+ // Mocks for console.log and console.warn
51
+ const consoleLogMock = jest.spyOn(console, 'log');
52
+ const consoleWarnMock = jest.spyOn(console, 'warn');
53
+
54
+ describe('SecretsManagerV2', () => {
55
+ // Service instance
56
+ let secretsManagerService;
57
+
58
+ // Variables to hold link values
59
+ let configurationNameForGetConfigurationLink;
60
+ let secretGroupIdForGetSecretGroupLink;
61
+ let secretIdForCreateSecretVersionLink;
62
+ let secretIdForCreateSecretVersionLocksLink;
63
+ let secretIdForGetSecretLink;
64
+ let secretIdForGetSecretVersionLink;
65
+ let secretIdForListSecretLocksLink;
66
+ let secretIdForListSecretVersionLocksLink;
67
+ let secretNameLink;
68
+ let secretVersionIdForCreateSecretVersionLocksLink;
69
+ let secretVersionIdForDeleteSecretVersionLocksLink;
70
+ let secretVersionIdForGetSecretVersionLink;
71
+ let secretVersionIdForGetSecretVersionMetadataLink;
72
+ let secretVersionIdForListSecretVersionLocksLink;
73
+ let secretVersionIdForUpdateSecretVersionMetadataLink;
74
+
75
+ // To access additional configuration values, uncomment this line and extract the values from config
76
+ // const config = readExternalSources(SecretsManagerV2.DEFAULT_SERVICE_NAME);
77
+
78
+ test('Initialize service', async () => {
79
+ // begin-common
80
+
81
+ secretsManagerService = SecretsManagerV2.newInstance();
82
+
83
+ // end-common
84
+ });
85
+
86
+ test('createSecretGroup request example', async () => {
87
+ consoleLogMock.mockImplementation((output) => {
88
+ originalLog(output);
89
+ });
90
+ consoleWarnMock.mockImplementation((output) => {
91
+ // if an error occurs, display the message and then fail the test
92
+ originalWarn(output);
93
+ expect(true).toBeFalsy();
94
+ });
95
+
96
+ originalLog('createSecretGroup() result:');
97
+ // begin-create_secret_group
98
+
99
+ const params = {
100
+ name: 'my-secret-group',
101
+ };
102
+
103
+ let res;
104
+ try {
105
+ res = await secretsManagerService.createSecretGroup(params);
106
+ console.log(JSON.stringify(res.result, null, 2));
107
+ } catch (err) {
108
+ console.warn(err);
109
+ }
110
+
111
+ // end-create_secret_group
112
+ const responseBody = res.result;
113
+ secretGroupIdForGetSecretGroupLink = responseBody.id;
114
+ });
115
+
116
+ test('createSecret request example', async () => {
117
+ consoleLogMock.mockImplementation((output) => {
118
+ originalLog(output);
119
+ });
120
+ consoleWarnMock.mockImplementation((output) => {
121
+ // if an error occurs, display the message and then fail the test
122
+ originalWarn(output);
123
+ expect(true).toBeFalsy();
124
+ });
125
+
126
+ originalLog('createSecret() result:');
127
+ // begin-create_secret
128
+
129
+ // Request models needed by this operation.
130
+
131
+ // ArbitrarySecretPrototype
132
+ const secretPrototypeModel = {
133
+ custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
134
+ description: 'Description of my arbitrary secret.',
135
+ expiration_date: '2023-10-05T11:49:42Z',
136
+ labels: ['dev', 'us-south'],
137
+ name: 'example-arbitrary-secret',
138
+ secret_group_id: 'default',
139
+ secret_type: 'arbitrary',
140
+ payload: 'secret-data',
141
+ version_custom_metadata: { custom_version_key: 'custom_version_value' },
142
+ };
143
+
144
+ const params = {
145
+ secretPrototype: secretPrototypeModel,
146
+ };
147
+
148
+ let res;
149
+ try {
150
+ res = await secretsManagerService.createSecret(params);
151
+ console.log(JSON.stringify(res.result, null, 2));
152
+ } catch (err) {
153
+ console.warn(err);
154
+ }
155
+
156
+ // end-create_secret
157
+ const responseBody = res.result;
158
+ secretIdForGetSecretLink = responseBody.id;
159
+ secretIdForGetSecretVersionLink = responseBody.id;
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
+
203
+ test('listSecretVersions request example', async () => {
204
+ consoleLogMock.mockImplementation((output) => {
205
+ originalLog(output);
206
+ });
207
+ consoleWarnMock.mockImplementation((output) => {
208
+ // if an error occurs, display the message and then fail the test
209
+ originalWarn(output);
210
+ expect(true).toBeFalsy();
211
+ });
212
+
213
+ originalLog('listSecretVersions() result:');
214
+ // begin-list_secret_versions
215
+
216
+ const params = {
217
+ secretId: secretIdForGetSecretLink,
218
+ };
219
+
220
+ let res;
221
+ try {
222
+ res = await secretsManagerService.listSecretVersions(params);
223
+ console.log(JSON.stringify(res.result, null, 2));
224
+ } catch (err) {
225
+ console.warn(err);
226
+ }
227
+
228
+ // end-list_secret_versions
229
+ const responseBody = res.result;
230
+ secretVersionIdForGetSecretVersionLink = responseBody.versions[0].id;
231
+ secretIdForCreateSecretVersionLink = responseBody.versions[0].secret_id;
232
+ secretVersionIdForGetSecretVersionMetadataLink = responseBody.versions[0].id;
233
+ secretVersionIdForUpdateSecretVersionMetadataLink = responseBody.versions[0].id;
234
+ secretIdForCreateSecretVersionLocksLink = responseBody.versions[0].secret_id;
235
+ secretVersionIdForCreateSecretVersionLocksLink = responseBody.versions[0].id;
236
+ secretVersionIdForDeleteSecretVersionLocksLink = responseBody.versions[0].id;
237
+ });
238
+
239
+ test('createSecretLocksBulk request example', async () => {
240
+ consoleLogMock.mockImplementation((output) => {
241
+ originalLog(output);
242
+ });
243
+ consoleWarnMock.mockImplementation((output) => {
244
+ // if an error occurs, display the message and then fail the test
245
+ originalWarn(output);
246
+ expect(true).toBeFalsy();
247
+ });
248
+
249
+ originalLog('createSecretLocksBulk() result:');
250
+ // begin-create_secret_locks_bulk
251
+
252
+ // Request models needed by this operation.
253
+
254
+ // SecretLockPrototype
255
+ const secretLockPrototypeModel = {
256
+ name: 'lock-example-1',
257
+ description: 'lock for consumer 1',
258
+ attributes: { key: 'value' },
259
+ };
260
+
261
+ const params = {
262
+ id: secretIdForGetSecretLink,
263
+ locks: [secretLockPrototypeModel],
264
+ };
265
+
266
+ let res;
267
+ try {
268
+ res = await secretsManagerService.createSecretLocksBulk(params);
269
+ console.log(JSON.stringify(res.result, null, 2));
270
+ } catch (err) {
271
+ console.warn(err);
272
+ }
273
+
274
+ // end-create_secret_locks_bulk
275
+ const responseBody = res.result;
276
+ secretIdForListSecretLocksLink = responseBody.secret_id;
277
+ secretIdForListSecretVersionLocksLink = responseBody.secret_id;
278
+ secretVersionIdForListSecretVersionLocksLink = responseBody.versions[0].version_id;
279
+ });
280
+
281
+ test('createConfiguration request example', async () => {
282
+ consoleLogMock.mockImplementation((output) => {
283
+ originalLog(output);
284
+ });
285
+ consoleWarnMock.mockImplementation((output) => {
286
+ // if an error occurs, display the message and then fail the test
287
+ originalWarn(output);
288
+ expect(true).toBeFalsy();
289
+ });
290
+
291
+ originalLog('createConfiguration() result:');
292
+ // begin-create_configuration
293
+
294
+ // Request models needed by this operation.
295
+
296
+ // PrivateCertificateConfigurationRootCAPrototype
297
+ const configurationPrototypeModel = {
298
+ config_type: 'private_cert_configuration_root_ca',
299
+ name: 'example-root-CA',
300
+ max_ttl: '43830h',
301
+ crl_expiry: '72h',
302
+ crl_disable: false,
303
+ crl_distribution_points_encoded: true,
304
+ issuing_certificates_urls_encoded: true,
305
+ common_name: 'example.com',
306
+ alt_names: ['alt-name-1', 'alt-name-2'],
307
+ ip_sans: '127.0.0.1',
308
+ uri_sans: 'https://www.example.com/test',
309
+ other_sans: ['1.2.3.5.4.3.201.10.4.3;utf8:test@example.com'],
310
+ ttl: '2190h',
311
+ format: 'pem',
312
+ private_key_format: 'der',
313
+ key_type: 'rsa',
314
+ key_bits: 4096,
315
+ max_path_length: -1,
316
+ exclude_cn_from_sans: false,
317
+ };
318
+
319
+ const params = {
320
+ configurationPrototype: configurationPrototypeModel,
321
+ };
322
+
323
+ let res;
324
+ try {
325
+ res = await secretsManagerService.createConfiguration(params);
326
+ console.log(JSON.stringify(res.result, null, 2));
327
+ } catch (err) {
328
+ console.warn(err);
329
+ }
330
+
331
+ // end-create_configuration
332
+ const responseBody = res.result;
333
+ configurationNameForGetConfigurationLink = responseBody.name;
334
+ });
335
+
336
+ test('listSecretGroups request example', async () => {
337
+ consoleLogMock.mockImplementation((output) => {
338
+ originalLog(output);
339
+ });
340
+ consoleWarnMock.mockImplementation((output) => {
341
+ // if an error occurs, display the message and then fail the test
342
+ originalWarn(output);
343
+ expect(true).toBeFalsy();
344
+ });
345
+
346
+ originalLog('listSecretGroups() result:');
347
+ // begin-list_secret_groups
348
+
349
+ let res;
350
+ try {
351
+ res = await secretsManagerService.listSecretGroups({});
352
+ console.log(JSON.stringify(res.result, null, 2));
353
+ } catch (err) {
354
+ console.warn(err);
355
+ }
356
+
357
+ // end-list_secret_groups
358
+ });
359
+
360
+ test('getSecretGroup request example', async () => {
361
+ consoleLogMock.mockImplementation((output) => {
362
+ originalLog(output);
363
+ });
364
+ consoleWarnMock.mockImplementation((output) => {
365
+ // if an error occurs, display the message and then fail the test
366
+ originalWarn(output);
367
+ expect(true).toBeFalsy();
368
+ });
369
+
370
+ originalLog('getSecretGroup() result:');
371
+ // begin-get_secret_group
372
+
373
+ const params = {
374
+ id: secretGroupIdForGetSecretGroupLink,
375
+ };
376
+
377
+ let res;
378
+ try {
379
+ res = await secretsManagerService.getSecretGroup(params);
380
+ console.log(JSON.stringify(res.result, null, 2));
381
+ } catch (err) {
382
+ console.warn(err);
383
+ }
384
+
385
+ // end-get_secret_group
386
+ });
387
+
388
+ test('updateSecretGroup request example', async () => {
389
+ consoleLogMock.mockImplementation((output) => {
390
+ originalLog(output);
391
+ });
392
+ consoleWarnMock.mockImplementation((output) => {
393
+ // if an error occurs, display the message and then fail the test
394
+ originalWarn(output);
395
+ expect(true).toBeFalsy();
396
+ });
397
+
398
+ originalLog('updateSecretGroup() result:');
399
+ // begin-update_secret_group
400
+
401
+ const params = {
402
+ id: secretGroupIdForGetSecretGroupLink,
403
+ };
404
+
405
+ let res;
406
+ try {
407
+ res = await secretsManagerService.updateSecretGroup(params);
408
+ console.log(JSON.stringify(res.result, null, 2));
409
+ } catch (err) {
410
+ console.warn(err);
411
+ }
412
+
413
+ // end-update_secret_group
414
+ });
415
+
416
+ test('listSecrets request example', async () => {
417
+ consoleLogMock.mockImplementation((output) => {
418
+ originalLog(output);
419
+ });
420
+ consoleWarnMock.mockImplementation((output) => {
421
+ // if an error occurs, display the message and then fail the test
422
+ originalWarn(output);
423
+ expect(true).toBeFalsy();
424
+ });
425
+
426
+ originalLog('listSecrets() result:');
427
+ // begin-list_secrets
428
+
429
+ const params = {
430
+ limit: 10,
431
+ sort: 'created_at',
432
+ search: 'example',
433
+ groups: ['default', 'cac40995-c37a-4dcb-9506-472869077634'],
434
+ };
435
+
436
+ const allResults = [];
437
+ try {
438
+ const pager = new SecretsManagerV2.SecretsPager(secretsManagerService, params);
439
+ while (pager.hasNext()) {
440
+ const nextPage = await pager.getNext();
441
+ expect(nextPage).not.toBeNull();
442
+ allResults.push(...nextPage);
443
+ }
444
+ console.log(JSON.stringify(allResults, null, 2));
445
+ } catch (err) {
446
+ console.warn(err);
447
+ }
448
+
449
+ // end-list_secrets
450
+ });
451
+
452
+ test('getSecret request example', async () => {
453
+ consoleLogMock.mockImplementation((output) => {
454
+ originalLog(output);
455
+ });
456
+ consoleWarnMock.mockImplementation((output) => {
457
+ // if an error occurs, display the message and then fail the test
458
+ originalWarn(output);
459
+ expect(true).toBeFalsy();
460
+ });
461
+
462
+ originalLog('getSecret() result:');
463
+ // begin-get_secret
464
+
465
+ const params = {
466
+ id: secretIdForGetSecretLink,
467
+ };
468
+
469
+ let res;
470
+ try {
471
+ res = await secretsManagerService.getSecret(params);
472
+ console.log(JSON.stringify(res.result, null, 2));
473
+ } catch (err) {
474
+ console.warn(err);
475
+ }
476
+
477
+ // end-get_secret
478
+ });
479
+
480
+ test('getSecretMetadata request example', async () => {
481
+ consoleLogMock.mockImplementation((output) => {
482
+ originalLog(output);
483
+ });
484
+ consoleWarnMock.mockImplementation((output) => {
485
+ // if an error occurs, display the message and then fail the test
486
+ originalWarn(output);
487
+ expect(true).toBeFalsy();
488
+ });
489
+
490
+ originalLog('getSecretMetadata() result:');
491
+ // begin-get_secret_metadata
492
+
493
+ const params = {
494
+ id: secretIdForGetSecretLink,
495
+ };
496
+
497
+ let res;
498
+ try {
499
+ res = await secretsManagerService.getSecretMetadata(params);
500
+ console.log(JSON.stringify(res.result, null, 2));
501
+ } catch (err) {
502
+ console.warn(err);
503
+ }
504
+
505
+ // end-get_secret_metadata
506
+ });
507
+
508
+ test('createSecretAction request example', async () => {
509
+ consoleLogMock.mockImplementation((output) => {
510
+ originalLog(output);
511
+ });
512
+ consoleWarnMock.mockImplementation((output) => {
513
+ // if an error occurs, display the message and then fail the test
514
+ originalWarn(output);
515
+ expect(true).toBeFalsy();
516
+ });
517
+
518
+ originalLog('createSecretAction() result:');
519
+ // begin-create_secret_action
520
+
521
+ // Request models needed by this operation.
522
+
523
+ // PrivateCertificateActionRevokePrototype
524
+ const secretActionPrototypeModel = {
525
+ action_type: 'private_cert_action_revoke_certificate',
526
+ };
527
+
528
+ const params = {
529
+ id: secretIdForGetSecretLink,
530
+ secretActionPrototype: secretActionPrototypeModel,
531
+ };
532
+
533
+ let res;
534
+ try {
535
+ res = await secretsManagerService.createSecretAction(params);
536
+ console.log(JSON.stringify(res.result, null, 2));
537
+ } catch (err) {
538
+ console.warn(err);
539
+ }
540
+
541
+ // end-create_secret_action
542
+ });
543
+
544
+ test('getSecretByNameType request example', async () => {
545
+ consoleLogMock.mockImplementation((output) => {
546
+ originalLog(output);
547
+ });
548
+ consoleWarnMock.mockImplementation((output) => {
549
+ // if an error occurs, display the message and then fail the test
550
+ originalWarn(output);
551
+ expect(true).toBeFalsy();
552
+ });
553
+
554
+ originalLog('getSecretByNameType() result:');
555
+ // begin-get_secret_by_name_type
556
+
557
+ const params = {
558
+ secretType: 'arbitrary',
559
+ name: secretNameLink,
560
+ secretGroupName: 'default',
561
+ };
562
+
563
+ let res;
564
+ try {
565
+ res = await secretsManagerService.getSecretByNameType(params);
566
+ console.log(JSON.stringify(res.result, null, 2));
567
+ } catch (err) {
568
+ console.warn(err);
569
+ }
570
+
571
+ // end-get_secret_by_name_type
572
+ });
573
+
574
+ test('createSecretVersion request example', async () => {
575
+ consoleLogMock.mockImplementation((output) => {
576
+ originalLog(output);
577
+ });
578
+ consoleWarnMock.mockImplementation((output) => {
579
+ // if an error occurs, display the message and then fail the test
580
+ originalWarn(output);
581
+ expect(true).toBeFalsy();
582
+ });
583
+
584
+ originalLog('createSecretVersion() result:');
585
+ // begin-create_secret_version
586
+
587
+ // Request models needed by this operation.
588
+
589
+ // ArbitrarySecretVersionPrototype
590
+ const secretVersionPrototypeModel = {
591
+ payload: 'updated secret credentials',
592
+ custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
593
+ version_custom_metadata: { custom_version_key: 'custom_version_value' },
594
+ };
595
+
596
+ const params = {
597
+ secretId: secretIdForGetSecretLink,
598
+ secretVersionPrototype: secretVersionPrototypeModel,
599
+ };
600
+
601
+ let res;
602
+ try {
603
+ res = await secretsManagerService.createSecretVersion(params);
604
+ console.log(JSON.stringify(res.result, null, 2));
605
+ } catch (err) {
606
+ console.warn(err);
607
+ }
608
+
609
+ // end-create_secret_version
610
+ });
611
+
612
+ test('getSecretVersion request example', async () => {
613
+ consoleLogMock.mockImplementation((output) => {
614
+ originalLog(output);
615
+ });
616
+ consoleWarnMock.mockImplementation((output) => {
617
+ // if an error occurs, display the message and then fail the test
618
+ originalWarn(output);
619
+ expect(true).toBeFalsy();
620
+ });
621
+
622
+ originalLog('getSecretVersion() result:');
623
+ // begin-get_secret_version
624
+
625
+ const params = {
626
+ secretId: secretIdForGetSecretLink,
627
+ id: secretVersionIdForGetSecretVersionLink,
628
+ };
629
+
630
+ let res;
631
+ try {
632
+ res = await secretsManagerService.getSecretVersion(params);
633
+ console.log(JSON.stringify(res.result, null, 2));
634
+ } catch (err) {
635
+ console.warn(err);
636
+ }
637
+
638
+ // end-get_secret_version
639
+ });
640
+
641
+ test('getSecretVersionMetadata request example', async () => {
642
+ consoleLogMock.mockImplementation((output) => {
643
+ originalLog(output);
644
+ });
645
+ consoleWarnMock.mockImplementation((output) => {
646
+ // if an error occurs, display the message and then fail the test
647
+ originalWarn(output);
648
+ expect(true).toBeFalsy();
649
+ });
650
+
651
+ originalLog('getSecretVersionMetadata() result:');
652
+ // begin-get_secret_version_metadata
653
+
654
+ const params = {
655
+ secretId: secretIdForGetSecretLink,
656
+ id: secretVersionIdForGetSecretVersionLink,
657
+ };
658
+
659
+ let res;
660
+ try {
661
+ res = await secretsManagerService.getSecretVersionMetadata(params);
662
+ console.log(JSON.stringify(res.result, null, 2));
663
+ } catch (err) {
664
+ console.warn(err);
665
+ }
666
+
667
+ // end-get_secret_version_metadata
668
+ });
669
+
670
+ test('updateSecretVersionMetadata request example', async () => {
671
+ consoleLogMock.mockImplementation((output) => {
672
+ originalLog(output);
673
+ });
674
+ consoleWarnMock.mockImplementation((output) => {
675
+ // if an error occurs, display the message and then fail the test
676
+ originalWarn(output);
677
+ expect(true).toBeFalsy();
678
+ });
679
+
680
+ originalLog('updateSecretVersionMetadata() result:');
681
+ // begin-update_secret_version_metadata
682
+
683
+ const params = {
684
+ secretId: secretIdForGetSecretLink,
685
+ id: secretVersionIdForGetSecretVersionLink,
686
+ };
687
+
688
+ let res;
689
+ try {
690
+ res = await secretsManagerService.updateSecretVersionMetadata(params);
691
+ console.log(JSON.stringify(res.result, null, 2));
692
+ } catch (err) {
693
+ console.warn(err);
694
+ }
695
+
696
+ // end-update_secret_version_metadata
697
+ });
698
+
699
+ test('createSecretVersionAction request example', async () => {
700
+ consoleLogMock.mockImplementation((output) => {
701
+ originalLog(output);
702
+ });
703
+ consoleWarnMock.mockImplementation((output) => {
704
+ // if an error occurs, display the message and then fail the test
705
+ originalWarn(output);
706
+ expect(true).toBeFalsy();
707
+ });
708
+
709
+ originalLog('createSecretVersionAction() result:');
710
+ // begin-create_secret_version_action
711
+
712
+ // Request models needed by this operation.
713
+
714
+ // PrivateCertificateVersionActionRevokePrototype
715
+ const secretVersionActionPrototypeModel = {
716
+ action_type: 'private_cert_action_revoke_certificate',
717
+ };
718
+
719
+ const params = {
720
+ secretId: secretIdForGetSecretLink,
721
+ id: secretVersionIdForGetSecretVersionLink,
722
+ secretVersionActionPrototype: secretVersionActionPrototypeModel,
723
+ };
724
+
725
+ let res;
726
+ try {
727
+ res = await secretsManagerService.createSecretVersionAction(params);
728
+ console.log(JSON.stringify(res.result, null, 2));
729
+ } catch (err) {
730
+ console.warn(err);
731
+ }
732
+
733
+ // end-create_secret_version_action
734
+ });
735
+
736
+ test('listSecretsLocks request example', async () => {
737
+ consoleLogMock.mockImplementation((output) => {
738
+ originalLog(output);
739
+ });
740
+ consoleWarnMock.mockImplementation((output) => {
741
+ // if an error occurs, display the message and then fail the test
742
+ originalWarn(output);
743
+ expect(true).toBeFalsy();
744
+ });
745
+
746
+ originalLog('listSecretsLocks() result:');
747
+ // begin-list_secrets_locks
748
+
749
+ const params = {
750
+ limit: 10,
751
+ search: 'example',
752
+ groups: ['default', 'cac40995-c37a-4dcb-9506-472869077634'],
753
+ };
754
+
755
+ const allResults = [];
756
+ try {
757
+ const pager = new SecretsManagerV2.SecretsLocksPager(secretsManagerService, params);
758
+ while (pager.hasNext()) {
759
+ const nextPage = await pager.getNext();
760
+ expect(nextPage).not.toBeNull();
761
+ allResults.push(...nextPage);
762
+ }
763
+ console.log(JSON.stringify(allResults, null, 2));
764
+ } catch (err) {
765
+ console.warn(err);
766
+ }
767
+
768
+ // end-list_secrets_locks
769
+ });
770
+
771
+ test('listSecretLocks request example', async () => {
772
+ consoleLogMock.mockImplementation((output) => {
773
+ originalLog(output);
774
+ });
775
+ consoleWarnMock.mockImplementation((output) => {
776
+ // if an error occurs, display the message and then fail the test
777
+ originalWarn(output);
778
+ expect(true).toBeFalsy();
779
+ });
780
+
781
+ originalLog('listSecretLocks() result:');
782
+ // begin-list_secret_locks
783
+
784
+ const params = {
785
+ id: secretIdForGetSecretLink,
786
+ limit: 10,
787
+ sort: 'name',
788
+ search: 'example',
789
+ };
790
+
791
+ const allResults = [];
792
+ try {
793
+ const pager = new SecretsManagerV2.SecretLocksPager(secretsManagerService, params);
794
+ while (pager.hasNext()) {
795
+ const nextPage = await pager.getNext();
796
+ expect(nextPage).not.toBeNull();
797
+ allResults.push(...nextPage);
798
+ }
799
+ console.log(JSON.stringify(allResults, null, 2));
800
+ } catch (err) {
801
+ console.warn(err);
802
+ }
803
+
804
+ // end-list_secret_locks
805
+ });
806
+
807
+ test('createSecretVersionLocksBulk request example', async () => {
808
+ consoleLogMock.mockImplementation((output) => {
809
+ originalLog(output);
810
+ });
811
+ consoleWarnMock.mockImplementation((output) => {
812
+ // if an error occurs, display the message and then fail the test
813
+ originalWarn(output);
814
+ expect(true).toBeFalsy();
815
+ });
816
+
817
+ originalLog('createSecretVersionLocksBulk() result:');
818
+ // begin-create_secret_version_locks_bulk
819
+
820
+ // Request models needed by this operation.
821
+
822
+ // SecretLockPrototype
823
+ const secretLockPrototypeModel = {
824
+ name: 'lock-example-1',
825
+ description: 'lock for consumer 1',
826
+ attributes: { key: 'value' },
827
+ };
828
+
829
+ const params = {
830
+ secretId: secretIdForGetSecretLink,
831
+ id: secretVersionIdForGetSecretVersionLink,
832
+ locks: [secretLockPrototypeModel],
833
+ };
834
+
835
+ let res;
836
+ try {
837
+ res = await secretsManagerService.createSecretVersionLocksBulk(params);
838
+ console.log(JSON.stringify(res.result, null, 2));
839
+ } catch (err) {
840
+ console.warn(err);
841
+ }
842
+
843
+ // end-create_secret_version_locks_bulk
844
+ });
845
+
846
+ test('listSecretVersionLocks request example', async () => {
847
+ consoleLogMock.mockImplementation((output) => {
848
+ originalLog(output);
849
+ });
850
+ consoleWarnMock.mockImplementation((output) => {
851
+ // if an error occurs, display the message and then fail the test
852
+ originalWarn(output);
853
+ expect(true).toBeFalsy();
854
+ });
855
+
856
+ originalLog('listSecretVersionLocks() result:');
857
+ // begin-list_secret_version_locks
858
+
859
+ const params = {
860
+ secretId: secretIdForGetSecretLink,
861
+ id: secretVersionIdForGetSecretVersionLink,
862
+ limit: 10,
863
+ sort: 'name',
864
+ search: 'example',
865
+ };
866
+
867
+ const allResults = [];
868
+ try {
869
+ const pager = new SecretsManagerV2.SecretVersionLocksPager(secretsManagerService, params);
870
+ while (pager.hasNext()) {
871
+ const nextPage = await pager.getNext();
872
+ expect(nextPage).not.toBeNull();
873
+ allResults.push(...nextPage);
874
+ }
875
+ console.log(JSON.stringify(allResults, null, 2));
876
+ } catch (err) {
877
+ console.warn(err);
878
+ }
879
+
880
+ // end-list_secret_version_locks
881
+ });
882
+
883
+ test('listConfigurations request example', async () => {
884
+ consoleLogMock.mockImplementation((output) => {
885
+ originalLog(output);
886
+ });
887
+ consoleWarnMock.mockImplementation((output) => {
888
+ // if an error occurs, display the message and then fail the test
889
+ originalWarn(output);
890
+ expect(true).toBeFalsy();
891
+ });
892
+
893
+ originalLog('listConfigurations() result:');
894
+ // begin-list_configurations
895
+
896
+ const params = {
897
+ limit: 10,
898
+ sort: 'config_type',
899
+ search: 'example',
900
+ };
901
+
902
+ const allResults = [];
903
+ try {
904
+ const pager = new SecretsManagerV2.ConfigurationsPager(secretsManagerService, params);
905
+ while (pager.hasNext()) {
906
+ const nextPage = await pager.getNext();
907
+ expect(nextPage).not.toBeNull();
908
+ allResults.push(...nextPage);
909
+ }
910
+ console.log(JSON.stringify(allResults, null, 2));
911
+ } catch (err) {
912
+ console.warn(err);
913
+ }
914
+
915
+ // end-list_configurations
916
+ });
917
+
918
+ test('getConfiguration request example', async () => {
919
+ consoleLogMock.mockImplementation((output) => {
920
+ originalLog(output);
921
+ });
922
+ consoleWarnMock.mockImplementation((output) => {
923
+ // if an error occurs, display the message and then fail the test
924
+ originalWarn(output);
925
+ expect(true).toBeFalsy();
926
+ });
927
+
928
+ originalLog('getConfiguration() result:');
929
+ // begin-get_configuration
930
+
931
+ const params = {
932
+ name: configurationNameForGetConfigurationLink,
933
+ xSmAcceptConfigurationType: 'private_cert_configuration_root_ca',
934
+ };
935
+
936
+ let res;
937
+ try {
938
+ res = await secretsManagerService.getConfiguration(params);
939
+ console.log(JSON.stringify(res.result, null, 2));
940
+ } catch (err) {
941
+ console.warn(err);
942
+ }
943
+
944
+ // end-get_configuration
945
+ });
946
+
947
+ test('updateConfiguration request example', async () => {
948
+ consoleLogMock.mockImplementation((output) => {
949
+ originalLog(output);
950
+ });
951
+ consoleWarnMock.mockImplementation((output) => {
952
+ // if an error occurs, display the message and then fail the test
953
+ originalWarn(output);
954
+ expect(true).toBeFalsy();
955
+ });
956
+
957
+ originalLog('updateConfiguration() result:');
958
+ // begin-update_configuration
959
+
960
+ // Request models needed by this operation.
961
+
962
+ // IAMCredentialsConfigurationPatch
963
+ const configurationPatchModel = {
964
+ api_key: 'RmnPBn6n1dzoo0v3kyznKEpg0WzdTpW9lW7FtKa017_u',
965
+ };
966
+
967
+ const params = {
968
+ name: configurationNameForGetConfigurationLink,
969
+ configurationPatch: configurationPatchModel,
970
+ xSmAcceptConfigurationType: 'private_cert_configuration_root_ca',
971
+ };
972
+
973
+ let res;
974
+ try {
975
+ res = await secretsManagerService.updateConfiguration(params);
976
+ console.log(JSON.stringify(res.result, null, 2));
977
+ } catch (err) {
978
+ console.warn(err);
979
+ }
980
+
981
+ // end-update_configuration
982
+ });
983
+
984
+ test('createConfigurationAction request example', async () => {
985
+ consoleLogMock.mockImplementation((output) => {
986
+ originalLog(output);
987
+ });
988
+ consoleWarnMock.mockImplementation((output) => {
989
+ // if an error occurs, display the message and then fail the test
990
+ originalWarn(output);
991
+ expect(true).toBeFalsy();
992
+ });
993
+
994
+ originalLog('createConfigurationAction() result:');
995
+ // begin-create_configuration_action
996
+
997
+ // Request models needed by this operation.
998
+
999
+ // PrivateCertificateConfigurationActionRotateCRLPrototype
1000
+ const configurationActionPrototypeModel = {
1001
+ action_type: 'private_cert_configuration_action_rotate_crl',
1002
+ };
1003
+
1004
+ const params = {
1005
+ name: configurationNameForGetConfigurationLink,
1006
+ configActionPrototype: configurationActionPrototypeModel,
1007
+ xSmAcceptConfigurationType: 'private_cert_configuration_root_ca',
1008
+ };
1009
+
1010
+ let res;
1011
+ try {
1012
+ res = await secretsManagerService.createConfigurationAction(params);
1013
+ console.log(JSON.stringify(res.result, null, 2));
1014
+ } catch (err) {
1015
+ console.warn(err);
1016
+ }
1017
+
1018
+ // end-create_configuration_action
1019
+ });
1020
+
1021
+ test('createNotificationsRegistration request example', async () => {
1022
+ consoleLogMock.mockImplementation((output) => {
1023
+ originalLog(output);
1024
+ });
1025
+ consoleWarnMock.mockImplementation((output) => {
1026
+ // if an error occurs, display the message and then fail the test
1027
+ originalWarn(output);
1028
+ expect(true).toBeFalsy();
1029
+ });
1030
+
1031
+ originalLog('createNotificationsRegistration() result:');
1032
+ // begin-create_notifications_registration
1033
+
1034
+ const params = {
1035
+ eventNotificationsInstanceCrn: 'crn:v1:bluemix:public:event-notifications:us-south:a/22018f3c34ff4ff193698d15ca316946:578ad1a4-2fd8-4e66-95d5-79a842ba91f8::',
1036
+ eventNotificationsSourceName: 'My Secrets Manager',
1037
+ eventNotificationsSourceDescription: 'Optional description of this source in an Event Notifications instance.',
1038
+ };
1039
+
1040
+ let res;
1041
+ try {
1042
+ res = await secretsManagerService.createNotificationsRegistration(params);
1043
+ console.log(JSON.stringify(res.result, null, 2));
1044
+ } catch (err) {
1045
+ console.warn(err);
1046
+ }
1047
+
1048
+ // end-create_notifications_registration
1049
+ });
1050
+
1051
+ test('getNotificationsRegistration request example', async () => {
1052
+ consoleLogMock.mockImplementation((output) => {
1053
+ originalLog(output);
1054
+ });
1055
+ consoleWarnMock.mockImplementation((output) => {
1056
+ // if an error occurs, display the message and then fail the test
1057
+ originalWarn(output);
1058
+ expect(true).toBeFalsy();
1059
+ });
1060
+
1061
+ originalLog('getNotificationsRegistration() result:');
1062
+ // begin-get_notifications_registration
1063
+
1064
+ let res;
1065
+ try {
1066
+ res = await secretsManagerService.getNotificationsRegistration({});
1067
+ console.log(JSON.stringify(res.result, null, 2));
1068
+ } catch (err) {
1069
+ console.warn(err);
1070
+ }
1071
+
1072
+ // end-get_notifications_registration
1073
+ });
1074
+
1075
+ test('getNotificationsRegistrationTest request example', async () => {
1076
+ consoleLogMock.mockImplementation((output) => {
1077
+ originalLog(output);
1078
+ });
1079
+ consoleWarnMock.mockImplementation((output) => {
1080
+ // if an error occurs, display the message and then fail the test
1081
+ originalWarn(output);
1082
+ expect(true).toBeFalsy();
1083
+ });
1084
+
1085
+ // begin-get_notifications_registration_test
1086
+
1087
+ try {
1088
+ await secretsManagerService.getNotificationsRegistrationTest({});
1089
+ } catch (err) {
1090
+ console.warn(err);
1091
+ }
1092
+
1093
+ // end-get_notifications_registration_test
1094
+ });
1095
+
1096
+ test('deleteSecretGroup request example', async () => {
1097
+ consoleLogMock.mockImplementation((output) => {
1098
+ originalLog(output);
1099
+ });
1100
+ consoleWarnMock.mockImplementation((output) => {
1101
+ // if an error occurs, display the message and then fail the test
1102
+ originalWarn(output);
1103
+ expect(true).toBeFalsy();
1104
+ });
1105
+
1106
+ // begin-delete_secret_group
1107
+
1108
+ const params = {
1109
+ id: secretGroupIdForGetSecretGroupLink,
1110
+ };
1111
+
1112
+ try {
1113
+ await secretsManagerService.deleteSecretGroup(params);
1114
+ } catch (err) {
1115
+ console.warn(err);
1116
+ }
1117
+
1118
+ // end-delete_secret_group
1119
+ });
1120
+
1121
+ test('deleteSecretVersionData request example', async () => {
1122
+ consoleLogMock.mockImplementation((output) => {
1123
+ originalLog(output);
1124
+ });
1125
+ consoleWarnMock.mockImplementation((output) => {
1126
+ // if an error occurs, display the message and then fail the test
1127
+ originalWarn(output);
1128
+ expect(true).toBeFalsy();
1129
+ });
1130
+
1131
+ // begin-delete_secret_version_data
1132
+
1133
+ const params = {
1134
+ secretId: secretIdForGetSecretLink,
1135
+ id: secretVersionIdForGetSecretVersionLink,
1136
+ };
1137
+
1138
+ try {
1139
+ await secretsManagerService.deleteSecretVersionData(params);
1140
+ } catch (err) {
1141
+ console.warn(err);
1142
+ }
1143
+
1144
+ // end-delete_secret_version_data
1145
+ });
1146
+
1147
+ test('deleteSecretLocksBulk request example', async () => {
1148
+ consoleLogMock.mockImplementation((output) => {
1149
+ originalLog(output);
1150
+ });
1151
+ consoleWarnMock.mockImplementation((output) => {
1152
+ // if an error occurs, display the message and then fail the test
1153
+ originalWarn(output);
1154
+ expect(true).toBeFalsy();
1155
+ });
1156
+
1157
+ originalLog('deleteSecretLocksBulk() result:');
1158
+ // begin-delete_secret_locks_bulk
1159
+
1160
+ const params = {
1161
+ id: secretIdForGetSecretLink,
1162
+ name: ['lock-example-1'],
1163
+ };
1164
+
1165
+ let res;
1166
+ try {
1167
+ res = await secretsManagerService.deleteSecretLocksBulk(params);
1168
+ console.log(JSON.stringify(res.result, null, 2));
1169
+ } catch (err) {
1170
+ console.warn(err);
1171
+ }
1172
+
1173
+ // end-delete_secret_locks_bulk
1174
+ });
1175
+
1176
+ test('deleteSecretVersionLocksBulk request example', async () => {
1177
+ consoleLogMock.mockImplementation((output) => {
1178
+ originalLog(output);
1179
+ });
1180
+ consoleWarnMock.mockImplementation((output) => {
1181
+ // if an error occurs, display the message and then fail the test
1182
+ originalWarn(output);
1183
+ expect(true).toBeFalsy();
1184
+ });
1185
+
1186
+ originalLog('deleteSecretVersionLocksBulk() result:');
1187
+ // begin-delete_secret_version_locks_bulk
1188
+
1189
+ const params = {
1190
+ secretId: secretIdForGetSecretLink,
1191
+ id: secretVersionIdForGetSecretVersionLink,
1192
+ name: ['lock-example-1'],
1193
+ };
1194
+
1195
+ let res;
1196
+ try {
1197
+ res = await secretsManagerService.deleteSecretVersionLocksBulk(params);
1198
+ console.log(JSON.stringify(res.result, null, 2));
1199
+ } catch (err) {
1200
+ console.warn(err);
1201
+ }
1202
+
1203
+ // end-delete_secret_version_locks_bulk
1204
+ });
1205
+
1206
+ test('deleteSecret request example', async () => {
1207
+ consoleLogMock.mockImplementation((output) => {
1208
+ originalLog(output);
1209
+ });
1210
+ consoleWarnMock.mockImplementation((output) => {
1211
+ // if an error occurs, display the message and then fail the test
1212
+ originalWarn(output);
1213
+ expect(true).toBeFalsy();
1214
+ });
1215
+
1216
+ // begin-delete_secret
1217
+
1218
+ const params = {
1219
+ id: secretIdForGetSecretLink,
1220
+ };
1221
+
1222
+ try {
1223
+ await secretsManagerService.deleteSecret(params);
1224
+ } catch (err) {
1225
+ console.warn(err);
1226
+ }
1227
+
1228
+ // end-delete_secret
1229
+ });
1230
+
1231
+ test('deleteConfiguration request example', async () => {
1232
+ consoleLogMock.mockImplementation((output) => {
1233
+ originalLog(output);
1234
+ });
1235
+ consoleWarnMock.mockImplementation((output) => {
1236
+ // if an error occurs, display the message and then fail the test
1237
+ originalWarn(output);
1238
+ expect(true).toBeFalsy();
1239
+ });
1240
+
1241
+ // begin-delete_configuration
1242
+
1243
+ const params = {
1244
+ name: configurationNameForGetConfigurationLink,
1245
+ xSmAcceptConfigurationType: 'private_cert_configuration_root_ca',
1246
+ };
1247
+
1248
+ try {
1249
+ await secretsManagerService.deleteConfiguration(params);
1250
+ } catch (err) {
1251
+ console.warn(err);
1252
+ }
1253
+
1254
+ // end-delete_configuration
1255
+ });
1256
+
1257
+ test('deleteNotificationsRegistration request example', async () => {
1258
+ consoleLogMock.mockImplementation((output) => {
1259
+ originalLog(output);
1260
+ });
1261
+ consoleWarnMock.mockImplementation((output) => {
1262
+ // if an error occurs, display the message and then fail the test
1263
+ originalWarn(output);
1264
+ expect(true).toBeFalsy();
1265
+ });
1266
+
1267
+ // begin-delete_notifications_registration
1268
+
1269
+ try {
1270
+ await secretsManagerService.deleteNotificationsRegistration({});
1271
+ } catch (err) {
1272
+ console.warn(err);
1273
+ }
1274
+
1275
+ // end-delete_notifications_registration
1276
+ });
1277
+ });