-
Notifications
You must be signed in to change notification settings - Fork 275
/
cli.go
1686 lines (1666 loc) · 74.3 KB
/
cli.go
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
// Copyright 2016 Yahoo Inc.
// Licensed under the terms of the Apache version 2.0 license. See LICENSE file for terms.
package zmscli
import (
"bytes"
"crypto/tls"
"crypto/x509"
"fmt"
"io/ioutil"
"net"
"net/http"
"strconv"
"strings"
"golang.org/x/net/proxy"
"github.com/ardielle/ardielle-go/rdl"
"github.com/yahoo/athenz/clients/go/zms"
)
type Zms struct {
ZmsUrl string
Identity string
Verbose bool
Bulkmode bool
Interactive bool
Zms zms.ZMSClient
Domain string
AuditRef string
UserDomain string
HomeDomain string
ProductIdSupport bool
Debug bool
}
func (cli *Zms) SetClient(tr *http.Transport, authHeader, ntoken *string) {
cli.Zms = zms.NewClient(cli.ZmsUrl, tr)
cli.Zms.AddCredentials(*authHeader, *ntoken)
}
func (cli Zms) interactiveSingleQuoteString(interactive bool, value string) string {
retValue := value
if !interactive {
retValue = "'" + value + "'"
}
return retValue
}
func (cli Zms) getInt32(str string) (int32, error) {
value, err := strconv.ParseInt(str, 10, 32)
if err != nil {
return -1, err
}
return int32(value), nil
}
func getTimestamp(str string) (rdl.Timestamp, error) {
value, err := rdl.TimestampParse(str)
return value, err
}
func (cli *Zms) EvalCommand(params []string) (*string, error) {
if len(params) >= 1 {
cmd := params[0]
args := params[1:]
argc := len(args)
dn := cli.Domain
//first do commands that do not require the domain to be set in the context
switch cmd {
case "list-domain", "list-domains", "domain", "domains":
if argc == 0 {
return cli.ListDomains(nil, "", "", nil)
} else if argc == 1 {
prefix := args[0]
return cli.ListDomains(nil, "", prefix, nil)
} else if argc == 4 {
var err error
var limit, depth int32
limit, err = cli.getInt32(args[0])
if err != nil {
return nil, err
}
skip := args[1]
prefix := args[2]
depth, err = cli.getInt32(args[3])
if err != nil {
return nil, err
}
return cli.ListDomains(&limit, skip, prefix, &depth)
}
return cli.helpCommand(params)
case "lookup-domain-by-role":
if argc == 2 {
return cli.LookupDomainByRole(args[0], args[1])
}
return cli.helpCommand(params)
case "lookup-domain-by-aws-account", "lookup-domain-by-account":
if argc == 1 {
return cli.LookupDomainById(args[0], nil)
}
return cli.helpCommand(params)
case "lookup-domain-by-product-id":
if argc == 1 {
productID, err := cli.getInt32(args[0])
if err != nil {
return nil, err
}
return cli.LookupDomainById("", &productID)
}
return cli.helpCommand(params)
case "use-domain":
var s string
if argc > 0 {
cli.Domain = args[0]
s = "[now working with the " + cli.Domain + " domain]"
} else {
cli.Domain = ""
s = "[not using any domain]"
}
return &s, nil
case "show-domain":
if argc == 1 {
//override the default domain, this command can show any of them
dn = args[0]
}
if dn != "" {
return cli.ShowDomain(dn)
}
return nil, fmt.Errorf("No domain specified")
case "check-domain":
if argc == 1 {
//override the default domain, this command can check any of them
dn = args[0]
}
if dn != "" {
return cli.CheckDomain(dn)
}
return nil, fmt.Errorf("No domain specified")
case "export-domain":
if argc == 1 || argc == 2 {
dn = args[0]
yamlfile := "-"
if argc == 2 {
yamlfile = args[1]
}
return cli.ExportDomain(dn, yamlfile)
}
return cli.helpCommand(params)
case "import-domain":
if argc >= 1 {
dn = args[0]
yamlfile := "-"
admins := args[0:0]
if argc >= 2 {
yamlfile = args[1]
admins = args[2:]
}
cli.Bulkmode = true
return cli.ImportDomain(dn, yamlfile, admins)
}
return cli.helpCommand(params)
case "update-domain":
if argc >= 1 {
dn = args[0]
yamlfile := "-"
if argc >= 2 {
yamlfile = args[1]
}
cli.Bulkmode = true
return cli.UpdateDomain(dn, yamlfile)
}
return cli.helpCommand(params)
case "system-backup":
if argc == 1 {
return cli.SystemBackup(args[0])
}
return cli.helpCommand(params)
case "add-domain":
if argc > 0 {
dn = args[0]
if cli.ProductIdSupport && strings.LastIndex(dn, ".") < 0 {
if argc < 2 {
return nil, fmt.Errorf("Top Level Domains require a number specified for the product id")
}
productID, err := cli.getInt32(args[1])
if err != nil {
return nil, fmt.Errorf("Top Level Domains require an integer number specified for the product id")
}
return cli.AddDomain(dn, &productID, args[2:])
}
return cli.AddDomain(dn, nil, args[1:])
}
return cli.helpCommand(params)
case "delete-domain":
if argc == 1 {
if args[0] == dn {
return nil, fmt.Errorf("Cannot delete domain while using it")
}
return cli.DeleteDomain(args[0])
}
return cli.helpCommand(params)
case "set-default-admins":
if argc >= 1 {
return cli.SetDefaultAdmins(args[0], args[1:])
}
case "get-signed-domains":
matchingTag := ""
if argc == 1 {
matchingTag = args[0]
}
return cli.GetSignedDomains("", matchingTag)
case "list-server-template", "list-server-templates":
return cli.ListServerTemplates()
case "list-domain-template", "list-domain-templates":
if argc == 1 {
//override the default domain, this command can show any of them
dn = args[0]
}
if dn != "" {
return cli.ListDomainTemplates(dn)
}
return nil, fmt.Errorf("No domain specified")
case "show-server-template":
if argc == 1 {
return cli.ShowServerTemplate(args[0])
}
case "show-resource":
if argc == 2 {
return cli.ShowResourceAccess(args[0], args[1])
}
case "list-user":
return cli.ListUsers()
case "delete-user":
if argc == 1 {
return cli.DeleteUser(args[0])
}
case "help":
return cli.helpCommand(args)
default:
//the rest all rely on the domain being defined
if dn == "" {
var err error
if cli.Interactive {
err = fmt.Errorf("No domain specified. Use use-domain command to set the domain")
} else {
err = fmt.Errorf("No domain specified. Use -d argument to specify the domain. Type 'zms-cli' to see help information")
}
return nil, err
}
//and fall through
}
switch cmd {
case "list-policy", "list-policies":
return cli.ListPolicies(dn)
case "show-policy":
if argc == 1 {
return cli.ShowPolicy(dn, args[0])
}
case "add-policy", "set-policy":
if argc >= 1 {
return cli.AddPolicy(dn, args[0], args[1:])
}
case "add-assertion":
if argc >= 1 {
return cli.AddAssertion(dn, args[0], args[1:])
}
case "delete-assertion":
if argc >= 1 {
return cli.DeleteAssertion(dn, args[0], args[1:])
}
case "delete-policy":
if argc == 1 {
return cli.DeletePolicy(dn, args[0])
}
case "show-access":
if argc >= 2 {
var trustDomain *string
var altPrincipal *string
if argc > 2 {
altPrincipal = &args[2]
if argc > 3 {
trustDomain = &args[3]
}
}
return cli.ShowAccess(dn, args[0], args[1], altPrincipal, trustDomain)
}
case "show-access-ext":
if argc >= 2 {
var trustDomain *string
var altPrincipal *string
if argc > 2 {
altPrincipal = &args[2]
if argc > 3 {
trustDomain = &args[3]
}
}
return cli.ShowAccessExt(dn, args[0], args[1], altPrincipal, trustDomain)
}
case "list-role", "list-roles":
return cli.ListRoles(dn)
case "show-role":
if argc == 1 {
return cli.ShowRole(dn, args[0], false, false)
} else if argc == 2 && args[1] == "log" {
return cli.ShowRole(dn, args[0], true, false)
} else if argc == 2 && args[1] == "expand" {
return cli.ShowRole(dn, args[0], false, true)
}
case "add-delegated-role", "add-trusted-role":
if argc == 2 {
return cli.AddDelegatedRole(dn, args[0], args[1])
}
case "add-group-role":
if argc >= 1 {
roleMembers := cli.convertRoleMembers(args[1:])
return cli.AddGroupRole(dn, args[0], roleMembers)
}
case "add-provider-role-member", "add-provider-role-members":
if argc >= 4 {
return cli.AddProviderRoleMembers(dn, args[0], args[1], args[2], args[3:])
}
case "show-provider-role-member", "show-provider-role-members":
if argc == 3 {
return cli.ShowProviderRoleMembers(dn, args[0], args[1], args[2])
}
case "delete-provider-role-member", "delete-provider-role-members":
if argc >= 4 {
return cli.DeleteProviderRoleMembers(dn, args[0], args[1], args[2], args[3:])
}
case "add-member", "add-members":
if argc >= 2 {
return cli.AddMembers(dn, args[0], args[1:])
}
case "add-temporary-member":
if argc == 3 {
value, err := getTimestamp(args[2])
if err == nil {
return cli.AddTemporaryMember(dn, args[0], args[1], value)
}
return nil, err
}
case "delete-member", "delete-members":
if argc >= 2 {
return cli.DeleteMembers(dn, args[0], args[1:])
}
case "check-member", "check-members", "show-member", "show-members":
if argc >= 2 {
return cli.CheckMembers(dn, args[0], args[1:])
}
case "delete-role":
if argc == 1 {
return cli.DeleteRole(dn, args[0])
}
case "list-service", "list-services":
if argc == 0 {
return cli.ListServices(dn)
}
case "show-service":
if argc == 1 {
return cli.ShowService(dn, args[0])
}
case "add-service":
if argc == 3 {
pubkey, err := cli.getPublicKey(args[2])
if err == nil {
return cli.AddService(dn, args[0], args[1], pubkey)
}
return nil, err
} else if argc == 1 {
return cli.AddService(dn, args[0], "", nil)
}
case "add-provider-service":
if argc == 3 {
pubkey, err := cli.getPublicKey(args[2])
if err == nil {
return cli.AddProviderService(dn, args[0], args[1], pubkey)
}
return nil, err
}
case "set-service-endpoint":
if argc == 2 {
return cli.SetServiceEndpoint(dn, args[0], args[1])
}
case "set-service-exe":
if argc == 4 {
return cli.SetServiceExe(dn, args[0], args[1], args[2], args[3])
}
case "add-service-host":
if argc >= 2 {
return cli.AddServiceHost(dn, args[0], args[1:])
}
case "delete-service-host":
if argc >= 2 {
return cli.DeleteServiceHost(dn, args[0], args[1:])
}
case "add-public-key":
if argc == 3 {
pubkey, err := cli.getPublicKey(args[2])
if err == nil {
return cli.AddServicePublicKey(dn, args[0], args[1], pubkey)
}
return nil, err
}
case "show-public-key":
if argc == 2 {
return cli.ShowServicePublicKey(dn, args[0], args[1])
}
case "delete-public-key":
if argc == 2 {
return cli.DeleteServicePublicKey(dn, args[0], args[1])
}
case "delete-service":
if argc == 1 {
return cli.DeleteService(dn, args[0])
}
case "list-entity", "list-entities":
if argc == 0 {
return cli.ListEntities(dn)
}
case "add-entity":
if argc > 1 {
return cli.AddEntity(dn, args[0], args[1:])
}
case "delete-entity":
if argc == 1 {
return cli.DeleteEntity(dn, args[0])
}
case "show-entity":
if argc == 1 {
return cli.ShowEntity(dn, args[0])
}
case "add-tenancy":
if argc == 1 {
return cli.AddTenancy(dn, args[0])
}
case "delete-tenancy":
if argc == 1 {
return cli.DeleteTenancy(dn, args[0])
}
case "show-tenant-resource-group-roles":
if argc == 3 {
return cli.ShowTenantResourceGroupRoles(dn, args[0], args[1], args[2])
}
case "add-tenant-resource-group-roles":
if argc > 3 {
return cli.AddTenantResourceGroupRoles(dn, args[0], args[1], args[2], args[3:])
}
case "delete-tenant-resource-group-roles":
if argc == 3 {
return cli.DeleteTenantResourceGroupRoles(dn, args[0], args[1], args[2])
}
case "show-provider-resource-group-roles":
if argc == 3 {
return cli.ShowProviderResourceGroupRoles(dn, args[0], args[1], args[2])
}
case "add-provider-resource-group-roles":
if argc > 3 {
return cli.AddProviderResourceGroupRoles(dn, args[0], args[1], args[2], args[3:])
}
case "delete-provider-resource-group-roles":
if argc == 3 {
return cli.DeleteProviderResourceGroupRoles(dn, args[0], args[1], args[2])
}
case "set-domain-meta":
if argc == 3 {
descr := args[0]
org := args[1]
auditEnabled, err := strconv.ParseBool(args[2])
if err != nil {
return nil, err
}
return cli.SetDomainMeta(dn, descr, org, auditEnabled)
}
case "set-aws-account", "set-domain-account":
if argc == 1 {
return cli.SetDomainAccount(dn, args[0])
}
case "set-product-id", "set-domain-product-id":
if argc == 1 {
productID, err := cli.getInt32(args[0])
if err != nil {
return nil, err
}
return cli.SetDomainProductId(dn, productID)
}
case "set-application-id":
if argc == 1 {
return cli.SetDomainApplicationId(dn, args[0])
}
case "set-domain-template":
if argc >= 1 {
return cli.SetDomainTemplate(dn, args[0:])
}
case "delete-domain-template":
if argc == 1 {
return cli.DeleteDomainTemplate(dn, args[0])
}
case "get-quota":
if argc == 0 {
return cli.GetQuota(dn)
}
case "set-quota":
if argc >= 1 {
return cli.SetQuota(dn, args[0:])
}
case "delete-quota":
if argc == 0 {
return cli.DeleteQuota(dn)
}
default:
return nil, fmt.Errorf("Unrecognized command '%v'. Type 'zms-cli help' to see help information", cmd)
}
return nil, fmt.Errorf("Bad command syntax. Type 'zms-cli help' to see help information")
}
return cli.helpCommand(params)
}
func (cli Zms) helpCommand(params []string) (*string, error) {
s := ""
if len(params) == 1 {
s = cli.HelpSpecificCommand(cli.Interactive, params[0])
} else {
s = cli.HelpListCommand()
}
return &s, nil
}
// HelpSpecificCommand returns the help string for the given command.
func (cli Zms) HelpSpecificCommand(interactive bool, cmd string) string {
var buf bytes.Buffer
// we are going to display the required domain argument
// only in non-interactive mode
domain_param := "-d domain"
domain_example := "-d coretech"
tenant_example := "-d sports"
if interactive {
domain_param = ""
domain_example = "coretech> "
tenant_example = "sports> "
}
switch cmd {
case "list-domain":
buf.WriteString(" syntax:\n")
buf.WriteString(" list-domain [prefix]\n")
buf.WriteString(" list-domain [limit skip prefix depth]\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" prefix : return domains starting with this value \n")
buf.WriteString(" limit : return specified number of domains only\n")
buf.WriteString(" skip : exclude all the domains including the specified one from the return set\n")
buf.WriteString(" depth : maximum depth of the domains returned (0 - top level domains only)\n")
buf.WriteString(" examples:\n")
buf.WriteString(" list-domain cd\n")
buf.WriteString(" return all domains who names start with cd\n")
case "show-domain":
buf.WriteString(" syntax:\n")
buf.WriteString(" show-domain domain\n")
buf.WriteString(" " + domain_param + " show-domain\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : retrieve roles, policies and services for this domain\n")
buf.WriteString(" : this argument is required unless -d <domain> is specified or\n")
buf.WriteString(" : running in repl/interactive mode with use-domain specified\n")
buf.WriteString(" examples:\n")
buf.WriteString(" show-domain coretech.hosted\n")
buf.WriteString(" " + domain_example + " show-domain\n")
case "lookup-domain-by-account", "lookup-domain-by-aws-account":
buf.WriteString(" syntax:\n")
buf.WriteString(" lookup-domain-by-aws-account account-id\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" account-id : lookup domain with specified account id\n")
buf.WriteString(" examples:\n")
buf.WriteString(" lookup-domain-by-aws-account 1234567890\n")
case "lookup-domain-by-product-id":
buf.WriteString(" syntax:\n")
buf.WriteString(" lookup-domain-by-product-id product-id\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" product-id : lookup domain with specified product id\n")
buf.WriteString(" examples:\n")
buf.WriteString(" lookup-domain-by-product-id 10001\n")
case "lookup-domain-by-role":
buf.WriteString(" syntax:\n")
buf.WriteString(" lookup-domain-by-role role-member role-name\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" role-member : name of the principal\n")
buf.WriteString(" role-name : name of the role where the principal is a member of\n")
buf.WriteString(" examples:\n")
buf.WriteString(" lookup-domain-by-role " + cli.UserDomain + ".joe admin\n")
case "check-domain":
buf.WriteString(" syntax:\n")
buf.WriteString(" check-domain domain\n")
buf.WriteString(" " + domain_param + " check-domain\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : verify domain resources and report any issues\n")
buf.WriteString(" : this argument is required unless -d <domain> is specified or\n")
buf.WriteString(" : running in repl/interactive mode with use-domain specified\n")
buf.WriteString(" examples:\n")
buf.WriteString(" check-domain coretech.hosted\n")
buf.WriteString(" " + domain_example + " check-domain\n")
case "use-domain":
buf.WriteString(" syntax:\n")
buf.WriteString(" use-domain [domain]\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : when running in repl mode sets the domain value for all operations\n")
buf.WriteString(" : passing \"\" domain will reset the client's saved domain value\n")
buf.WriteString(" examples:\n")
buf.WriteString(" use-domain coretech\n")
case "add-domain":
buf.WriteString(" syntax:\n")
buf.WriteString(" add-domain domain [product-id] [admin ...]\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : name of the domain to be added\n")
buf.WriteString(" : The name can be either a top level domain or a subdomain\n")
buf.WriteString(" product-id : unique product id number required when creating top level domains\n")
buf.WriteString(" admin : list of domain administrators separated by a space\n")
buf.WriteString(" : the user creating the domain will be added as an administrator\n")
buf.WriteString(" examples:\n")
buf.WriteString(" add-domain coretech john jane\n")
buf.WriteString(" add a top level domain called coretech with " + cli.UserDomain + ".john, " + cli.UserDomain + ".jane and the caller as administrators\n")
buf.WriteString(" add-domain coretech.hosted john jane\n")
buf.WriteString(" add a subdomain hosted in domain coretech with " + cli.UserDomain + ".john, " + cli.UserDomain + ".jane and the caller as administrators\n")
case "set-domain-meta":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " set-domain-meta description org audit_enabled\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain being updated\n")
}
buf.WriteString(" description : set the description for the domain\n")
buf.WriteString(" org : set the organization of the domain\n")
buf.WriteString(" audit_enabled : boolean flag indicating if the domain must comply with SOX auditing requirements\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " set-domain-meta \"Coretech Hosted\" cloud.services false\n")
case "set-aws-account", "set-domain-account":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " set-aws-account account-id\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain being updated\n")
}
buf.WriteString(" account-id : set the aws account id for the domain\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " set-aws-account \"134901934383\"\n")
case "set-product-id", "set-domain-product-id":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " set-product-id product-id\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain being updated\n")
}
buf.WriteString(" product-id : set the Product ID for the domain\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " set-product-id 10001\n")
case "set-application-id":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " set-application-id application-id\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain being updated\n")
}
buf.WriteString(" application-id : set the Application ID for the domain\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " set-application-id 0oabg8pelxhjh0tcs0h7\n")
case "import-domain":
buf.WriteString(" syntax:\n")
buf.WriteString(" import-domain domain [file.yaml [admin ...]] - no file means stdin\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : name of the domain being imported\n")
buf.WriteString(" file.yaml : file that contains domain contents in yaml format\n")
buf.WriteString(" admin : additional list of administrators to be added to the domain\n")
buf.WriteString(" examples:\n")
buf.WriteString(" import-domain coretech coretech.yaml " + cli.UserDomain + ".john\n")
case "update-domain":
buf.WriteString(" syntax:\n")
buf.WriteString(" update-domain domain [file.yaml] - no file means stdin\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : name of the domain being updated\n")
buf.WriteString(" file.yaml : file that contains domain contents in yaml format\n")
buf.WriteString(" examples:\n")
buf.WriteString(" update-domain coretech coretech.yaml\n")
case "export-domain":
buf.WriteString(" syntax:\n")
buf.WriteString(" export-domain domain [file.yaml] - no file means stdout\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : name of the domain to be exported\n")
buf.WriteString(" file.yaml : filename where the domain data is stored\n")
buf.WriteString(" examples:\n")
buf.WriteString(" export-domain coretech /tmp/coretech.yaml\n")
case "delete-domain":
buf.WriteString(" syntax:\n")
buf.WriteString(" delete-domain domain\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : name of the domain to be deleted\n")
buf.WriteString(" examples:\n")
buf.WriteString(" delete-domain coretech\n")
case "set-default-admins":
buf.WriteString(" syntax:\n")
buf.WriteString(" set-default-admins domain admin [admin ...]\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : name of the domain to restore admin access\n")
buf.WriteString(" admin : list of administrators to be set for domain\n")
buf.WriteString(" examples:\n")
buf.WriteString(" set-default-admins coretech.hosted " + cli.UserDomain + ".john " + cli.UserDomain + ".jane\n")
case "get-signed-domains":
buf.WriteString(" syntax:\n")
buf.WriteString(" get-signed-domains [matching_tag]\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" matching-tag : value of ETag header retrieved from previous get-signed-domain call\n")
buf.WriteString(" : server will return changes since this timestamp only\n")
buf.WriteString(" examples:\n")
buf.WriteString(" get-signed-domains\n")
buf.WriteString(" get-signed-domains \"2015-04-10T20:43:34.023Z-gzip\"\n")
case "list-policy":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " list-policy\n")
if !interactive {
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : name of the domain to retrieve the list of policies from\n")
}
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " list-policy\n")
case "show-policy":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " show-policy policy\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that policy belongs to\n")
}
buf.WriteString(" policy : name of the policy to be displayed\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " show-policy admin\n")
case "add-policy", "set-policy":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " add-policy policy [assertion]\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain to add policy to\n")
}
buf.WriteString(" policy : name of the policy\n")
buf.WriteString(" assertion : <effect> <action> to <role> on <resource>\n")
buf.WriteString(" : effect - grant or deny\n")
buf.WriteString(" : action - domain admin defined action available for the resource (e.g. read, write, delete)\n")
buf.WriteString(" : role - which role this assertion applies to\n")
buf.WriteString(" : client will prepend 'domain:role.' to role name if not specified\n")
buf.WriteString(" : resource - which resource this assertion applies to\n")
buf.WriteString(" : client will prepend 'domain:' to resource if not specified\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " add-policy writers_policy grant write to writers_role on articles.sports\n")
buf.WriteString(" " + domain_example + " add-policy readers_policy grant read to readers_role on " + cli.interactiveSingleQuoteString(interactive, "articles.*") + "\n")
case "add-assertion":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " add-assertion policy assertion\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that policy belongs to\n")
}
buf.WriteString(" policy : name of the policy to add this assertion to\n")
buf.WriteString(" assertion : <effect> <action> to <role> on <resource>\n")
buf.WriteString(" : effect - grant or deny\n")
buf.WriteString(" : action - domain admin defined action available for the resource (e.g. read, write, delete)\n")
buf.WriteString(" : role - which role this assertion applies to\n")
buf.WriteString(" : client will prepend 'domain:role.' to role name if not specified\n")
buf.WriteString(" : resource - which resource this assertion applies to\n")
buf.WriteString(" : client will prepend 'domain:' to resource if not specified\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " add-assertion writers_policy grant write to writers_role on articles.sports\n")
buf.WriteString(" " + domain_example + " add-assertion readers_policy grant read to readers_role on " + cli.interactiveSingleQuoteString(interactive, "articles.*") + "\n")
case "delete-assertion":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " delete-assertion policy assertion\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that policy belongs to\n")
}
buf.WriteString(" policy : name of the policy to delete this assertion from\n")
buf.WriteString(" assertion : existing assertion in the policy in the '<effect> <action> to <role> on <resource>' format\n")
buf.WriteString(" : the value must be exactly what's displayed when executing the show-policy command\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " delete-assertion writers_policy grant write to writers_role on articles.sports\n")
buf.WriteString(" " + domain_example + " delete-assertion readers_policy grant read to readers_role on " + cli.interactiveSingleQuoteString(interactive, "articles.*") + "\n")
case "delete-policy":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " delete-policy policy\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that policy belongs to\n")
}
buf.WriteString(" policy : name of the policy to be deleted\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " delete-policy readers\n")
case "show-access":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " show-access action resource [alt_identity [trust_domain]]\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that resource belongs to\n")
}
buf.WriteString(" action : access check action value\n")
buf.WriteString(" resource : access check resource (resource name)\n")
buf.WriteString(" : client will prepend 'domain:' to resource if not specified\n")
buf.WriteString(" alt_identity : run the access check for this identity instead of the caller\n")
buf.WriteString(" trust_domain : when checking for cross-domain trust relationship\n")
buf.WriteString(" : only check this trusted domain\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " show-access node_sudo node.host1\n")
buf.WriteString(" " + domain_example + " show-access node_sudo coretech:node.host1\n")
buf.WriteString(" " + domain_example + " show-access node_sudo coretech:node.host1 " + cli.UserDomain + ".john\n")
case "show-access-ext":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " show-access-ext action resource [alt_identity [trust_domain]]\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that resource belongs to\n")
}
buf.WriteString(" action : access check action value\n")
buf.WriteString(" resource : access check resource (resource name)\n")
buf.WriteString(" : client will prepend 'domain:' to resource if not specified\n")
buf.WriteString(" alt_identity : run the access check for this identity instead of the caller\n")
buf.WriteString(" trust_domain : when checking for cross-domain trust relationship\n")
buf.WriteString(" : only check this trusted domain\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " show-access-ext node_sudo node.host1\n")
buf.WriteString(" " + domain_example + " show-access-ext node_sudo coretech:node.host1\n")
buf.WriteString(" " + domain_example + " show-access-ext node_sudo coretech:node.host1 " + cli.UserDomain + ".john\n")
case "show-resource":
buf.WriteString(" syntax:\n")
buf.WriteString(" show-resource principal action\n")
buf.WriteString(" parameters:\n")
buf.WriteString(" principal : show resources for this principal only\n")
buf.WriteString(" action : assertion action value to filter on\n")
buf.WriteString(" examples:\n")
buf.WriteString(" show-resource " + cli.UserDomain + ".user1 update\n")
buf.WriteString(" show-resource " + cli.UserDomain + ".user1 \"\"\n")
buf.WriteString(" show-resource \"\" assume_aws_role\n")
case "list-role":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " list-role\n")
if !interactive {
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : name of the domain to retrieve the list of roles from\n")
}
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " list-role\n")
case "show-role":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " show-role role [log | expand]\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" role : name of the role to be displayed\n")
buf.WriteString(" log : option argument to specify to display audit logs for role\n")
buf.WriteString(" expand : option argument to specify to display delegated members\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " show-role admin\n")
buf.WriteString(" " + domain_example + " show-role admin log\n")
buf.WriteString(" " + domain_example + " show-role delegated-role expand\n")
case "add-delegated-role":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " add-delegated-role role trusted_domain\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" role : name of the cross-domain/trust delegated role\n")
buf.WriteString(" trust_domain : name of the cross/trusted domain name\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " add-delegated-role tenant.sports.readers sports\n")
case "add-group-role":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " add-group-role role member [member ... ]\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" role : name of the standard group role\n")
buf.WriteString(" member : list of group members that could be either users or services\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " add-group-role readers " + cli.UserDomain + ".john " + cli.UserDomain + ".joe media.sports.storage\n")
case "add-member":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " add-member group_role user_or_service [user_or_service ...]\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" group-role : name of the standard group role to add members to\n")
buf.WriteString(" user_or_service : users or services to be added as members\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " add-member readers " + cli.UserDomain + ".john " + cli.UserDomain + ".joe media.sports.storage\n")
case "add-temporary-member":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " add-temporary-member group_role user_or_service expiration\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" group-role : name of the standard group role to add a temporary member to\n")
buf.WriteString(" user_or_service : user or service to be added as member\n")
buf.WriteString(" expiration : expiration date format yyyy-mm-ddThh:mm:ss.msecZ\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " add-temporary-member readers " + cli.UserDomain + ",john 2017-03-02T15:04:05.999Z\n")
case "check-member":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " check-member group_role user_or_service [user_or_service ...]\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" group-role : name of the standard group role to check membership\n")
buf.WriteString(" user_or_service : users or services to be checked if they are members\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " check-member readers " + cli.UserDomain + ".john " + cli.UserDomain + ".joe media.sports.storage\n")
case "delete-member":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " delete-member group_role user_or_service [user_or_service ...]\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" group-role : name of the standard group role to remove members from\n")
buf.WriteString(" user_or_service : users or services to be removed as members\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " delete-member readers " + cli.UserDomain + ".john " + cli.UserDomain + ".joe media.sports.storage\n")
case "add-provider-role-member":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " add-provider-role-member provider_service resource_group provider_role user_or_service [user_or_service ...]\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" provider_service : name of the provider service\n")
buf.WriteString(" resource_group : name of the resource group\n")
buf.WriteString(" provider_role : the provider role name\n")
buf.WriteString(" user_or_service : users or services to be added as members\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " add-provider-role-member storage.db stats_db access media.sports.storage\n")
case "show-provider-role-member":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " show-provider-role-member provider_service resource_group provider_role\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" provider_service : name of the provider service\n")
buf.WriteString(" resource_group : name of the resource group\n")
buf.WriteString(" provider_role : the provider role name\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " show-provider-role-member storage.db stats_db access\n")
case "delete-provider-role-member":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " delete-provider-role-member provider_service resource_group provider_role user_or_service [user_or_service ...]\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" provider_service : name of the provider service\n")
buf.WriteString(" resource_group : name of the resource group\n")
buf.WriteString(" provider_role : the provider role name\n")
buf.WriteString(" user_or_service : users or services to be removed as members\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " delete-provider-role-member storage.db stats_db access media.sports.storage\n")
case "delete-role":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " delete-role role\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that role belongs to\n")
}
buf.WriteString(" role : name of the role to be deleted\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " delete-role readers\n")
case "list-service":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " list-service\n")
if !interactive {
buf.WriteString(" parameters:\n")
buf.WriteString(" domain : name of the domain to retrieve the list of services from\n")
}
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " list-service\n")
case "show-service":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " show-service service\n")
buf.WriteString(" parameters:\n")
if !interactive {
buf.WriteString(" domain : name of the domain that service belongs to\n")
}
buf.WriteString(" service : name of the service to be displayed\n")
buf.WriteString(" examples:\n")
buf.WriteString(" " + domain_example + " show-service storage\n")
case "add-service":
buf.WriteString(" syntax:\n")
buf.WriteString(" " + domain_param + " add-service service key_id identity_pubkey.pem|identity_key_ybase64\n")
buf.WriteString(" parameters:\n")
if !interactive {