@ibm-cloud/secrets-manager 2.1.0 → 2.1.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.
@@ -1,1393 +0,0 @@
1
- /**
2
- * @jest-environment node
3
- */
4
- /**
5
- * (C) Copyright IBM Corp. 2025.
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: '2030-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
- // PublicCertificateConfigurationDNSCloudInternetServicesPrototype
297
- const configurationPrototypeModel = {
298
- config_type: 'public_cert_configuration_dns_cloud_internet_services',
299
- name: 'example-cloud-internet-services-config',
300
- cloud_internet_services_apikey: '5ipu_ykv0PMp2MhxQnDMn7VzrkSlBwi3BOI8uthi_EXZ',
301
- cloud_internet_services_crn: 'crn:v1:bluemix:public:internet-svcs:global:a/128e84fcca45c1224aae525d31ef2b52:009a0357-1460-42b4-b903-10580aba7dd8::',
302
- };
303
-
304
- const params = {
305
- configurationPrototype: configurationPrototypeModel,
306
- };
307
-
308
- let res;
309
- try {
310
- res = await secretsManagerService.createConfiguration(params);
311
- console.log(JSON.stringify(res.result, null, 2));
312
- } catch (err) {
313
- console.warn(err);
314
- }
315
-
316
- // end-create_configuration
317
- const responseBody = res.result;
318
- configurationNameForGetConfigurationLink = responseBody.name;
319
- });
320
-
321
- test('listSecretGroups request example', async () => {
322
- consoleLogMock.mockImplementation((output) => {
323
- originalLog(output);
324
- });
325
- consoleWarnMock.mockImplementation((output) => {
326
- // if an error occurs, display the message and then fail the test
327
- originalWarn(output);
328
- expect(true).toBeFalsy();
329
- });
330
-
331
- originalLog('listSecretGroups() result:');
332
- // begin-list_secret_groups
333
-
334
- let res;
335
- try {
336
- res = await secretsManagerService.listSecretGroups({});
337
- console.log(JSON.stringify(res.result, null, 2));
338
- } catch (err) {
339
- console.warn(err);
340
- }
341
-
342
- // end-list_secret_groups
343
- });
344
-
345
- test('getSecretGroup request example', async () => {
346
- consoleLogMock.mockImplementation((output) => {
347
- originalLog(output);
348
- });
349
- consoleWarnMock.mockImplementation((output) => {
350
- // if an error occurs, display the message and then fail the test
351
- originalWarn(output);
352
- expect(true).toBeFalsy();
353
- });
354
-
355
- originalLog('getSecretGroup() result:');
356
- // begin-get_secret_group
357
-
358
- const params = {
359
- id: secretGroupIdForGetSecretGroupLink,
360
- };
361
-
362
- let res;
363
- try {
364
- res = await secretsManagerService.getSecretGroup(params);
365
- console.log(JSON.stringify(res.result, null, 2));
366
- } catch (err) {
367
- console.warn(err);
368
- }
369
-
370
- // end-get_secret_group
371
- });
372
-
373
- test('updateSecretGroup request example', async () => {
374
- consoleLogMock.mockImplementation((output) => {
375
- originalLog(output);
376
- });
377
- consoleWarnMock.mockImplementation((output) => {
378
- // if an error occurs, display the message and then fail the test
379
- originalWarn(output);
380
- expect(true).toBeFalsy();
381
- });
382
-
383
- originalLog('updateSecretGroup() result:');
384
- // begin-update_secret_group
385
-
386
- const params = {
387
- id: secretGroupIdForGetSecretGroupLink,
388
- };
389
-
390
- let res;
391
- try {
392
- res = await secretsManagerService.updateSecretGroup(params);
393
- console.log(JSON.stringify(res.result, null, 2));
394
- } catch (err) {
395
- console.warn(err);
396
- }
397
-
398
- // end-update_secret_group
399
- });
400
-
401
- test('listSecrets request example', async () => {
402
- consoleLogMock.mockImplementation((output) => {
403
- originalLog(output);
404
- });
405
- consoleWarnMock.mockImplementation((output) => {
406
- // if an error occurs, display the message and then fail the test
407
- originalWarn(output);
408
- expect(true).toBeFalsy();
409
- });
410
-
411
- originalLog('listSecrets() result:');
412
- // begin-list_secrets
413
-
414
- const params = {
415
- limit: 10,
416
- sort: 'created_at',
417
- search: 'example',
418
- groups: ['default', 'cac40995-c37a-4dcb-9506-472869077634'],
419
- secretTypes: ['arbitrary', 'kv'],
420
- matchAllLabels: ['dev', 'us-south'],
421
- };
422
-
423
- const allResults = [];
424
- try {
425
- const pager = new SecretsManagerV2.SecretsPager(secretsManagerService, params);
426
- while (pager.hasNext()) {
427
- const nextPage = await pager.getNext();
428
- expect(nextPage).not.toBeNull();
429
- allResults.push(...nextPage);
430
- }
431
- console.log(JSON.stringify(allResults, null, 2));
432
- } catch (err) {
433
- console.warn(err);
434
- }
435
-
436
- // end-list_secrets
437
- });
438
-
439
- test('getSecret request example', async () => {
440
- consoleLogMock.mockImplementation((output) => {
441
- originalLog(output);
442
- });
443
- consoleWarnMock.mockImplementation((output) => {
444
- // if an error occurs, display the message and then fail the test
445
- originalWarn(output);
446
- expect(true).toBeFalsy();
447
- });
448
-
449
- originalLog('getSecret() result:');
450
- // begin-get_secret
451
-
452
- const params = {
453
- id: secretIdForGetSecretLink,
454
- };
455
-
456
- let res;
457
- try {
458
- res = await secretsManagerService.getSecret(params);
459
- console.log(JSON.stringify(res.result, null, 2));
460
- } catch (err) {
461
- console.warn(err);
462
- }
463
-
464
- // end-get_secret
465
- });
466
-
467
- test('getSecretMetadata request example', async () => {
468
- consoleLogMock.mockImplementation((output) => {
469
- originalLog(output);
470
- });
471
- consoleWarnMock.mockImplementation((output) => {
472
- // if an error occurs, display the message and then fail the test
473
- originalWarn(output);
474
- expect(true).toBeFalsy();
475
- });
476
-
477
- originalLog('getSecretMetadata() result:');
478
- // begin-get_secret_metadata
479
-
480
- const params = {
481
- id: secretIdForGetSecretLink,
482
- };
483
-
484
- let res;
485
- try {
486
- res = await secretsManagerService.getSecretMetadata(params);
487
- console.log(JSON.stringify(res.result, null, 2));
488
- } catch (err) {
489
- console.warn(err);
490
- }
491
-
492
- // end-get_secret_metadata
493
- });
494
-
495
- test('createSecretAction request example', async () => {
496
- consoleLogMock.mockImplementation((output) => {
497
- originalLog(output);
498
- });
499
- consoleWarnMock.mockImplementation((output) => {
500
- // if an error occurs, display the message and then fail the test
501
- originalWarn(output);
502
- expect(true).toBeFalsy();
503
- });
504
-
505
- originalLog('createSecretAction() result:');
506
- // begin-create_secret_action
507
-
508
- // Request models needed by this operation.
509
-
510
- // PrivateCertificateActionRevokePrototype
511
- const secretActionPrototypeModel = {
512
- action_type: 'private_cert_action_revoke_certificate',
513
- };
514
-
515
- const params = {
516
- id: secretIdForGetSecretLink,
517
- secretActionPrototype: secretActionPrototypeModel,
518
- };
519
-
520
- let res;
521
- try {
522
- res = await secretsManagerService.createSecretAction(params);
523
- console.log(JSON.stringify(res.result, null, 2));
524
- } catch (err) {
525
- console.warn(err);
526
- }
527
-
528
- // end-create_secret_action
529
- });
530
-
531
- test('getSecretByNameType request example', async () => {
532
- consoleLogMock.mockImplementation((output) => {
533
- originalLog(output);
534
- });
535
- consoleWarnMock.mockImplementation((output) => {
536
- // if an error occurs, display the message and then fail the test
537
- originalWarn(output);
538
- expect(true).toBeFalsy();
539
- });
540
-
541
- originalLog('getSecretByNameType() result:');
542
- // begin-get_secret_by_name_type
543
-
544
- const params = {
545
- secretType: 'arbitrary',
546
- name: secretNameLink,
547
- secretGroupName: 'default',
548
- };
549
-
550
- let res;
551
- try {
552
- res = await secretsManagerService.getSecretByNameType(params);
553
- console.log(JSON.stringify(res.result, null, 2));
554
- } catch (err) {
555
- console.warn(err);
556
- }
557
-
558
- // end-get_secret_by_name_type
559
- });
560
-
561
- test('createSecretVersion request example', async () => {
562
- consoleLogMock.mockImplementation((output) => {
563
- originalLog(output);
564
- });
565
- consoleWarnMock.mockImplementation((output) => {
566
- // if an error occurs, display the message and then fail the test
567
- originalWarn(output);
568
- expect(true).toBeFalsy();
569
- });
570
-
571
- originalLog('createSecretVersion() result:');
572
- // begin-create_secret_version
573
-
574
- // Request models needed by this operation.
575
-
576
- // ArbitrarySecretVersionPrototype
577
- const secretVersionPrototypeModel = {
578
- payload: 'updated secret credentials',
579
- custom_metadata: { metadata_custom_key: 'metadata_custom_value' },
580
- version_custom_metadata: { custom_version_key: 'custom_version_value' },
581
- };
582
-
583
- const params = {
584
- secretId: secretIdForGetSecretLink,
585
- secretVersionPrototype: secretVersionPrototypeModel,
586
- };
587
-
588
- let res;
589
- try {
590
- res = await secretsManagerService.createSecretVersion(params);
591
- console.log(JSON.stringify(res.result, null, 2));
592
- } catch (err) {
593
- console.warn(err);
594
- }
595
-
596
- // end-create_secret_version
597
- });
598
-
599
- test('getSecretVersion request example', async () => {
600
- consoleLogMock.mockImplementation((output) => {
601
- originalLog(output);
602
- });
603
- consoleWarnMock.mockImplementation((output) => {
604
- // if an error occurs, display the message and then fail the test
605
- originalWarn(output);
606
- expect(true).toBeFalsy();
607
- });
608
-
609
- originalLog('getSecretVersion() result:');
610
- // begin-get_secret_version
611
-
612
- const params = {
613
- secretId: secretIdForGetSecretLink,
614
- id: secretVersionIdForGetSecretVersionLink,
615
- };
616
-
617
- let res;
618
- try {
619
- res = await secretsManagerService.getSecretVersion(params);
620
- console.log(JSON.stringify(res.result, null, 2));
621
- } catch (err) {
622
- console.warn(err);
623
- }
624
-
625
- // end-get_secret_version
626
- });
627
-
628
- test('getSecretVersionMetadata request example', async () => {
629
- consoleLogMock.mockImplementation((output) => {
630
- originalLog(output);
631
- });
632
- consoleWarnMock.mockImplementation((output) => {
633
- // if an error occurs, display the message and then fail the test
634
- originalWarn(output);
635
- expect(true).toBeFalsy();
636
- });
637
-
638
- originalLog('getSecretVersionMetadata() result:');
639
- // begin-get_secret_version_metadata
640
-
641
- const params = {
642
- secretId: secretIdForGetSecretLink,
643
- id: secretVersionIdForGetSecretVersionLink,
644
- };
645
-
646
- let res;
647
- try {
648
- res = await secretsManagerService.getSecretVersionMetadata(params);
649
- console.log(JSON.stringify(res.result, null, 2));
650
- } catch (err) {
651
- console.warn(err);
652
- }
653
-
654
- // end-get_secret_version_metadata
655
- });
656
-
657
- test('updateSecretVersionMetadata request example', async () => {
658
- consoleLogMock.mockImplementation((output) => {
659
- originalLog(output);
660
- });
661
- consoleWarnMock.mockImplementation((output) => {
662
- // if an error occurs, display the message and then fail the test
663
- originalWarn(output);
664
- expect(true).toBeFalsy();
665
- });
666
-
667
- originalLog('updateSecretVersionMetadata() result:');
668
- // begin-update_secret_version_metadata
669
-
670
- const params = {
671
- secretId: secretIdForGetSecretLink,
672
- id: secretVersionIdForGetSecretVersionLink,
673
- };
674
-
675
- let res;
676
- try {
677
- res = await secretsManagerService.updateSecretVersionMetadata(params);
678
- console.log(JSON.stringify(res.result, null, 2));
679
- } catch (err) {
680
- console.warn(err);
681
- }
682
-
683
- // end-update_secret_version_metadata
684
- });
685
-
686
- test('createSecretVersionAction request example', async () => {
687
- consoleLogMock.mockImplementation((output) => {
688
- originalLog(output);
689
- });
690
- consoleWarnMock.mockImplementation((output) => {
691
- // if an error occurs, display the message and then fail the test
692
- originalWarn(output);
693
- expect(true).toBeFalsy();
694
- });
695
-
696
- originalLog('createSecretVersionAction() result:');
697
- // begin-create_secret_version_action
698
-
699
- // Request models needed by this operation.
700
-
701
- // PrivateCertificateVersionActionRevokePrototype
702
- const secretVersionActionPrototypeModel = {
703
- action_type: 'private_cert_action_revoke_certificate',
704
- };
705
-
706
- const params = {
707
- secretId: secretIdForGetSecretLink,
708
- id: secretVersionIdForGetSecretVersionLink,
709
- secretVersionActionPrototype: secretVersionActionPrototypeModel,
710
- };
711
-
712
- let res;
713
- try {
714
- res = await secretsManagerService.createSecretVersionAction(params);
715
- console.log(JSON.stringify(res.result, null, 2));
716
- } catch (err) {
717
- console.warn(err);
718
- }
719
-
720
- // end-create_secret_version_action
721
- });
722
-
723
- test('listSecretTasks request example', async () => {
724
- consoleLogMock.mockImplementation((output) => {
725
- originalLog(output);
726
- });
727
- consoleWarnMock.mockImplementation((output) => {
728
- // if an error occurs, display the message and then fail the test
729
- originalWarn(output);
730
- expect(true).toBeFalsy();
731
- });
732
-
733
- originalLog('listSecretTasks() result:');
734
- // begin-list_secret_tasks
735
-
736
- const params = {
737
- secretId: secretIdForGetSecretLink,
738
- };
739
-
740
- let res;
741
- try {
742
- res = await secretsManagerService.listSecretTasks(params);
743
- console.log(JSON.stringify(res.result, null, 2));
744
- } catch (err) {
745
- console.warn(err);
746
- }
747
-
748
- // end-list_secret_tasks
749
- });
750
-
751
- test('getSecretTask request example', async () => {
752
- consoleLogMock.mockImplementation((output) => {
753
- originalLog(output);
754
- });
755
- consoleWarnMock.mockImplementation((output) => {
756
- // if an error occurs, display the message and then fail the test
757
- originalWarn(output);
758
- expect(true).toBeFalsy();
759
- });
760
-
761
- originalLog('getSecretTask() result:');
762
- // begin-get_secret_task
763
-
764
- const params = {
765
- secretId: secretIdForGetSecretLink,
766
- id: secretIdForGetSecretLink,
767
- };
768
-
769
- let res;
770
- try {
771
- res = await secretsManagerService.getSecretTask(params);
772
- console.log(JSON.stringify(res.result, null, 2));
773
- } catch (err) {
774
- console.warn(err);
775
- }
776
-
777
- // end-get_secret_task
778
- });
779
-
780
- test('replaceSecretTask request example', async () => {
781
- consoleLogMock.mockImplementation((output) => {
782
- originalLog(output);
783
- });
784
- consoleWarnMock.mockImplementation((output) => {
785
- // if an error occurs, display the message and then fail the test
786
- originalWarn(output);
787
- expect(true).toBeFalsy();
788
- });
789
-
790
- originalLog('replaceSecretTask() result:');
791
- // begin-replace_secret_task
792
-
793
- // Request models needed by this operation.
794
-
795
- // CustomCredentialsNewCredentials
796
- const customCredentialsNewCredentialsModel = {
797
- id: 'b49ad24d-81d4-5ebc-b9b9-b0937d1c84d5',
798
- payload: { token: 'xF9v7OztItL5DOnFgHfS9NCT1sLTUew8KYZcZfxI' },
799
- };
800
-
801
- // SecretTaskPrototypeUpdateSecretTaskCredentialsCreated
802
- const secretTaskPrototypeModel = {
803
- status: 'credentials_created',
804
- credentials: customCredentialsNewCredentialsModel,
805
- };
806
-
807
- const params = {
808
- secretId: secretIdForGetSecretLink,
809
- id: secretIdForGetSecretLink,
810
- taskPut: secretTaskPrototypeModel,
811
- };
812
-
813
- let res;
814
- try {
815
- res = await secretsManagerService.replaceSecretTask(params);
816
- console.log(JSON.stringify(res.result, null, 2));
817
- } catch (err) {
818
- console.warn(err);
819
- }
820
-
821
- // end-replace_secret_task
822
- });
823
-
824
- test('listSecretsLocks request example', async () => {
825
- consoleLogMock.mockImplementation((output) => {
826
- originalLog(output);
827
- });
828
- consoleWarnMock.mockImplementation((output) => {
829
- // if an error occurs, display the message and then fail the test
830
- originalWarn(output);
831
- expect(true).toBeFalsy();
832
- });
833
-
834
- originalLog('listSecretsLocks() result:');
835
- // begin-list_secrets_locks
836
-
837
- const params = {
838
- limit: 10,
839
- search: 'example',
840
- groups: ['default', 'cac40995-c37a-4dcb-9506-472869077634'],
841
- };
842
-
843
- const allResults = [];
844
- try {
845
- const pager = new SecretsManagerV2.SecretsLocksPager(secretsManagerService, params);
846
- while (pager.hasNext()) {
847
- const nextPage = await pager.getNext();
848
- expect(nextPage).not.toBeNull();
849
- allResults.push(...nextPage);
850
- }
851
- console.log(JSON.stringify(allResults, null, 2));
852
- } catch (err) {
853
- console.warn(err);
854
- }
855
-
856
- // end-list_secrets_locks
857
- });
858
-
859
- test('listSecretLocks request example', async () => {
860
- consoleLogMock.mockImplementation((output) => {
861
- originalLog(output);
862
- });
863
- consoleWarnMock.mockImplementation((output) => {
864
- // if an error occurs, display the message and then fail the test
865
- originalWarn(output);
866
- expect(true).toBeFalsy();
867
- });
868
-
869
- originalLog('listSecretLocks() result:');
870
- // begin-list_secret_locks
871
-
872
- const params = {
873
- id: secretIdForGetSecretLink,
874
- limit: 10,
875
- sort: 'name',
876
- search: 'example',
877
- };
878
-
879
- const allResults = [];
880
- try {
881
- const pager = new SecretsManagerV2.SecretLocksPager(secretsManagerService, params);
882
- while (pager.hasNext()) {
883
- const nextPage = await pager.getNext();
884
- expect(nextPage).not.toBeNull();
885
- allResults.push(...nextPage);
886
- }
887
- console.log(JSON.stringify(allResults, null, 2));
888
- } catch (err) {
889
- console.warn(err);
890
- }
891
-
892
- // end-list_secret_locks
893
- });
894
-
895
- test('createSecretVersionLocksBulk request example', async () => {
896
- consoleLogMock.mockImplementation((output) => {
897
- originalLog(output);
898
- });
899
- consoleWarnMock.mockImplementation((output) => {
900
- // if an error occurs, display the message and then fail the test
901
- originalWarn(output);
902
- expect(true).toBeFalsy();
903
- });
904
-
905
- originalLog('createSecretVersionLocksBulk() result:');
906
- // begin-create_secret_version_locks_bulk
907
-
908
- // Request models needed by this operation.
909
-
910
- // SecretLockPrototype
911
- const secretLockPrototypeModel = {
912
- name: 'lock-example-1',
913
- description: 'lock for consumer 1',
914
- attributes: { key: 'value' },
915
- };
916
-
917
- const params = {
918
- secretId: secretIdForGetSecretLink,
919
- id: secretVersionIdForGetSecretVersionLink,
920
- locks: [secretLockPrototypeModel],
921
- };
922
-
923
- let res;
924
- try {
925
- res = await secretsManagerService.createSecretVersionLocksBulk(params);
926
- console.log(JSON.stringify(res.result, null, 2));
927
- } catch (err) {
928
- console.warn(err);
929
- }
930
-
931
- // end-create_secret_version_locks_bulk
932
- });
933
-
934
- test('listSecretVersionLocks request example', async () => {
935
- consoleLogMock.mockImplementation((output) => {
936
- originalLog(output);
937
- });
938
- consoleWarnMock.mockImplementation((output) => {
939
- // if an error occurs, display the message and then fail the test
940
- originalWarn(output);
941
- expect(true).toBeFalsy();
942
- });
943
-
944
- originalLog('listSecretVersionLocks() result:');
945
- // begin-list_secret_version_locks
946
-
947
- const params = {
948
- secretId: secretIdForGetSecretLink,
949
- id: secretVersionIdForGetSecretVersionLink,
950
- limit: 10,
951
- sort: 'name',
952
- search: 'example',
953
- };
954
-
955
- const allResults = [];
956
- try {
957
- const pager = new SecretsManagerV2.SecretVersionLocksPager(secretsManagerService, params);
958
- while (pager.hasNext()) {
959
- const nextPage = await pager.getNext();
960
- expect(nextPage).not.toBeNull();
961
- allResults.push(...nextPage);
962
- }
963
- console.log(JSON.stringify(allResults, null, 2));
964
- } catch (err) {
965
- console.warn(err);
966
- }
967
-
968
- // end-list_secret_version_locks
969
- });
970
-
971
- test('listConfigurations request example', async () => {
972
- consoleLogMock.mockImplementation((output) => {
973
- originalLog(output);
974
- });
975
- consoleWarnMock.mockImplementation((output) => {
976
- // if an error occurs, display the message and then fail the test
977
- originalWarn(output);
978
- expect(true).toBeFalsy();
979
- });
980
-
981
- originalLog('listConfigurations() result:');
982
- // begin-list_configurations
983
-
984
- const params = {
985
- limit: 10,
986
- sort: 'config_type',
987
- search: 'example',
988
- secretTypes: ['iam_credentials', 'public_cert', 'private_cert', 'custom_credentials'],
989
- };
990
-
991
- const allResults = [];
992
- try {
993
- const pager = new SecretsManagerV2.ConfigurationsPager(secretsManagerService, params);
994
- while (pager.hasNext()) {
995
- const nextPage = await pager.getNext();
996
- expect(nextPage).not.toBeNull();
997
- allResults.push(...nextPage);
998
- }
999
- console.log(JSON.stringify(allResults, null, 2));
1000
- } catch (err) {
1001
- console.warn(err);
1002
- }
1003
-
1004
- // end-list_configurations
1005
- });
1006
-
1007
- test('getConfiguration request example', async () => {
1008
- consoleLogMock.mockImplementation((output) => {
1009
- originalLog(output);
1010
- });
1011
- consoleWarnMock.mockImplementation((output) => {
1012
- // if an error occurs, display the message and then fail the test
1013
- originalWarn(output);
1014
- expect(true).toBeFalsy();
1015
- });
1016
-
1017
- originalLog('getConfiguration() result:');
1018
- // begin-get_configuration
1019
-
1020
- const params = {
1021
- name: configurationNameForGetConfigurationLink,
1022
- xSmAcceptConfigurationType: 'public_cert_configuration_dns_cloud_internet_services',
1023
- };
1024
-
1025
- let res;
1026
- try {
1027
- res = await secretsManagerService.getConfiguration(params);
1028
- console.log(JSON.stringify(res.result, null, 2));
1029
- } catch (err) {
1030
- console.warn(err);
1031
- }
1032
-
1033
- // end-get_configuration
1034
- });
1035
-
1036
- test('updateConfiguration request example', async () => {
1037
- consoleLogMock.mockImplementation((output) => {
1038
- originalLog(output);
1039
- });
1040
- consoleWarnMock.mockImplementation((output) => {
1041
- // if an error occurs, display the message and then fail the test
1042
- originalWarn(output);
1043
- expect(true).toBeFalsy();
1044
- });
1045
-
1046
- originalLog('updateConfiguration() result:');
1047
- // begin-update_configuration
1048
-
1049
- // Request models needed by this operation.
1050
-
1051
- // PublicCertificateConfigurationDNSCloudInternetServicesPatch
1052
- const configurationPatchModel = {
1053
- cloud_internet_services_apikey: '5ipu_ykv0PMp2MhxQnDMn7VzrkSlBwi3BOI8uthi_EXZ',
1054
- cloud_internet_services_crn: 'crn:v1:bluemix:public:internet-svcs:global:a/128e84fcca45c1224aae525d31ef2b52:009a0357-1460-42b4-b903-10580aba7dd8::',
1055
- };
1056
-
1057
- const params = {
1058
- name: configurationNameForGetConfigurationLink,
1059
- configurationPatch: configurationPatchModel,
1060
- xSmAcceptConfigurationType: 'public_cert_configuration_dns_cloud_internet_services',
1061
- };
1062
-
1063
- let res;
1064
- try {
1065
- res = await secretsManagerService.updateConfiguration(params);
1066
- console.log(JSON.stringify(res.result, null, 2));
1067
- } catch (err) {
1068
- console.warn(err);
1069
- }
1070
-
1071
- // end-update_configuration
1072
- });
1073
-
1074
- test('createConfigurationAction request example', async () => {
1075
- consoleLogMock.mockImplementation((output) => {
1076
- originalLog(output);
1077
- });
1078
- consoleWarnMock.mockImplementation((output) => {
1079
- // if an error occurs, display the message and then fail the test
1080
- originalWarn(output);
1081
- expect(true).toBeFalsy();
1082
- });
1083
-
1084
- originalLog('createConfigurationAction() result:');
1085
- // begin-create_configuration_action
1086
-
1087
- // Request models needed by this operation.
1088
-
1089
- // PrivateCertificateConfigurationActionRotateCRLPrototype
1090
- const configurationActionPrototypeModel = {
1091
- action_type: 'private_cert_configuration_action_rotate_crl',
1092
- };
1093
-
1094
- const params = {
1095
- name: configurationNameForGetConfigurationLink,
1096
- configActionPrototype: configurationActionPrototypeModel,
1097
- xSmAcceptConfigurationType: 'public_cert_configuration_dns_cloud_internet_services',
1098
- };
1099
-
1100
- let res;
1101
- try {
1102
- res = await secretsManagerService.createConfigurationAction(params);
1103
- console.log(JSON.stringify(res.result, null, 2));
1104
- } catch (err) {
1105
- console.warn(err);
1106
- }
1107
-
1108
- // end-create_configuration_action
1109
- });
1110
-
1111
- test('createNotificationsRegistration request example', async () => {
1112
- consoleLogMock.mockImplementation((output) => {
1113
- originalLog(output);
1114
- });
1115
- consoleWarnMock.mockImplementation((output) => {
1116
- // if an error occurs, display the message and then fail the test
1117
- originalWarn(output);
1118
- expect(true).toBeFalsy();
1119
- });
1120
-
1121
- originalLog('createNotificationsRegistration() result:');
1122
- // begin-create_notifications_registration
1123
-
1124
- const params = {
1125
- eventNotificationsInstanceCrn: 'crn:v1:bluemix:public:event-notifications:us-south:a/22018f3c34ff4ff193698d15ca316946:578ad1a4-2fd8-4e66-95d5-79a842ba91f8::',
1126
- eventNotificationsSourceName: 'My Secrets Manager',
1127
- eventNotificationsSourceDescription: 'Optional description of this source in an Event Notifications instance.',
1128
- };
1129
-
1130
- let res;
1131
- try {
1132
- res = await secretsManagerService.createNotificationsRegistration(params);
1133
- console.log(JSON.stringify(res.result, null, 2));
1134
- } catch (err) {
1135
- console.warn(err);
1136
- }
1137
-
1138
- // end-create_notifications_registration
1139
- });
1140
-
1141
- test('getNotificationsRegistration request example', async () => {
1142
- consoleLogMock.mockImplementation((output) => {
1143
- originalLog(output);
1144
- });
1145
- consoleWarnMock.mockImplementation((output) => {
1146
- // if an error occurs, display the message and then fail the test
1147
- originalWarn(output);
1148
- expect(true).toBeFalsy();
1149
- });
1150
-
1151
- originalLog('getNotificationsRegistration() result:');
1152
- // begin-get_notifications_registration
1153
-
1154
- let res;
1155
- try {
1156
- res = await secretsManagerService.getNotificationsRegistration({});
1157
- console.log(JSON.stringify(res.result, null, 2));
1158
- } catch (err) {
1159
- console.warn(err);
1160
- }
1161
-
1162
- // end-get_notifications_registration
1163
- });
1164
-
1165
- test('getNotificationsRegistrationTest request example', async () => {
1166
- consoleLogMock.mockImplementation((output) => {
1167
- originalLog(output);
1168
- });
1169
- consoleWarnMock.mockImplementation((output) => {
1170
- // if an error occurs, display the message and then fail the test
1171
- originalWarn(output);
1172
- expect(true).toBeFalsy();
1173
- });
1174
-
1175
- // begin-get_notifications_registration_test
1176
-
1177
- try {
1178
- await secretsManagerService.getNotificationsRegistrationTest({});
1179
- } catch (err) {
1180
- console.warn(err);
1181
- }
1182
-
1183
- // end-get_notifications_registration_test
1184
- });
1185
-
1186
- test('deleteSecretGroup request example', async () => {
1187
- consoleLogMock.mockImplementation((output) => {
1188
- originalLog(output);
1189
- });
1190
- consoleWarnMock.mockImplementation((output) => {
1191
- // if an error occurs, display the message and then fail the test
1192
- originalWarn(output);
1193
- expect(true).toBeFalsy();
1194
- });
1195
-
1196
- // begin-delete_secret_group
1197
-
1198
- const params = {
1199
- id: secretGroupIdForGetSecretGroupLink,
1200
- };
1201
-
1202
- try {
1203
- await secretsManagerService.deleteSecretGroup(params);
1204
- } catch (err) {
1205
- console.warn(err);
1206
- }
1207
-
1208
- // end-delete_secret_group
1209
- });
1210
-
1211
- test('deleteSecretVersionData request example', async () => {
1212
- consoleLogMock.mockImplementation((output) => {
1213
- originalLog(output);
1214
- });
1215
- consoleWarnMock.mockImplementation((output) => {
1216
- // if an error occurs, display the message and then fail the test
1217
- originalWarn(output);
1218
- expect(true).toBeFalsy();
1219
- });
1220
-
1221
- // begin-delete_secret_version_data
1222
-
1223
- const params = {
1224
- secretId: secretIdForGetSecretLink,
1225
- id: secretVersionIdForGetSecretVersionLink,
1226
- };
1227
-
1228
- try {
1229
- await secretsManagerService.deleteSecretVersionData(params);
1230
- } catch (err) {
1231
- console.warn(err);
1232
- }
1233
-
1234
- // end-delete_secret_version_data
1235
- });
1236
-
1237
- test('deleteSecretLocksBulk request example', async () => {
1238
- consoleLogMock.mockImplementation((output) => {
1239
- originalLog(output);
1240
- });
1241
- consoleWarnMock.mockImplementation((output) => {
1242
- // if an error occurs, display the message and then fail the test
1243
- originalWarn(output);
1244
- expect(true).toBeFalsy();
1245
- });
1246
-
1247
- originalLog('deleteSecretLocksBulk() result:');
1248
- // begin-delete_secret_locks_bulk
1249
-
1250
- const params = {
1251
- id: secretIdForGetSecretLink,
1252
- name: ['lock-example-1'],
1253
- };
1254
-
1255
- let res;
1256
- try {
1257
- res = await secretsManagerService.deleteSecretLocksBulk(params);
1258
- console.log(JSON.stringify(res.result, null, 2));
1259
- } catch (err) {
1260
- console.warn(err);
1261
- }
1262
-
1263
- // end-delete_secret_locks_bulk
1264
- });
1265
-
1266
- test('deleteSecretVersionLocksBulk request example', async () => {
1267
- consoleLogMock.mockImplementation((output) => {
1268
- originalLog(output);
1269
- });
1270
- consoleWarnMock.mockImplementation((output) => {
1271
- // if an error occurs, display the message and then fail the test
1272
- originalWarn(output);
1273
- expect(true).toBeFalsy();
1274
- });
1275
-
1276
- originalLog('deleteSecretVersionLocksBulk() result:');
1277
- // begin-delete_secret_version_locks_bulk
1278
-
1279
- const params = {
1280
- secretId: secretIdForGetSecretLink,
1281
- id: secretVersionIdForGetSecretVersionLink,
1282
- name: ['lock-example-1'],
1283
- };
1284
-
1285
- let res;
1286
- try {
1287
- res = await secretsManagerService.deleteSecretVersionLocksBulk(params);
1288
- console.log(JSON.stringify(res.result, null, 2));
1289
- } catch (err) {
1290
- console.warn(err);
1291
- }
1292
-
1293
- // end-delete_secret_version_locks_bulk
1294
- });
1295
-
1296
- test('deleteSecret request example', async () => {
1297
- consoleLogMock.mockImplementation((output) => {
1298
- originalLog(output);
1299
- });
1300
- consoleWarnMock.mockImplementation((output) => {
1301
- // if an error occurs, display the message and then fail the test
1302
- originalWarn(output);
1303
- expect(true).toBeFalsy();
1304
- });
1305
-
1306
- // begin-delete_secret
1307
-
1308
- const params = {
1309
- id: secretIdForGetSecretLink,
1310
- };
1311
-
1312
- try {
1313
- await secretsManagerService.deleteSecret(params);
1314
- } catch (err) {
1315
- console.warn(err);
1316
- }
1317
-
1318
- // end-delete_secret
1319
- });
1320
-
1321
- test('deleteSecretTask request example', async () => {
1322
- consoleLogMock.mockImplementation((output) => {
1323
- originalLog(output);
1324
- });
1325
- consoleWarnMock.mockImplementation((output) => {
1326
- // if an error occurs, display the message and then fail the test
1327
- originalWarn(output);
1328
- expect(true).toBeFalsy();
1329
- });
1330
-
1331
- // begin-delete_secret_task
1332
-
1333
- const params = {
1334
- secretId: secretIdForGetSecretLink,
1335
- id: secretIdForGetSecretLink,
1336
- };
1337
-
1338
- try {
1339
- await secretsManagerService.deleteSecretTask(params);
1340
- } catch (err) {
1341
- console.warn(err);
1342
- }
1343
-
1344
- // end-delete_secret_task
1345
- });
1346
-
1347
- test('deleteConfiguration request example', async () => {
1348
- consoleLogMock.mockImplementation((output) => {
1349
- originalLog(output);
1350
- });
1351
- consoleWarnMock.mockImplementation((output) => {
1352
- // if an error occurs, display the message and then fail the test
1353
- originalWarn(output);
1354
- expect(true).toBeFalsy();
1355
- });
1356
-
1357
- // begin-delete_configuration
1358
-
1359
- const params = {
1360
- name: configurationNameForGetConfigurationLink,
1361
- xSmAcceptConfigurationType: 'public_cert_configuration_dns_cloud_internet_services',
1362
- };
1363
-
1364
- try {
1365
- await secretsManagerService.deleteConfiguration(params);
1366
- } catch (err) {
1367
- console.warn(err);
1368
- }
1369
-
1370
- // end-delete_configuration
1371
- });
1372
-
1373
- test('deleteNotificationsRegistration request example', async () => {
1374
- consoleLogMock.mockImplementation((output) => {
1375
- originalLog(output);
1376
- });
1377
- consoleWarnMock.mockImplementation((output) => {
1378
- // if an error occurs, display the message and then fail the test
1379
- originalWarn(output);
1380
- expect(true).toBeFalsy();
1381
- });
1382
-
1383
- // begin-delete_notifications_registration
1384
-
1385
- try {
1386
- await secretsManagerService.deleteNotificationsRegistration({});
1387
- } catch (err) {
1388
- console.warn(err);
1389
- }
1390
-
1391
- // end-delete_notifications_registration
1392
- });
1393
- });