forked from SalesforceCommerceCloud/sfcc-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·2168 lines (2071 loc) · 109 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env node
/*
* Copyright (c) 2020, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
var colors = require('colors');
var program = require('commander');
var { prompt } = require('inquirer');
program
.version(require('./package.json').version, '-V, --version')
.option('-D, --debug', 'enable verbose output', function() {
process.env.DEBUG = true;
process.env.NODE_DEBUG = 'request';
})
.option('--selfsigned', 'allow connection to hosts using self-signed certificates', function() {
process.env.SFCC_ALLOW_SELF_SIGNED = true;
})
.option('-I, --ignorewarnings', 'ignore any warnings logged to the console', function() {
process.env.SFCC_IGNORE_WARNINGS = true;
});
program
.command('auth:login [client] [secret]')
.option('-a, --authserver [authserver]','The authorization server used to authenticate')
.description('Authenticate a present user for interactive use')
.action(function(client, secret, options) {
require('./lib/auth').login(client, secret, options.authserver);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' Authenticate a user (resource owner) for interactive use. The user must be present and must');
console.log(' provide his login credentials as part of the authentication flow. The authentication requires');
console.log(' an API key (client).');
console.log();
console.log(' If not passed the API key is being looked up in a dw.json file in the current working');
console.log(' You may use environment variable SFCC_OAUTH_CLIENT_ID to pass the API key alternatively.');
if ( require('./lib/auth').OAUTH_AUTHORIZATION_CODE_GRANT_ALLOWED ) {
console.log();
console.log(' The client [secret] is optional. If the secret is not provided, the authentication is done');
console.log(' using the Oauth2 authorization code grant. If the secret is not provided, the ');
console.log(' authentication is done using the Oauth2 implicit grant.');
}
console.log();
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci auth:login app-client-id');
if ( require('./lib/auth').OAUTH_AUTHORIZATION_CODE_GRANT_ALLOWED ) {
console.log(' $ sfcc-ci auth:login app-client-id app-client-secret');
}
console.log(' $ sfcc-ci auth:login app-client-id -a account.demandware.com');
console.log(' $ sfcc-ci auth:login');
console.log();
});
program
.command('auth:logout')
.description('End the current sessions and clears the authentication')
.action(function() {
require('./lib/auth').cli.logout();
}).on('--help', function() {
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci auth:logout');
console.log();
});
program
.command('client:auth [client] [secret] [user] [user_password]')
.option('-a, --authserver [authserver]','The authorization server used to authenticate')
.option('-r, --renew','Controls whether the authentication should be automatically renewed, ' +
'once the token expires.')
.description('Authenticate an API client with an optional user for automation use')
.action(function(client, secret, user, user_password, options) {
var renew = ( options.renew ? options.renew : false );
require('./lib/auth').auth(client, secret, user, user_password, renew, options.authserver);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' Authenticate an API client for automation use, where presence of the resource owner is not');
console.log(' required. Optionally, user (resource owner) credentials can be provided to grant access to');
console.log(' user specific resources.');
console.log();
console.log(' The client and the client secret are optional. If not provided, client and secret are read');
console.log(' from a dw.json file located in the current working directory. You can make use of environment');
console.log(' variables SFCC_OAUTH_CLIENT_ID and SFCC_OAUTH_CLIENT_SECRET to pass the API key and secret.');
console.log();
console.log(' If user credentials are not provided, they are read from a dw.json file located in the')
console.log(' current working directory. You may use environment variables SFCC_OAUTH_USER_NAME and');
console.log(' SFCC_OAUTH_USER_PASSWORD to pass the user credentails alternatively.');
console.log();
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci client:auth my_client_id my_client_secret user_name user_password');
console.log(' $ sfcc-ci client:auth my_client_id my_client_secret');
console.log(' $ sfcc-ci client:auth my_client_id my_client_secret -r');
console.log(' $ sfcc-ci client:auth my_client_id my_client_secret -a account.demandware.com');
console.log(' $ sfcc-ci client:auth');
console.log();
});
program
.command('client:auth:renew')
.description('Renews the client authentication. Requires the initial client authentication to ' +
'be run with the --renew option.')
.action(function() {
require('./lib/auth').renew();
}).on('--help', function() {
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci client:auth:renew');
console.log();
});
program
.command('client:auth:token')
.description('Return the current authentication token')
.action(function() {
console.log(require('./lib/auth').getToken());
}).on('--help', function() {
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci client:auth:token');
console.log();
});
program
.command('data:upload')
.option('-i, --instance <instance>','Instance to upload the file to. Can be an ' +
'instance alias. If not specified the currently configured instance will be used.')
.option('-t, --target <target>', 'Target (WebDAV) location to upload to')
.option('-f, --file <file>', 'File to upload')
.option('-c, --certificate <certificate>','Path to the certificate to use for two factor authentication.')
.option('-p, --passphrase <passphrase>','Passphrase to be used to read the given certificate.')
.description('Uploads a file onto a Commerce Cloud instance')
.action(function(options) {
var instance = require('./lib/instance').getInstance(options.instance);
var target = ( options.target ? options.target : null );
if (!target) {
this.missingArgument('target');
return;
}
var file = ( options.file ? options.file : null );
if (!file) {
this.missingArgument('file');
return;
}
require('./lib/webdav').cli.upload(instance, '/' + target, file, true, {
pfx: options.certificate,
passphrase: options.passphrase
});
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' Uploads the file onto an instance into the target WebDAV folder.');
console.log(' Note, that there is a max file size of 100 MB for uploading files. You may');
console.log(' want to zip or gzip the file to upload.');
console.log();
console.log(' The file may include a path to the actual location where the file resides locally.');
console.log(' The provided --target <target> is relative to /webdav/Sites/, e.g. "impex/src/upload".');
console.log();
console.log(' Supported top level --target are "impex", "static", "catalogs", "libraries" and "dynamic".');
console.log(' In order to use "catalogs", "libraries" and "dynamic" you have to set API permissions for');
console.log(' a specific catalog, library or dynamic folder in WebDAV Client Permissions.');
console.log();
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci data:upload --instance my-instance.demandware.net --target impex/src/upload ' +
'--file data.xml');
console.log(' $ sfcc-ci data:upload --instance my-instance.demandware.net --target impex/src/instance ' +
'--file site-import.zip');
console.log();
});
program
.command('sandbox:realm:list')
.description('List realms eligible to manage sandboxes for')
.option('-r, --realm <realm>','Realm to get details for')
.option('--show-usage', 'Whether to return detailed usage data')
.option('-j, --json','Formats the output in json')
.action(function(options) {
var realm = ( options.realm ? options.realm : null );
var asJson = ( options.json ? options.json : false );
var topic = ( options.showUsage ? 'usage' : null );
require('./lib/sandbox').cli.realm.list(realm, topic, asJson);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' Use --realm <realm> to get details of a single realm such as configuration and usage');
console.log(' information about sandboxes. Use --usage to retrieve detailed usage information of');
console.log(' sandboxes in that realm.');
console.log();
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:realm:list');
console.log(' $ sfcc-ci sandbox:realm:list --json');
console.log(' $ sfcc-ci sandbox:realm:list --realm zzzz');
console.log(' $ sfcc-ci sandbox:realm:list --realm zzzz --json');
console.log(' $ sfcc-ci sandbox:realm:list --realm zzzz --show-usage');
console.log();
});
program
.command('sandbox:realm:update')
.description('Update realm settings')
.option('-r, --realm <realm>','Realm to update')
.option('-m, --max-sandbox-ttl <maxSandboxTTL>','Maximum number of hours a sandbox can live in the realm')
.option('-d, --default-sandbox-ttl <defaultSandboxTTL>','Number of hours a sandbox lives in the realm by default')
.option('-j, --json','Formats the output in json')
.action(function(options) {
var realm = ( options.realm ? options.realm : null );
if (!realm) {
this.missingArgument('realm');
return;
}
var maxSandboxTTL = ( options.maxSandboxTtl ? parseInt(options.maxSandboxTtl) : false );
var defaultSandboxTTL = ( options.defaultSandboxTtl ? parseInt(options.defaultSandboxTtl) : false );
var asJson = ( options.json ? options.json : false );
require('./lib/sandbox').cli.realm.update(realm, maxSandboxTTL, defaultSandboxTTL, asJson);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' Update details of a realm.');
console.log();
console.log(' Use --max-sandbox-ttl to update the maximum number of hours a sandbox can live');
console.log(' in the realm (must adhere to the maximum TTL quota). Use --default-sandbox-ttl to');
console.log(' update the number of hours a sandbox lives in the realm when no TTL was given upon');
console.log(' provisioning (must adhere to the maximum TTL quota).');
console.log();
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:realm:update --realm zzzz --max-sandbox-ttl 72');
console.log(' $ sfcc-ci sandbox:realm:update --realm zzzz --default-sandbox-ttl 24');
console.log();
});
program
.command('sandbox:list')
.description('List all available sandboxes')
.option('--show-deleted', 'Whether to include deleted sandboxes')
.option('-j, --json','Formats the output in json')
.option('-S, --sortby <sortby>', 'Sort by specifying any field')
.action(function(options) {
var showDeleted = ( options.showDeleted ? true : false );
var asJson = ( options.json ? options.json : false );
var sortby = ( options.sortby ? options.sortby : null );
require('./lib/sandbox').cli.list(showDeleted, asJson, sortby);
}).on('--help', function() {
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:list');
console.log(' $ sfcc-ci sandbox:list --show-deleted');
console.log(' $ sfcc-ci sandbox:list --json');
console.log();
});
program
.command('sandbox:ips')
.description('List inbound and outbound IP addresses for sandboxes')
.option('-j, --json','Formats the output in json')
.action(function(options) {
var asJson = ( options.json ? options.json : false );
require('./lib/sandbox').cli.ips(asJson);
}).on('--help', function() {
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:ips');
console.log(' $ sfcc-ci sandbox:ips --json');
console.log();
});
program
.command('sandbox:create')
.option('-r, --realm <realm>','Realm to create the sandbox for')
.option('-t, --ttl <hours>','Number of hours the sandbox will live')
.option('--auto-scheduled', 'Sets the sandbox as being auto scheduled')
.option('-p, --profile <profile>','Resource profile used for the sandbox, "medium" is the default')
.option('--ocapi-settings <json>','Additional OCAPI settings applied to the sandbox')
.option('--webdav-settings <json>','Additional WebDAV permissions applied to the sandbox')
.option('-j, --json','Formats the output in json')
.option('-s, --sync', 'Operates in synchronous mode and waits until the operation has been finished.')
.option('-d, --default', 'Sets the created sandbox as default instance.')
.option('-a, --set-alias <alias>','Instance alias to create for the sandbox')
.description('Create a new sandbox')
.action(function(options) {
var realm = ( options.realm ? options.realm : null );
var ttl = ( options.ttl ? parseInt(options.ttl) : null );
var autoScheduled = ( options.autoScheduled ? options.autoScheduled : false );
var profile = ( options.profile ? options.profile : null );
var asJson = ( options.json ? options.json : false );
var sync = ( options.sync ? options.sync : false );
var setAsDefault = ( options.default ? options.default : false );
var alias = ( options.setAlias ? options.setAlias : null );
var ocapiSettings = ( options.ocapiSettings ? options.ocapiSettings : null );
var webdavSettings = ( options.webdavSettings ? options.webdavSettings : null );
require('./lib/sandbox').cli.create(realm, alias, ttl, profile, autoScheduled, ocapiSettings, webdavSettings,
asJson, sync, setAsDefault);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' The sandbox will be created for the realm using the <realm> argument or stored in dw.json');
console.log(' config file. You must have permission to create a new sandbox for the realm. The number of');
console.log(' sandboxes allowed to create is limited. The command only trigger the creation and does not');
console.log(' wait until the sandbox is fully up and running. Use may use `sfcc-ci sandbox:list` to check');
console.log(' the status of the sandbox.');
console.log();
console.log(' The --auto-scheduled flag controls if the sandbox is being auto scheduled according to the');
console.log(' schedule configured at sandbox realm level. By default or if omitted the sandbox is not auto');
console.log(' scheduled.');
console.log();
console.log(' Use the optional --profile <profile> to set the resource allocation for the sandbox, "medium"');
console.log(' is the default. Be careful, more powerful profiles consume more credits. Supported values');
console.log(' are: medium, large, xlarge.');
console.log();
console.log(' You can force the command to wait until the creation of the sandbox has been finished and the');
console.log(' sandbox is available to use (in "started" status) by using the --sync flag. By default the');
console.log(' command will poll the status for 10 minutes. You can overwrite this by using the environment');
console.log(' variable SFCC_SANDBOX_API_POLLING_TIMEOUT to set another timeout in minutes.')
console.log();
console.log(' The created sandbox is being added to the list of instances with its host name. The optional');
console.log(' --set-alias <alias> is used as alias for the new instance. If it is omitted, the host is used');
console.log(' as alias.');
console.log();
console.log(' If executed with --default flag, the created sandbox will be set as new default instance.');
console.log();
console.log(' The TTL (time to live) in hours of the sandbox can be modified via the --ttl flag. The value');
console.log(' must adhere to the maximum TTL quotas) If absent the realms default sandbox TTL is used.');
console.log(' If the sandbox age reaches its TTL, it will be deleted automatically.');
console.log();
console.log(' Use --ocapi-settings and --webdav-settings to pass additional OCAPI and/or WebDAV settings to');
console.log(' the created sandbox as JSON. You may not overwrite the permissions for the CLI client but');
console.log(' amend its permissions or add permissions for other clients. The passed JSON must be valid.');
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:create');
console.log(' $ sfcc-ci sandbox:create --realm my-realm');
console.log(' $ sfcc-ci sandbox:create -r my-realm --set-alias an-alias');
console.log(' $ sfcc-ci sandbox:create -r my-realm -a an-alias -d');
console.log(' $ sfcc-ci sandbox:create -r my-realm -s');
console.log(' $ sfcc-ci sandbox:create -r my-realm -a an-alias -s');
console.log(' $ sfcc-ci sandbox:create -r my-realm -a an-alias -s -d');
console.log(' $ sfcc-ci sandbox:create -r my-realm -s -j');
console.log(' $ sfcc-ci sandbox:create -r my-realm --ttl 6');
console.log(' $ sfcc-ci sandbox:create -r my-realm --auto-scheduled');
console.log(' $ sfcc-ci sandbox:create -r my-realm -p large');
console.log();
});
program
.command('sandbox:get')
.description('Get detailed information about a sandbox')
.option('-s, --sandbox <id>','sandbox to get details for')
.option('-j, --json','Formats the output in json')
.option('-h, --host','Return the host name of the sandbox')
.option('-O, --open','Opens a browser with the Business Manager on the sandbox')
.option('--show-operations','Display operations performed')
.option('--show-usage','Display detailed usage information')
.option('--show-settings','Display settings applied')
.option('--show-storage','Display detailed storage information')
.action(function(options) {
var sandbox_id = ( options.sandbox ? options.sandbox : null );
if (!sandbox_id) {
this.missingArgument('sandbox');
return;
}
// always assume it is a sandbox id
var spec = { id : sandbox_id };
// check if we have to lookup the sandbox by realm and instance
var split = sandbox_id.split(/[-_]/);
if (split.length === 2) {
spec['realm'] = split[0];
spec['instance'] = split[1];
}
var asJson = ( options.json ? options.json : false );
var hostOnly = ( options.host ? options.host : false );
var openBrowser = ( options.open ? options.open : false );
var topic = null;
if ( options.showOperations ) {
topic = 'operations';
} else if ( options.showUsage ) {
topic = 'usage';
} else if ( options.showSettings ) {
topic = 'settings';
} else if ( options.showStorage ) {
topic = 'storage';
}
require('./lib/sandbox').cli.get(spec, asJson, hostOnly, openBrowser, topic);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' The sandbox to lookup must be identified by its id. Use may use `sfcc-ci sandbox:list` to');
console.log(' identify the id of your sandboxes.');
console.log();
console.log(' You can also pass the realm and the instance (e.g. zzzz-s01) as <id>.');
console.log();
console.log(' Use --show-usage to display detailed usage information, --show-operations to get a list of');
console.log(' previous operations executed on the sandbox, --show-settings to return the settings initially');
console.log(' applied to the sandbox during creation. Use --show-storage to retrieve detailed storage');
console.log(' capacity.');
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:get --sandbox my-sandbox-id');
console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id -j');
console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id -h');
console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id -O');
console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id --show-usage');
console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id --show-operations');
console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id --show-settings');
console.log(' $ sfcc-ci sandbox:get -s my-sandbox-id --show-storage');
console.log();
});
program
.command('sandbox:update')
.option('-s, --sandbox <id>','sandbox to update')
.option('-t, --ttl <hours>','number of hours to add to the sandbox lifetime')
.option('--auto-scheduled <flag>','Sets the sandbox as being auto scheduled')
.description('Update a sandbox')
.action(function(options) {
var sandbox_id = ( options.sandbox ? options.sandbox : null );
if (!sandbox_id) {
this.missingArgument('sandbox');
return;
}
// always assume it is a sandbox id
var spec = { id : sandbox_id };
// check if we have to lookup the sandbox by realm and instance
var split = sandbox_id.split(/[-_]/);
if (split.length === 2) {
spec['realm'] = split[0];
spec['instance'] = split[1];
}
var ttl = ( options.ttl ? parseInt(options.ttl) : null );
var autoScheduled = ( options.autoScheduled !== null ?
( options.autoScheduled === 'true' ? true : false ) : null );
require('./lib/sandbox').cli.update(spec, ttl, autoScheduled, false);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' The TTL (time to live) in hours of the sandbox can be prolonged via the --ttl flag. The value');
console.log(' must, together with previous prolongiations, adhere to the maximum TTL quotas). If set to 0 or');
console.log(' less the sandbox will have an infinite lifetime.');
console.log();
console.log(' The --auto-scheduled flag controls if the sandbox is being autoscheduled according to the');
console.log(' schedule configured at sandbox realm level.');
console.log();
console.log(' The sandbox to update must be identified by its id. Use may use `sfcc-ci sandbox:list` to');
console.log(' identify the id of your sandboxes.');
console.log();
console.log(' You can also pass the realm and the instance (e.g. zzzz-s01) as <id>.');
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:update --sandbox my-sandbox-id --ttl 8');
console.log(' $ sfcc-ci sandbox:update --sandbox my-sandbox-id --auto-scheduled true');
console.log(' $ sfcc-ci sandbox:update --sandbox my-sandbox-id --auto-scheduled false');
console.log();
});
program
.command('sandbox:start')
.option('-s, --sandbox <id>','sandbox to start')
.option('--sync','Operates in synchronous mode and waits until the operation has finished.')
.description('Start a sandbox')
.action(function(options) {
var sandbox_id = ( options.sandbox ? options.sandbox : null );
var sync = ( options.sync ? options.sync : false );
if (!sandbox_id) {
this.missingArgument('sandbox');
return;
}
// always assume it is a sandbox id
var spec = { id : sandbox_id };
// check if we have to lookup the sandbox by realm and instance
var split = sandbox_id.split(/[-_]/);
if (split.length === 2) {
spec['realm'] = split[0];
spec['instance'] = split[1];
}
require('./lib/sandbox').cli.start(spec, false, sync);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' The sandbox to start must be identified by its id. Use may use `sfcc-ci sandbox:list` to');
console.log(' identify the id of your sandboxes.');
console.log();
console.log(' You can also pass the realm and the instance (e.g. zzzz-s01) as <id>.');
console.log();
console.log(' Use the --sync flag to wait for the sandbox to have `started` status.');
console.log();
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:start --sandbox my-sandbox-id');
console.log(' $ sfcc-ci sandbox:start --sandbox my-sandbox-id --sync');
console.log();
});
program
.command('sandbox:stop')
.option('-s, --sandbox <id>','sandbox to stop')
.option('--sync','Operates in synchronous mode and waits until the operation has finished.')
.description('Stop a sandbox')
.action(function(options) {
var sandbox_id = ( options.sandbox ? options.sandbox : null );
var sync = ( options.sync ? options.sync : false );
if (!sandbox_id) {
this.missingArgument('sandbox');
return;
}
// always assume it is a sandbox id
var spec = { id : sandbox_id };
// check if we have to lookup the sandbox by realm and instance
var split = sandbox_id.split(/[-_]/);
if (split.length === 2) {
spec['realm'] = split[0];
spec['instance'] = split[1];
}
require('./lib/sandbox').cli.stop(spec, false, sync);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' The sandbox to stop must be identified by its id. Use may use `sfcc-ci sandbox:list` to');
console.log(' identify the id of your sandboxes.');
console.log();
console.log(' You can also pass the realm and the instance (e.g. zzzz-s01) as <id>.');
console.log();
console.log(' Use the --sync flag to wait for the sandbox to have `stopped` status.');
console.log();
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:stop --sandbox my-sandbox-id');
console.log(' $ sfcc-ci sandbox:stop --sandbox my-sandbox-id --sync');
console.log();
});
program
.command('sandbox:restart')
.option('-s, --sandbox <id>','sandbox to restart')
.description('Restart a sandbox')
.action(function(options) {
var sandbox_id = ( options.sandbox ? options.sandbox : null );
if (!sandbox_id) {
this.missingArgument('sandbox');
return;
}
// always assume it is a sandbox id
var spec = { id : sandbox_id };
// check if we have to lookup the sandbox by realm and instance
var split = sandbox_id.split(/[-_]/);
if (split.length === 2) {
spec['realm'] = split[0];
spec['instance'] = split[1];
}
require('./lib/sandbox').cli.restart(spec, false);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' The sandbox to restart must be identified by its id. Use may use `sfcc-ci sandbox:list` to');
console.log(' identify the id of your sandboxes.');
console.log();
console.log(' You can also pass the realm and the instance (e.g. zzzz-s01) as <id>.');
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:restart --sandbox my-sandbox-id');
console.log();
});
program
.command('sandbox:reset')
.option('-s, --sandbox <id>','sandbox to reset')
.option('-N, --noprompt','No prompt to confirm reset')
.description('Reset a sandbox')
.action(function(options) {
var sandbox_id = ( options.sandbox ? options.sandbox : null );
if (!sandbox_id) {
this.missingArgument('sandbox');
return;
}
// always assume it is a sandbox id
var spec = { id : sandbox_id };
// check if we have to lookup the sandbox by realm and instance
var split = sandbox_id.split(/[-_]/);
if (split.length === 2) {
spec['realm'] = split[0];
spec['instance'] = split[1];
}
var noPrompt = ( options.noprompt ? options.noprompt : false );
if ( noPrompt ) {
require('./lib/sandbox').cli.reset(spec, false);
} else {
prompt({
type : 'confirm',
name : 'ok',
default : false,
message : 'Reset sandbox ' + sandbox_id + '. Are you sure?'
}).then((answers) => {
if (answers['ok']) {
require('./lib/sandbox').cli.reset(spec, false);
}
});
}
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' WARNING: This is a destructive operation and you will loose any data stored on the sandbox.');
console.log();
console.log(' The sandbox to reset must be identified by its id. Use may use `sfcc-ci sandbox:list` to');
console.log(' identify the id of your sandboxes.');
console.log();
console.log(' You can also pass the realm and the instance (e.g. zzzz-s01) as <id>.');
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:reset --sandbox my-sandbox-id');
console.log(' $ sfcc-ci sandbox:reset --sandbox my-sandbox-id --noprompt');
console.log();
});
program
.command('sandbox:delete')
.option('-s, --sandbox <id>','sandbox to delete')
.option('-N, --noprompt','No prompt to confirm delete')
.description('Delete a sandbox')
.action(function(options) {
var sandbox_id = ( options.sandbox ? options.sandbox : null );
if (!sandbox_id) {
this.missingArgument('sandbox');
return;
}
// always assume it is a sandbox id
var spec = { id : sandbox_id };
// check if we have to lookup the sandbox by realm and instance
var split = sandbox_id.split(/[-_]/);
if (split.length === 2) {
spec['realm'] = split[0];
spec['instance'] = split[1];
}
var noPrompt = ( options.noprompt ? options.noprompt : false );
if ( noPrompt ) {
require('./lib/sandbox').cli.delete(spec);
} else {
prompt({
type : 'confirm',
name : 'ok',
default : false,
message : 'Delete sandbox ' + sandbox_id + '. Are you sure?'
}).then((answers) => {
if (answers['ok']) {
require('./lib/sandbox').cli.delete(spec);
}
});
}
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' WARNING: This is a destructive operation and you will loose any data stored on the sandbox.');
console.log();
console.log(' The sandbox to delete must be identified by its id. Use may use `sfcc-ci sandbox:list` to');
console.log(' identify the id of your sandboxes. You must have permission to delete a sandbox. The command');
console.log(' only triggers the deletion and does not wait until the sandbox is fully deleted. Use may use');
console.log(' `sfcc-ci sandbox:list` to check the status of the deletion.');
console.log();
console.log(' You can also pass the realm and the instance (e.g. zzzz-s01) as <id>.');
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:delete --sandbox my-sandbox-id');
console.log(' $ sfcc-ci sandbox:delete --sandbox my-sandbox-id --noprompt');
console.log();
});
program
.command('sandbox:alias:add')
.option('-s, --sandbox <id>','sandbox to create alias for')
.option('-h, --host <host>','hostname alias to register')
.option('-j, --json', 'Optional, formats the output in json')
.option('-u, --unique', 'Optional, define alias as unique, false by default')
.description('Registers a hostname alias for a sandbox.')
.action(function(options) {
var sandbox = options.sandbox;
if (!sandbox) {
this.missingArgument('sandbox');
return;
}
var spec = {};
// check if we have to lookup the sandbox by realm and instance
var split = sandbox.split(/[-_]/);
if (split.length === 2) {
spec['realm'] = split[0];
spec['instance'] = split[1];
} else {
// assume it is a sandbox id
spec = { id : sandbox };
}
var aliasName = options.host;
if (!aliasName) {
this.missingArgument('host');
return;
}
var asJson = ( options.json ? options.json : false );
var unique = ( options.unique ? options.unique : false );
require('./lib/sandbox').cli.alias.create(spec, aliasName, unique, asJson);
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' Registers a hostname alias for a sandbox. This will open a registration link in your browser');
console.log(' as soon as you have inserted the domain and a given target IP in your etc/hosts file. ');
console.log(' Note that you also have to include the hostname in your site alias configuration in Business');
console.log(' Manager to make the following redirect to your storefront working.');
console.log('');
console.log(' Use the --unique flag allows you to configure the alias to be unique across all aliases');
console.log(' registered. This requires that you have to proof ownership of the host on a DNS level.');
console.log(' The domain verification record value is generated and returned. By default the alias is not');
console.log(' unique.');
console.log('');
console.log(' Use --json to only print the created alias incl. either the registration link or the');
console.log(' the domain verification record.');
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:alias:add -s my-sandbox-id -h sbx1.merchant.com');
console.log(' $ sfcc-ci sandbox:alias:add -s my-sandbox-id -h sbx1.merchant.com -j');
console.log();
});
program
.command('sandbox:alias:list')
.option('-s, --sandbox <id>','sandbox to list hostname aliases for')
// can not use '--alias' here because of: https://github.com/tj/commander.js/issues/183
// and https://github.com/tj/commander.js/issues/592
.option('-a, --aliasid <aliasid>','Optional ID of the hostname alias to only get a single one')
.option('-j, --json', 'Optional, formats the output in json')
.description('Lists all hostname aliases, which are registered for the given sandbox.')
.action(function(options) {
var sandbox = options.sandbox;
if (!sandbox) {
this.missingArgument('sandbox');
return;
}
var spec = {};
// check if we have to lookup the sandbox by realm and instance
var split = sandbox.split(/[-_]/);
if (split.length === 2) {
spec['realm'] = split[0];
spec['instance'] = split[1];
} else {
// assume it is a sandbox id
spec = { id : sandbox };
}
var asJson = ( options.json ? options.json : false );
var aliasId = options.aliasid;
if (!aliasId) {
require('./lib/sandbox').cli.alias.list(spec, asJson);
} else {
require('./lib/sandbox').cli.alias.get(spec, aliasId, asJson);
}
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' Lists all hostname aliases for the given sandbox with their registration link or retrieves');
console.log(' a single one and call the registration link for it.');
console.log('');
console.log(' Use --json to only print the alias details incl. the registration link.');
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:alias:list -s my-sandbox-id');
console.log(' $ sfcc-ci sandbox:alias:list -s my-sandbox-id -a 83f05593-6272-...');
console.log(' $ sfcc-ci sandbox:alias:list -s my-sandbox-id --json');
console.log();
});
program
.command('sandbox:alias:delete')
.option('-s, --sandbox <id>','sandbox to delete the hostname alias for')
// can not use '--alias' here because of: https://github.com/tj/commander.js/issues/183
// and https://github.com/tj/commander.js/issues/592
.option('-a, --aliasid <aliasid>','ID of the hostname alias to delete')
.option('-N, --noprompt','No prompt to confirm delete')
.option('-j, --json', 'Optional, formats the output in json')
.description('Removes a sandbox alias by its ID')
.action(function(options) {
var sandbox = options.sandbox;
if (!sandbox) {
this.missingArgument('sandbox');
return;
}
var spec = {};
// check if we have to lookup the sandbox by realm and instance
var split = sandbox.split(/[-_]/);
if (split.length === 2) {
spec['realm'] = split[0];
spec['instance'] = split[1];
} else {
// assume it is a sandbox id
spec = { id : sandbox };
}
var aliasId = options.aliasid;
if (!aliasId) {
this.missingArgument('aliasid');
return;
}
var asJson = ( options.json ? options.json : false );
var noPrompt = ( options.noprompt ? options.noprompt : false );
if ( noPrompt ) {
require('./lib/sandbox').cli.alias.delete(spec, aliasId, asJson);
} else {
prompt({
type : 'confirm',
name : 'ok',
default : false,
message : 'Delete sandbox alias ' + aliasId + '. Are you sure?'
}).then((answers) => {
if (answers['ok']) {
require('./lib/sandbox').cli.alias.delete(spec, aliasId, false);
}
});
}
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' Deletes a hostname alias from the sandbox by its ID. Use `sfcc-ci sandbox:alias:list`');
console.log(' to get all registered sandbox aliases.');
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci sandbox:alias:delete -s my-sandbox-id -a 83f05593-6272-...');
console.log(' $ sfcc-ci sandbox:alias:delete -s my-sandbox-id -a 83f05593-6272-... --noprompt');
console.log();
});
program
.command('instance:add <instance> [alias]')
.option('-d, --default', 'Set the new instance as default')
.description('Adds a new Commerce Cloud instance to the list of configured instances')
.action(function(instance, alias, options) {
var asDefault = ( options.default ? options.default : false );
require('./lib/instance').add(instance, alias, asDefault);
}).on('--help', function() {
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci instance:add my-instance.demandware.net');
console.log(' $ sfcc-ci instance:add my-instance.demandware.net -d');
console.log(' $ sfcc-ci instance:add my-instance.demandware.net my-instance');
console.log(' $ sfcc-ci instance:add my-instance.demandware.net my-instance -d');
console.log();
});
program
.command('instance:set <alias_or_host>')
.description('Sets a Commerce Cloud instance as the default instance')
.action(function(alias_or_host) {
require('./lib/instance').config.setDefault(alias_or_host);
}).on('--help', function() {
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci instance:set my-instance');
console.log(' $ sfcc-ci instance:set my-instance.demandware.net');
console.log();
});
program
.command('instance:clear')
.description('Clears all configured Commerce Cloud instances')
.action(function() {
require('./lib/instance').clearAll();
}).on('--help', function() {
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci instance:clear');
console.log();
});
program
.command('instance:list')
.option('-j, --json', 'Formats the output in json')
.option('-v, --verbose', 'Outputs additional details of the current configuration')
.option('-S, --sortby <sortby>', 'Sort by specifying any field')
.description('List instance and client details currently configured')
.action(function(options) {
var verbose = ( options.verbose ? options.verbose : false );
var asJson = ( options.json ? options.json : false );
var sortby = ( options.sortby ? options.sortby : null );
require('./lib/instance').list(verbose, asJson, sortby);
}).on('--help', function() {
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci instance:list');
console.log(' $ sfcc-ci instance:list -v');
console.log(' $ sfcc-ci instance:list -j');
console.log(' $ sfcc-ci instance:list --sortby=alias');
console.log();
});
program
.command('instance:upload <archive>')
.option('-i, --instance [instance]','Instance to upload the import file to. Can be an ' +
'instance alias. If not specified the currently configured instance will be used.')
.option('-c, --certificate <certificate>','Path to the certificate to use for two factor authentication.')
.option('-p, --passphrase <passphrase>','Passphrase to be used to read the given certificate.')
.description('Uploads an instance import file onto a Commerce Cloud instance')
.action(function(archive, options) {
var instance = require('./lib/instance').getInstance(options.instance);
require('./lib/webdav').uploadInstanceImport(instance, archive, {
pfx: options.certificate,
passphrase: options.passphrase
});
}).on('--help', function() {
console.log('');
console.log(' Details:');
console.log();
console.log(' Uploads the passed site import archive file onto an instance. The archive must be a zip file');
console.log(' If the archive file does not have the file extension *.zip it will be appended.');
console.log();
console.log(' The archive may include a path to the actual archive file where the file resides locally.');
console.log();
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci instance:upload archive.zip');
console.log(' $ sfcc-ci instance:upload path/to/archive.zip');
console.log(' $ sfcc-ci instance:upload archive.zip -i my-instance-alias');
console.log(' $ sfcc-ci instance:upload archive.zip -i my-instance.demandware.net');
console.log(' $ sfcc-ci instance:upload archive.zip -i my-instance.demandware.net '
+ '-c path/to/my/certificate.p12 -p "myPassphraseForTheCertificate"');
console.log();
});
program
.command('instance:import <archive>')
.option('-i, --instance <instance>','Instance to run the import on. Can be an instance alias. ' +
'If not specified the currently configured instance will be used.')
.option('-j, --json', 'Formats the output in json')
.option('-s, --sync', 'Operates in synchronous mode and waits until the operation has been finished.')
.option('-f, --failfast', 'Forces the command (if ran with --sync mode) to result in an error if the job ' +
'on the instance exits with an error.')
.description('Perform a instance import (aka site import) on a Commerce Cloud instance')
.action(function(archive, options) {
var instance = require('./lib/instance').getInstance(options.instance);
var asJson = ( options.json ? options.json : false );
var sync = ( options.sync ? options.sync : false );
var failFast = ( options.failfast ? options.failfast : false );
if (sync) {
require('./lib/instance').importSync(instance, archive, asJson, failFast);
} else {
require('./lib/instance').import(instance, archive, asJson);
}
}).on('--help', function() {
console.log('');
console.log(' Examples:');
console.log();
console.log(' $ sfcc-ci instance:import archive.zip');
console.log(' $ sfcc-ci instance:import archive.zip -i my-instance-alias');
console.log(' $ sfcc-ci instance:import archive.zip -i my-instance-alias -s');
console.log(' $ sfcc-ci instance:import archive.zip -i my-instance.demandware.net');
console.log(' $ sfcc-ci instance:import archive.zip -i my-instance.demandware.net -s');
console.log(' $ sfcc-ci instance:import archive.zip -j');
console.log(' $ sfcc-ci instance:import archive.zip -s');
console.log(' $ sfcc-ci instance:import archive.zip -s -j');
console.log();
});
program
.command('instance:export')
.option('-i, --instance <instance>','Instance to run the export on. Can be an instance alias. ' +
'If not specified the currently configured instance will be used.')
.option('-j, --json', 'Formats the output in json')
.option('-d, --data <data>', 'Set of data as parameter or file specified in JSON format for what to export')
.option('-f, --file <file>', 'File to store exported data to, relative to impex/src/instance')
.option('-j, --json', 'Formats the output in json')