|
7 | 7 | "fmt" |
8 | 8 | "net/mail" |
9 | 9 | "os" |
| 10 | + "reflect" |
10 | 11 | "strconv" |
11 | 12 | "strings" |
12 | 13 |
|
@@ -158,6 +159,12 @@ var ( |
158 | 159 | Aliases: []string{"re"}, |
159 | 160 | Required: false, |
160 | 161 | } |
| 162 | + connectivityRuleIdsFlag = &cli.StringSliceFlag{ |
| 163 | + Name: connectivityRuleIdsFlagName, |
| 164 | + Usage: "The list of connectivity rule IDs, can be used in create namespace, update namespace and get list of connectivity rules. example: --ids id1 --ids id2 --ids id3", |
| 165 | + Aliases: []string{"ids"}, |
| 166 | + Required: false, |
| 167 | + } |
161 | 168 | ) |
162 | 169 |
|
163 | 170 | type NamespaceClient struct { |
@@ -497,80 +504,90 @@ func ReadCertFilters(ctx *cli.Context) ([]byte, error) { |
497 | 504 | return certFilterBytes, nil |
498 | 505 | } |
499 | 506 |
|
| 507 | +func getCreateNamespaceFlags() []cli.Flag { |
| 508 | + baseFlags := []cli.Flag{ |
| 509 | + RequestIDFlag, |
| 510 | + CaCertificateFlag, |
| 511 | + &cli.StringFlag{ |
| 512 | + Name: NamespaceFlagName, |
| 513 | + Usage: "The namespace hosted on temporal cloud", |
| 514 | + Aliases: []string{"n"}, |
| 515 | + Required: true, |
| 516 | + }, |
| 517 | + &cli.StringSliceFlag{ |
| 518 | + Name: namespaceRegionFlagName, |
| 519 | + Usage: "Create namespace in specified regions; if multiple regions are selected, the first one will be the active region. See 'tcld account list-regions' to get a list of available regions for your account", |
| 520 | + Aliases: []string{"re"}, |
| 521 | + Required: true, |
| 522 | + }, |
| 523 | + &cli.IntFlag{ |
| 524 | + Name: RetentionDaysFlagName, |
| 525 | + Usage: "The retention of the namespace in days", |
| 526 | + Aliases: []string{"rd"}, |
| 527 | + Value: 30, |
| 528 | + }, |
| 529 | + &cli.StringFlag{ |
| 530 | + Name: authMethodFlagName, |
| 531 | + Usage: "The authentication method to use for the namespace (e.g. 'mtls', 'api_key')", |
| 532 | + Value: AuthMethodMTLS, |
| 533 | + }, |
| 534 | + &cli.PathFlag{ |
| 535 | + Name: CaCertificateFileFlagName, |
| 536 | + Usage: "The path to the ca pem file", |
| 537 | + Aliases: []string{"cf"}, |
| 538 | + }, |
| 539 | + &cli.PathFlag{ |
| 540 | + Name: certificateFilterFileFlagName, |
| 541 | + Usage: `Path to a JSON file that defines the certificate filters that will be added to the namespace. Sample JSON: { "filters": [ { "commonName": "test1" } ] }`, |
| 542 | + Aliases: []string{"cff"}, |
| 543 | + }, |
| 544 | + &cli.StringFlag{ |
| 545 | + Name: certificateFilterInputFlagName, |
| 546 | + Usage: `JSON that defines the certificate filters that will be added to the namespace. Sample JSON: { "filters": [ { "commonName": "test1" } ] }`, |
| 547 | + Aliases: []string{"cfi"}, |
| 548 | + }, |
| 549 | + &cli.StringSliceFlag{ |
| 550 | + Name: searchAttributeFlagName, |
| 551 | + Usage: fmt.Sprintf("Flag can be used multiple times; value must be \"name=type\"; valid types are: %v", getSearchAttributeTypes()), |
| 552 | + Aliases: []string{"sa"}, |
| 553 | + }, |
| 554 | + &cli.StringSliceFlag{ |
| 555 | + Name: userNamespacePermissionFlagName, |
| 556 | + Usage: fmt.Sprintf("Flag can be used multiple times; value must be \"email=permission\"; valid permissions are: %v", getNamespacePermissionTypes()), |
| 557 | + Aliases: []string{"p"}, |
| 558 | + }, |
| 559 | + &cli.BoolFlag{ |
| 560 | + Name: enableDeleteProtectionFlagName, |
| 561 | + Usage: "Enable delete protection on the namespace", |
| 562 | + Aliases: []string{"edp"}, |
| 563 | + }, |
| 564 | + codecEndpointFlag, |
| 565 | + codecPassAccessTokenFlag, |
| 566 | + codecIncludeCredentialsFlag, |
| 567 | + &cli.StringFlag{ |
| 568 | + Name: cloudProviderFlagName, |
| 569 | + Usage: `Cloud provider for the namespace to be created for, currently support [aws, gcp]. For this version, if not specified, we default to aws`, |
| 570 | + Aliases: []string{"cp"}, |
| 571 | + // this is a temporary solution, we will have a follow up version update to make the cloud provider mandatory |
| 572 | + Value: CloudProviderAWS, |
| 573 | + }, |
| 574 | + } |
| 575 | + |
| 576 | + if IsFeatureEnabled(ConnectivityRuleFeatureFlag) { |
| 577 | + baseFlags = append(baseFlags, connectivityRuleIdsFlag) |
| 578 | + } |
| 579 | + |
| 580 | + return baseFlags |
| 581 | +} |
| 582 | + |
500 | 583 | func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut, error) { |
501 | 584 | var c *NamespaceClient |
502 | 585 | subCommands := []*cli.Command{ |
503 | 586 | { |
504 | 587 | Name: "create", |
505 | 588 | Usage: "Create a temporal namespace", |
506 | 589 | Aliases: []string{"c"}, |
507 | | - Flags: []cli.Flag{ |
508 | | - RequestIDFlag, |
509 | | - CaCertificateFlag, |
510 | | - &cli.StringFlag{ |
511 | | - Name: NamespaceFlagName, |
512 | | - Usage: "The namespace hosted on temporal cloud", |
513 | | - Aliases: []string{"n"}, |
514 | | - Required: true, |
515 | | - }, |
516 | | - &cli.StringSliceFlag{ |
517 | | - Name: namespaceRegionFlagName, |
518 | | - Usage: "Create namespace in specified regions; if multiple regions are selected, the first one will be the active region. See 'tcld account list-regions' to get a list of available regions for your account", |
519 | | - Aliases: []string{"re"}, |
520 | | - Required: true, |
521 | | - }, |
522 | | - &cli.IntFlag{ |
523 | | - Name: RetentionDaysFlagName, |
524 | | - Usage: "The retention of the namespace in days", |
525 | | - Aliases: []string{"rd"}, |
526 | | - Value: 30, |
527 | | - }, |
528 | | - &cli.StringFlag{ |
529 | | - Name: authMethodFlagName, |
530 | | - Usage: "The authentication method to use for the namespace (e.g. 'mtls', 'api_key')", |
531 | | - Value: AuthMethodMTLS, |
532 | | - }, |
533 | | - &cli.PathFlag{ |
534 | | - Name: CaCertificateFileFlagName, |
535 | | - Usage: "The path to the ca pem file", |
536 | | - Aliases: []string{"cf"}, |
537 | | - }, |
538 | | - &cli.PathFlag{ |
539 | | - Name: certificateFilterFileFlagName, |
540 | | - Usage: `Path to a JSON file that defines the certificate filters that will be added to the namespace. Sample JSON: { "filters": [ { "commonName": "test1" } ] }`, |
541 | | - Aliases: []string{"cff"}, |
542 | | - }, |
543 | | - &cli.StringFlag{ |
544 | | - Name: certificateFilterInputFlagName, |
545 | | - Usage: `JSON that defines the certificate filters that will be added to the namespace. Sample JSON: { "filters": [ { "commonName": "test1" } ] }`, |
546 | | - Aliases: []string{"cfi"}, |
547 | | - }, |
548 | | - &cli.StringSliceFlag{ |
549 | | - Name: searchAttributeFlagName, |
550 | | - Usage: fmt.Sprintf("Flag can be used multiple times; value must be \"name=type\"; valid types are: %v", getSearchAttributeTypes()), |
551 | | - Aliases: []string{"sa"}, |
552 | | - }, |
553 | | - &cli.StringSliceFlag{ |
554 | | - Name: userNamespacePermissionFlagName, |
555 | | - Usage: fmt.Sprintf("Flag can be used multiple times; value must be \"email=permission\"; valid permissions are: %v", getNamespacePermissionTypes()), |
556 | | - Aliases: []string{"p"}, |
557 | | - }, |
558 | | - &cli.BoolFlag{ |
559 | | - Name: enableDeleteProtectionFlagName, |
560 | | - Usage: "Enable delete protection on the namespace", |
561 | | - Aliases: []string{"edp"}, |
562 | | - }, |
563 | | - codecEndpointFlag, |
564 | | - codecPassAccessTokenFlag, |
565 | | - codecIncludeCredentialsFlag, |
566 | | - &cli.StringFlag{ |
567 | | - Name: cloudProviderFlagName, |
568 | | - Usage: `Cloud provider for the namespace to be created for, currently support [aws, gcp]. For this version, if not specified, we default to aws`, |
569 | | - Aliases: []string{"cp"}, |
570 | | - // this is a temporary solution, we will have a follow up version update to make the cloud provider mandatory |
571 | | - Value: CloudProviderAWS, |
572 | | - }, |
573 | | - }, |
| 590 | + Flags: getCreateNamespaceFlags(), |
574 | 591 | Action: func(ctx *cli.Context) error { |
575 | 592 | n := &namespace.Namespace{ |
576 | 593 | RequestId: ctx.String(RequestIDFlagName), |
@@ -722,6 +739,11 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut, |
722 | 739 | EnableDeleteProtection: ctx.Bool(enableDeleteProtectionFlagName), |
723 | 740 | } |
724 | 741 |
|
| 742 | + connectivityRuleIds := ctx.StringSlice(connectivityRuleIdsFlagName) |
| 743 | + if len(connectivityRuleIds) > 0 { |
| 744 | + n.Spec.ConnectivityRuleIds = connectivityRuleIds |
| 745 | + } |
| 746 | + |
725 | 747 | return c.createNamespace(n, unp) |
726 | 748 | }, |
727 | 749 | }, |
@@ -2113,8 +2135,38 @@ func NewNamespaceCommand(getNamespaceClientFn GetNamespaceClientFn) (CommandOut, |
2113 | 2135 | exportGCSCommands.Subcommands = append(exportGCSCommands.Subcommands, exportGeneralCommands...) |
2114 | 2136 | exportCommand.Subcommands = append(exportCommand.Subcommands, exportGCSCommands) |
2115 | 2137 |
|
| 2138 | + coonectivityRuleCommand := &cli.Command{ |
| 2139 | + Name: "set-connectivity-rules", |
| 2140 | + Usage: "set the connectivity rules for a namespace", |
| 2141 | + Aliases: []string{"scrs"}, |
| 2142 | + Flags: []cli.Flag{ |
| 2143 | + NamespaceFlag, |
| 2144 | + connectivityRuleIdsFlag, |
| 2145 | + }, |
| 2146 | + Action: func(ctx *cli.Context) error { |
| 2147 | + n, err := c.getNamespace(ctx.String(NamespaceFlagName)) |
| 2148 | + if err != nil { |
| 2149 | + return err |
| 2150 | + } |
| 2151 | + connectivityRuleIds := ctx.StringSlice(connectivityRuleIdsFlagName) |
| 2152 | + if len(connectivityRuleIds) == 0 { |
| 2153 | + return fmt.Errorf("connectivity rule ids must be provided") |
| 2154 | + } |
| 2155 | + if reflect.DeepEqual(n.Spec.ConnectivityRuleIds, connectivityRuleIds) { |
| 2156 | + return fmt.Errorf("no connectivity rule changes to apply") |
| 2157 | + } |
| 2158 | + |
| 2159 | + n.Spec.ConnectivityRuleIds = connectivityRuleIds |
| 2160 | + return c.updateNamespace(ctx, n) |
| 2161 | + }, |
| 2162 | + } |
| 2163 | + |
2116 | 2164 | subCommands = append(subCommands, exportCommand) |
2117 | 2165 |
|
| 2166 | + if IsFeatureEnabled(ConnectivityRuleFeatureFlag) { |
| 2167 | + subCommands = append(subCommands, coonectivityRuleCommand) |
| 2168 | + } |
| 2169 | + |
2118 | 2170 | command := &cli.Command{ |
2119 | 2171 | Name: "namespace", |
2120 | 2172 | Aliases: []string{"n"}, |
|
0 commit comments