forked from viamrobotics/rdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
2812 lines (2762 loc) · 101 KB
/
app.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
package cli
import (
"errors"
"fmt"
"io"
"reflect"
"regexp"
"strings"
"github.com/urfave/cli/v2"
)
// CLI flags.
const (
baseURLFlag = "base-url"
configFlag = "config"
debugFlag = "debug"
profileFlag = "profile"
disableProfilesFlag = "disable-profiles"
profileFlagName = "profile-name"
// TODO: RSDK-6683.
quietFlag = "quiet"
logsFlagFormat = "format"
logsFlagOutputFile = "output"
logsFlagKeyword = "keyword"
logsFlagLevels = "levels"
logsFlagErrors = "errors"
logsFlagTail = "tail"
runFlagData = "data"
runFlagStream = "stream"
loginFlagDisableBrowser = "disable-browser-open"
loginFlagKeyID = "key-id"
loginFlagKey = "key"
// Flags shared by logs, api-key, module, ml-training, package, and data subcommands.
generalFlagOrganization = "organization"
generalFlagAliasOrg = "org"
generalFlagAliasOrgName = "org-name"
generalFlagOrgID = "org-id"
generalFlagLocation = "location"
generalFlagAliasLocationName = "location-name"
generalFlagLocationID = "location-id"
generalFlagMachine = "machine"
generalFlagMachineName = "machine-name"
generalFlagMachineID = "machine-id"
generalFlagAliasRobot = "robot"
generalFlagAliasRobotID = "robot-id"
generalFlagPart = "part"
generalFlagPartName = "part-name"
generalFlagPartID = "part-id"
generalFlagName = "name"
generalFlagMethod = "method"
generalFlagDestination = "destination"
generalFlagVersion = "version"
generalFlagCount = "count"
generalFlagPath = "path"
generalFlagType = "type"
generalFlagResourceSubtype = "resource-subtype"
generalFlagTags = "tags"
generalFlagStart = "start"
generalFlagEnd = "end"
moduleFlagLanguage = "language"
moduleFlagPublicNamespace = "public-namespace"
moduleFlagPath = "module"
moduleFlagPlatform = "platform"
moduleFlagForce = "force"
moduleFlagBinary = "binary"
moduleFlagLocal = "local"
moduleFlagHomeDir = "home"
moduleCreateLocalOnly = "local-only"
moduleFlagID = "id"
moduleFlagIsPublic = "public"
moduleFlagResourceType = "resource-type"
moduleFlagModelName = "model-name"
moduleFlagEnableCloud = "enable-cloud"
moduleFlagRegister = "register"
moduleFlagDryRun = "dry-run"
moduleFlagUpload = "upload"
moduleBuildFlagRef = "ref"
moduleBuildFlagWait = "wait"
moduleBuildFlagToken = "token"
moduleBuildFlagWorkdir = "workdir"
moduleBuildFlagPlatforms = "platforms"
moduleBuildFlagGroupLogs = "group-logs"
moduleBuildRestartOnly = "restart-only"
moduleBuildFlagNoBuild = "no-build"
moduleBuildFlagOAuthLink = "oauth-link"
moduleBuildFlagRepo = "repo"
mlTrainingFlagName = "script-name"
mlTrainingFlagFramework = "framework"
mlTrainingFlagDraft = "draft"
mlTrainingFlagVisibility = "visibility"
mlTrainingFlagDescription = "description"
mlTrainingFlagURL = "url"
mlTrainingFlagArgs = "args"
dataFlagDataType = "data-type"
dataFlagOrgIDs = "org-ids"
dataFlagLocationIDs = "location-ids"
dataFlagAliasRobotName = "robot-name"
dataFlagComponentType = "component-type"
dataFlagComponentName = "component-name"
dataFlagResourceName = "resource-name"
dataFlagMimeTypes = "mime-types"
dataFlagParallelDownloads = "parallel"
dataFlagBboxLabels = "bbox-labels"
dataFlagDeleteTabularDataOlderThanDays = "delete-older-than-days"
dataFlagDatabasePassword = "password"
dataFlagFilterTags = "filter-tags"
dataFlagTimeout = "timeout"
packageFlagFramework = "model-framework"
oauthAppFlagClientID = "client-id"
oauthAppFlagClientName = "client-name"
oauthAppFlagClientAuthentication = "client-authentication"
oauthAppFlagPKCE = "pkce"
oauthAppFlagEnabledGrants = "enabled-grants"
oauthAppFlagURLValidation = "url-validation"
oauthAppFlagOriginURIs = "origin-uris"
oauthAppFlagRedirectURIs = "redirect-uris"
oauthAppFlagLogoutURI = "logout-uri"
unspecified = "unspecified"
cpFlagRecursive = "recursive"
cpFlagPreserve = "preserve"
tunnelFlagLocalPort = "local-port"
tunnelFlagDestinationPort = "destination-port"
organizationFlagSupportEmail = "support-email"
organizationBillingAddress = "address"
organizationFlagLogoPath = "logo-path"
)
// matches all uppercase characters that follow lowercase chars and aren't at the [0] index of a string.
// This is useful for converting camel case into kabob case when getting values out of a CLI Context
// based on a flag name, and putting them into a struct with a camel cased field name.
var matchAllCap = regexp.MustCompile("([a-z0-9])([A-Z])")
var commonFilterFlags = []cli.Flag{
&cli.StringSliceFlag{
Name: dataFlagOrgIDs,
Usage: "orgs filter",
},
&cli.StringSliceFlag{
Name: dataFlagLocationIDs,
Usage: "locations filter",
},
&AliasStringFlag{
cli.StringFlag{
Name: generalFlagMachineID,
Aliases: []string{generalFlagAliasRobotID},
Usage: "machine id filter",
},
},
&cli.StringFlag{
Name: generalFlagPartID,
Usage: "part id filter",
},
&AliasStringFlag{
cli.StringFlag{
Name: generalFlagMachineName,
Aliases: []string{dataFlagAliasRobotName},
Usage: "machine name filter",
},
},
&cli.StringFlag{
Name: generalFlagPartName,
Usage: "part name filter",
},
&cli.StringFlag{
Name: dataFlagComponentType,
Usage: "component type filter",
},
&cli.StringFlag{
Name: dataFlagComponentName,
Usage: "component name filter",
},
&cli.StringFlag{
Name: generalFlagMethod,
Usage: "method filter",
},
&cli.StringSliceFlag{
Name: dataFlagMimeTypes,
Usage: "mime types filter",
},
&cli.StringFlag{
Name: generalFlagStart,
Usage: "ISO-8601 timestamp in RFC3339 format indicating the start of the interval filter",
},
&cli.StringFlag{
Name: generalFlagEnd,
Usage: "ISO-8601 timestamp in RFC3339 format indicating the end of the interval filter",
},
&cli.StringSliceFlag{
Name: dataFlagBboxLabels,
Usage: "bbox labels filter. accepts string labels corresponding to bounding boxes within images",
},
}
var dataTagByIDsFlags = []cli.Flag{
&cli.StringSliceFlag{
Name: generalFlagTags,
Usage: "comma separated tags to add/remove to the data",
Required: true,
},
&cli.StringFlag{
Name: generalFlagOrgID,
Usage: "org ID to which data belongs",
Required: true,
},
&cli.StringFlag{
Name: dataFlagLocationID,
Usage: "location ID to which data belongs",
Required: true,
},
&cli.StringSliceFlag{
Name: dataFlagFileIDs,
Usage: "comma separated file IDs of data belonging to specified org and location",
Required: true,
},
}
var dataTagByFilterFlags = append([]cli.Flag{
&cli.StringSliceFlag{
Name: generalFlagTags,
Required: true,
Usage: "comma separated tags to add/remove to the data",
},
&cli.StringSliceFlag{
Name: dataFlagFilterTags,
Usage: "tags filter. " +
"accepts tagged for all tagged data, untagged for all untagged data, or a list of tags for all data matching any of the tags",
},
},
commonFilterFlags...)
type emptyArgs struct{}
type globalArgs struct {
BaseURL string
Config string
Debug bool
Quiet bool
Profile string
DisableProfiles bool
}
func getValFromContext(name string, ctx *cli.Context) any {
// some fuzzy searching is required here, because flags are typically in kebab case, but
// params are typically in snake or camel case
replacer := strings.NewReplacer("_", "-")
dashFormattedName := replacer.Replace(strings.ToLower(name))
value := ctx.Value(dashFormattedName)
if value != nil {
return value
}
camelFormattedName := matchAllCap.ReplaceAllString(name, "${1}-${2}")
camelFormattedName = strings.ToLower(camelFormattedName)
return ctx.Value(camelFormattedName)
}
// (erodkin) We don't support pointers in structs here. The problem is that when getting a value
// from a context for a supported flag, the context will default to populating with the zero value.
// When getting a value from the context, though, we currently have no way of know if that's going
// to a concrete value, going to a pointer and should be a nil value, or going to a pointer but should
// be a pointer to that default value.
func parseStructFromCtx[T any](ctx *cli.Context) T {
var t T
var s cli.StringSlice
s.Value()
tValue := reflect.ValueOf(&t).Elem()
tType := tValue.Type()
for i := 0; i < tType.NumField(); i++ {
field := tType.Field(i)
if value := getValFromContext(field.Name, ctx); value != nil {
reflectVal := reflect.ValueOf(&value)
// (erodkin) Unfortunately, the value we get out of the context when dealing with a
// slice is not, e.g., a `[]string`, but rather a `cli.StringSlice` that has a
// `Value` method that returns a `[]string`. Some short attempts to use reflection
// to access that `Value` method proved unproductive, so instead we match on all
// currently existing `cli.FooSlice` types. This should be relatively stable
// (currently we only use a `StringSlice` in the CLI), but in theory it would be
// sad if urfave introduced a new slice type and someone tried to use it in our
// CLI. The default warning message should hopefully provide some clarity if
// such a case should ever arise.
if field.Type.Kind() == reflect.Slice {
switch v := value.(type) {
case cli.StringSlice:
tValue.Field(i).Set(reflect.ValueOf(v.Value()))
case cli.IntSlice:
tValue.Field(i).Set(reflect.ValueOf(v.Value()))
case cli.Int64Slice:
tValue.Field(i).Set(reflect.ValueOf(v.Value()))
case cli.Float64Slice:
tValue.Field(i).Set(reflect.ValueOf(v.Value()))
default:
warningf(ctx.App.Writer,
"Attempted to set flag with unsupported slice type %s, this value may not be set correctly. consider filing a ticket to add support",
reflectVal.Type().Name())
}
} else {
tValue.Field(i).Set(reflect.ValueOf(value))
}
}
}
return t
}
func getGlobalArgs(ctx *cli.Context) (*globalArgs, error) {
gArgs := parseStructFromCtx[globalArgs](ctx)
// TODO(RSDK-9361) - currently nothing prevents a developer from creating globalArgs directly
// and thereby bypassing this check. We should find a way to prevent direct creation and thereby
// programmatically enforce compliance here.
if gArgs.DisableProfiles && gArgs.Profile != "" {
return nil, errors.New("profile specified with disable-profiles flag set")
}
return &gArgs, nil
}
func createCommandWithT[T any](f func(*cli.Context, T) error) func(*cli.Context) error {
return func(ctx *cli.Context) error {
t := parseStructFromCtx[T](ctx)
return f(ctx, t)
}
}
// createUsageText is a helper for formatting UsageTexts. The created UsageText
// contains "viam", the command, requiredFlags, "[other options]" if unrequiredOptions
// is true, "<command> [command options]" if subcommand is true, and all passed-in
// arguments in that order.
func createUsageText(command string, requiredFlags []string, unrequiredOptions, subcommand bool, arguments ...string) string {
formatted := []string{"viam", command}
for _, flag := range requiredFlags {
formatted = append(formatted, fmt.Sprintf("--%s=<%s>", flag, flag))
}
if unrequiredOptions {
if len(requiredFlags) == 0 {
formatted = append(formatted, "[options]")
} else {
formatted = append(formatted, "[other options]")
}
}
if subcommand {
formatted = append(formatted, "<command> [command options]")
}
formatted = append(formatted, arguments...)
return strings.Join(formatted, " ")
}
// formatAcceptedValues is a helper for formatting the usage text for flags that only accept certain values.
func formatAcceptedValues(description string, values ...string) string {
joined := strings.Join(values, ", ")
return fmt.Sprintf("%s. value(s) can be: [%s]", description, joined)
}
var app = &cli.App{
Name: "viam",
Usage: "interact with your Viam machines",
UsageText: "viam [global options] <command> [command options]",
HideHelpCommand: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: baseURLFlag,
Hidden: true,
Usage: "base URL of app",
},
// TODO(RSDK-9287) - this flag isn't used anywhere. Confirm that we actually need it,
// get rid of it if we don't.
&cli.StringFlag{
Name: configFlag,
Aliases: []string{"c"},
Usage: "load configuration from `FILE`",
},
&cli.BoolFlag{
Name: debugFlag,
Aliases: []string{"vvv"},
Usage: "enable debug logging",
},
&cli.BoolFlag{
Name: quietFlag,
Value: false,
Aliases: []string{"q"},
Usage: "suppress warnings",
},
&cli.StringFlag{
Name: profileFlag,
Usage: "specify a particular profile for the current command",
},
&cli.BoolFlag{
Name: disableProfilesFlag,
Aliases: []string{"disable-profile"}, // for ease of use; not backwards compatibility related
Usage: "disable usage of profiles, falling back to default behavior",
},
},
Commands: []*cli.Command{
{
Name: "login",
// NOTE(benjirewis): maintain `auth` as an alias for backward compatibility.
Aliases: []string{"auth"},
Usage: "login to app.viam.com",
UsageText: "viam login [options] [command] [command options]",
HideHelpCommand: true,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: loginFlagDisableBrowser,
Aliases: []string{"no-browser"}, // ease of use alias, not related to backwards compatibility
Usage: "prevent opening the default browser during login",
},
},
Action: createCommandWithT[loginActionArgs](LoginAction),
After: createCommandWithT[emptyArgs](CheckUpdateAction),
Subcommands: []*cli.Command{
{
Name: "print-access-token",
Usage: "print the access token associated with current credentials",
UsageText: createUsageText("login print-access-token", nil, false, false),
Action: createCommandWithT[emptyArgs](PrintAccessTokenAction),
},
{
Name: "api-key",
Usage: "authenticate with an api key",
UsageText: createUsageText("login api-key", []string{loginFlagKeyID, loginFlagKey}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: loginFlagKeyID,
Required: true,
Usage: "id of the key to authenticate with",
},
&cli.StringFlag{
Name: loginFlagKey,
Required: true,
Usage: "key to authenticate with",
},
},
Action: createCommandWithT[loginWithAPIKeyArgs](LoginWithAPIKeyAction),
},
},
},
{
Name: "logout",
Usage: "logout from current session",
UsageText: createUsageText("logout", nil, false, false),
Action: createCommandWithT[emptyArgs](LogoutAction),
},
{
Name: "whoami",
Usage: "get currently logged-in user",
UsageText: createUsageText("whoami", nil, false, false),
Action: createCommandWithT[emptyArgs](WhoAmIAction),
},
{
Name: "organizations",
Aliases: []string{"organization", "org"},
Usage: "work with organizations",
UsageText: createUsageText("organizations", nil, false, true),
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "auth-service",
Usage: "manage auth-service",
UsageText: createUsageText("organizations auth-service", nil, false, true),
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "enable",
Usage: "enable auth-service for OAuth applications",
UsageText: createUsageText("organizations auth-service enable", []string{generalFlagOrgID}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "organization ID tied to OAuth applications",
},
},
Action: createCommandWithT[enableAuthServiceArgs](EnableAuthServiceAction),
},
{
Name: "disable",
Usage: "disable auth-service for OAuth applications",
UsageText: createUsageText("organizations auth-service disable", []string{generalFlagOrgID}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "organization ID tied to OAuth applications",
},
},
Before: createCommandWithT[disableAuthServiceArgs](DisableAuthServiceConfirmation),
Action: createCommandWithT[disableAuthServiceArgs](DisableAuthServiceAction),
},
{
Name: "oauth-app",
Usage: "manage the OAuth applications for an organization",
UsageText: createUsageText("organizations auth-service oauth-app", nil, false, true),
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "delete",
Usage: "delete an OAuth application",
UsageText: createUsageText(
"organizations auth-service oauth-app delete", []string{generalFlagOrgID, oauthAppFlagClientID}, false, false,
),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "organization ID tied to the OAuth application",
},
&cli.StringFlag{
Name: oauthAppFlagClientID,
Required: true,
Usage: "client ID of the OAuth application to delete",
},
},
Before: createCommandWithT[deleteOAuthAppArgs](DeleteOAuthAppConfirmation),
Action: createCommandWithT[deleteOAuthAppArgs](DeleteOAuthAppAction),
},
{
Name: "list",
Usage: "list oauth applications for an organization",
UsageText: createUsageText("organizations auth-service oauth-app list", []string{generalFlagOrgID}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to get applications for",
},
},
Action: createCommandWithT[listOAuthAppsArgs](ListOAuthAppsAction),
},
{
Name: "read",
Usage: "read the OAuth configuration details",
UsageText: createUsageText(
"organizations auth-service oauth-app read", []string{generalFlagOrgID, oauthAppFlagClientID}, false, false,
),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "organization ID that is tied to the OAuth application",
},
&cli.StringFlag{
Name: oauthAppFlagClientID,
Usage: "id for the OAuth application",
Required: true,
},
},
Action: createCommandWithT[readOAuthAppArgs](ReadOAuthAppAction),
},
{
Name: "update",
Usage: "update an OAuth application",
UsageText: createUsageText(
"organizations auth-service oauth-app update", []string{generalFlagOrgID, oauthAppFlagClientID}, true, false,
),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "organization ID that is tied to the OAuth application",
},
&cli.StringFlag{
Name: oauthAppFlagClientID,
Usage: "id for the OAuth application to be updated",
Required: true,
},
&cli.StringFlag{
Name: oauthAppFlagClientName,
Usage: "updated name for the OAuth application",
},
&cli.StringFlag{
Name: oauthAppFlagClientAuthentication,
Usage: formatAcceptedValues(
"updated client authentication policy for the OAuth application",
string(ClientAuthenticationUnspecified), string(ClientAuthenticationRequired),
string(ClientAuthenticationNotRequired), string(ClientAuthenticationNotRequiredWhenUsingPKCE),
),
Value: unspecified,
},
&cli.StringFlag{
Name: oauthAppFlagURLValidation,
Usage: formatAcceptedValues(
"updated url validation for the OAuth application",
string(URLValidationUnspecified), string(URLValidationExactMatch), string(URLValidationAllowWildcards),
),
Value: unspecified,
},
&cli.StringFlag{
Name: oauthAppFlagPKCE,
Usage: formatAcceptedValues(
"updated pkce for the OAuth application",
string(PKCEUnspecified), string(PKCERequired), string(PKCENotRequired), string(PKCENotRequiredWhenUsingClientAuthentication),
),
Value: unspecified,
},
&cli.StringSliceFlag{
Name: oauthAppFlagOriginURIs,
Usage: "updated comma-separated origin uris for the OAuth application",
},
&cli.StringSliceFlag{
Name: oauthAppFlagRedirectURIs,
Usage: "updated comma separated redirect uris for the OAuth application",
},
&cli.StringFlag{
Name: oauthAppFlagLogoutURI,
Usage: "updated logout uri for the OAuth application",
},
&cli.StringSliceFlag{
Name: oauthAppFlagEnabledGrants,
Usage: formatAcceptedValues(
"updated comma separated enabled grants for the OAuth application",
string(EnabledGrantUnspecified), string(EnabledGrantRefreshToken), string(EnabledGrantPassword),
string(EnabledGrantImplicit), string(EnabledGrantDeviceCode), string(EnabledGrantAuthorizationCode),
),
},
},
Action: createCommandWithT[updateOAuthAppArgs](UpdateOAuthAppAction),
},
{
Name: "create",
Usage: "create an OAuth application",
UsageText: createUsageText("organizations auth-serice oauth-app create",
[]string{
generalFlagOrgID, oauthAppFlagClientAuthentication, oauthAppFlagURLValidation, oauthAppFlagPKCE,
oauthAppFlagRedirectURIs, oauthAppFlagLogoutURI, oauthAppFlagEnabledGrants,
},
true, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Usage: "organization ID that is tied to the OAuth application",
Required: true,
},
&cli.StringFlag{
Name: oauthAppFlagClientName,
Usage: "name for the OAuth application",
},
&cli.StringFlag{
Name: oauthAppFlagClientAuthentication,
Usage: formatAcceptedValues(
"client authentication policy for the OAuth application",
string(ClientAuthenticationUnspecified), string(ClientAuthenticationRequired),
string(ClientAuthenticationNotRequired), string(ClientAuthenticationNotRequiredWhenUsingPKCE),
),
Required: true,
},
&cli.StringFlag{
Name: oauthAppFlagURLValidation,
Usage: formatAcceptedValues(
"url validation for the OAuth application",
string(URLValidationUnspecified), string(URLValidationExactMatch), string(URLValidationAllowWildcards),
),
Required: true,
},
&cli.StringFlag{
Name: oauthAppFlagPKCE,
Usage: formatAcceptedValues(
"pkce for the OAuth application",
string(PKCEUnspecified), string(PKCERequired), string(PKCENotRequired), string(PKCENotRequiredWhenUsingClientAuthentication),
),
Required: true,
},
&cli.StringSliceFlag{
Name: oauthAppFlagOriginURIs,
Usage: "comma-separated origin uris for the OAuth application",
},
&cli.StringSliceFlag{
Name: oauthAppFlagRedirectURIs,
Usage: "comma-separated redirect uris for the OAuth application, requires at least one.",
Required: true,
},
&cli.StringFlag{
Name: oauthAppFlagLogoutURI,
Usage: "logout uri for the OAuth application",
Required: true,
},
&cli.StringSliceFlag{
Name: oauthAppFlagEnabledGrants,
Usage: formatAcceptedValues(
"comma-separated enabled grants for the OAuth application",
string(EnabledGrantUnspecified), string(EnabledGrantRefreshToken), string(EnabledGrantPassword),
string(EnabledGrantImplicit), string(EnabledGrantDeviceCode), string(EnabledGrantAuthorizationCode),
),
Required: true,
},
},
Action: createCommandWithT[createOAuthAppArgs](CreateOAuthAppAction),
},
},
},
},
},
{
Name: "list",
Usage: "list organizations for the current user",
UsageText: createUsageText("organizations list", nil, false, false),
Action: createCommandWithT[emptyArgs](ListOrganizationsAction),
},
{
Name: "logo",
Usage: "manage the logo for an organization",
UsageText: createUsageText("organizations logo", nil, false, true),
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "set",
Usage: "set the logo for an organization from a local file",
UsageText: createUsageText("organizations logo set", []string{generalFlagOrgID, organizationFlagLogoPath}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to set the logo for",
},
&cli.StringFlag{
Name: organizationFlagLogoPath,
Required: true,
Usage: "the file path of the logo to set for the organization. This must be a png file.",
},
},
Action: createCommandWithT[organizationsLogoSetArgs](OrganizationLogoSetAction),
},
{
Name: "get",
Usage: "get the logo for an organization",
UsageText: createUsageText("organizations logo get", []string{generalFlagOrgID}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to get the logo for",
},
},
Action: createCommandWithT[organizationsLogoGetArgs](OrganizationsLogoGetAction),
},
},
},
{
Name: "support-email",
Usage: "manage the support email for an organization",
UsageText: createUsageText("organizations support-email", nil, false, true),
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "set",
Usage: "set the support email for an organization",
UsageText: createUsageText(
"organizations support-email set", []string{generalFlagOrgID, organizationFlagSupportEmail}, false, false,
),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to set the support email for",
},
&cli.StringFlag{
Name: organizationFlagSupportEmail,
Required: true,
Usage: "the support email to set for the organization",
},
},
Action: createCommandWithT[organizationsSupportEmailSetArgs](OrganizationsSupportEmailSetAction),
},
{
Name: "get",
Usage: "get the support email for an organization",
UsageText: createUsageText("organizations support-email get", []string{generalFlagOrgID}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to get the support email for",
},
},
Action: createCommandWithT[organizationsSupportEmailGetArgs](OrganizationsSupportEmailGetAction),
},
},
},
{
Name: "billing-service",
Usage: "manage the organizations billing service",
UsageText: createUsageText("organizations billing-service", nil, false, true),
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "get-config",
Usage: "get the billing service config for an organization",
UsageText: createUsageText("organizations billing-service get-config", []string{generalFlagOrgID}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to get the billing config for",
},
},
Action: createCommandWithT[getBillingConfigArgs](GetBillingConfigAction),
},
{
Name: "disable",
Usage: "disable the billing service for an organization",
UsageText: createUsageText("organizations billing-service disable", []string{generalFlagOrgID}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to disable the billing service for",
},
},
Action: createCommandWithT[organizationDisableBillingServiceArgs](OrganizationDisableBillingServiceAction),
},
{
Name: "update",
Usage: "update the billing service update for an organization",
UsageText: createUsageText(
"organizations billing-service update", []string{generalFlagOrgID, organizationBillingAddress}, false, false,
),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to update the billing service for",
},
&cli.StringFlag{
Name: organizationBillingAddress,
Required: true,
Usage: "the stringified address that follows the pattern: line1, line2 (optional), city, state, zipcode",
},
},
Action: createCommandWithT[updateBillingServiceArgs](UpdateBillingServiceAction),
},
{
Name: "enable",
Usage: "enable the billing service for an organization",
UsageText: createUsageText(
"organizations billing-service enable", []string{generalFlagOrgID, organizationBillingAddress}, false, false,
),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to enable the billing service for",
},
&cli.StringFlag{
Name: organizationBillingAddress,
Required: true,
Usage: "the stringified address that follows the pattern: line1, line2 (optional), city, state, zipcode",
},
},
Action: createCommandWithT[organizationEnableBillingServiceArgs](OrganizationEnableBillingServiceAction),
},
},
},
{
Name: "api-key",
Usage: "work with an organization's api keys",
UsageText: createUsageText("organizations api-key", nil, false, true),
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "create",
Usage: "create an api key for your organization",
UsageText: createUsageText("organizations api-key create", []string{generalFlagOrgID}, true, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrgID,
Required: true,
Usage: "the org to create an api key for",
},
&cli.StringFlag{
Name: generalFlagName,
Usage: "the name of the key",
DefaultText: "login info with current time",
},
},
Action: createCommandWithT[organizationsAPIKeyCreateArgs](OrganizationsAPIKeyCreateAction),
},
},
},
},
},
{
Name: "locations",
Aliases: []string{"location"},
Usage: "work with locations",
UsageText: createUsageText("locations", nil, false, true),
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "list locations for the current user",
// use custom usage text to show default organization flag usage even if it isn't required
UsageText: "viam locations list [--organization=<organization>]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagOrganization,
Aliases: []string{generalFlagAliasOrg, generalFlagOrgID, generalFlagAliasOrgName},
DefaultText: "first organization alphabetically",
},
},
Action: createCommandWithT[listLocationsArgs](ListLocationsAction),
},
{
Name: "api-key",
Usage: "work with an api-key for your location",
UsageText: createUsageText("locations api-key", nil, false, true),
Subcommands: []*cli.Command{
{
Name: "create",
Usage: "create an api key for your location",
UsageText: createUsageText("locations api-key create", []string{generalFlagLocationID}, true, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: generalFlagLocationID,
Required: true,
Usage: "id of the location to create an api-key for",
},
&cli.StringFlag{
Name: generalFlagName,
Usage: "the name of the key (defaults to your login info with the current time)",
},
&cli.StringFlag{
Name: generalFlagOrgID,
Usage: "the org-id to attach the key to",
DefaultText: "will attempt to attach key to the org of the location if only one org is attached to the location",
},
},
Action: createCommandWithT[locationAPIKeyCreateArgs](LocationAPIKeyCreateAction),
},
},
},
},
},
{
Name: "profiles",
Usage: "work with CLI profiles",
UsageText: createUsageText("profiles", nil, false, true),
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "update",
Usage: "update an existing profile for authentication, or add it if it doesn't exist",
UsageText: createUsageText("profiles update", []string{profileFlagName, loginFlagKeyID, loginFlagKey}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: profileFlagName,
Required: true,
Usage: "name of the profile to update",
},
&cli.StringFlag{
Name: loginFlagKeyID,
Required: true,
Usage: "id of the profile's API key",
},
&cli.StringFlag{
Name: loginFlagKey,
Required: true,
Usage: "the profile's API key",
},
},
Action: createCommandWithT[addOrUpdateProfileArgs](UpdateProfileAction),
},
{
Name: "add",
Usage: "add a new profile for authentication (errors if the profile already exists)",
UsageText: createUsageText("profiles add", []string{profileFlagName, loginFlagKeyID, loginFlagKey}, false, false),
Flags: []cli.Flag{
&cli.StringFlag{
Name: profileFlagName,
Required: true,
Usage: "name of the profile to add",
},
&cli.StringFlag{
Name: loginFlagKeyID,
Required: true,
Usage: "id of the profile's API key",
},
&cli.StringFlag{
Name: loginFlagKey,
Required: true,
Usage: "the profile's API key",
},
},
Action: createCommandWithT[addOrUpdateProfileArgs](AddProfileAction),
},