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