-
Notifications
You must be signed in to change notification settings - Fork 26
Hide multi-channel license support from CLI #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,6 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "time" | ||
|
|
||
| "github.com/pkg/errors" | ||
|
|
@@ -15,8 +13,7 @@ import ( | |
| type createCustomerOpts struct { | ||
| Name string | ||
| CustomID string | ||
| ChannelNames []string | ||
| DefaultChannel string | ||
| ChannelName string | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent field naming between create and update optsLow Severity The Additional Locations (1) |
||
| ExpiryDuration time.Duration | ||
| EnsureChannel bool | ||
| IsAirgapEnabled bool | ||
|
|
@@ -54,9 +51,6 @@ The --app flag must be set to specify the target application.`, | |
| Example: `# Create a basic customer with a name and assigned to a channel | ||
| replicated customer create --app myapp --name "Acme Inc" --channel stable | ||
|
|
||
| # Create a customer with multiple channels and a custom ID | ||
| replicated customer create --app myapp --name "Beta Corp" --custom-id "BETA123" --channel beta --channel stable | ||
|
|
||
| # Create a paid customer with specific features enabled | ||
| replicated customer create --app myapp --name "Enterprise Ltd" --type paid --channel enterprise --airgap --snapshot | ||
|
|
||
|
|
@@ -65,8 +59,7 @@ replicated customer create --app myapp --name "Trial User" --type trial --channe | |
|
|
||
| # Create a customer with all available options | ||
| replicated customer create --app myapp --name "Full Options Inc" --custom-id "FULL001" \ | ||
| --channel stable --channel beta --default-channel stable --type paid \ | ||
| --email "contact@fulloptions.com" --expires-in 8760h \ | ||
| --channel stable --type paid --email "contact@fulloptions.com" --expires-in 8760h \ | ||
| --airgap --snapshot --kots-install --embedded-cluster-download \ | ||
| --support-bundle-upload --ensure-channel`, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
|
|
@@ -79,8 +72,7 @@ replicated customer create --app myapp --name "Full Options Inc" --custom-id "FU | |
| parent.AddCommand(cmd) | ||
| cmd.Flags().StringVar(&opts.Name, "name", "", "Name of the customer") | ||
| cmd.Flags().StringVar(&opts.CustomID, "custom-id", "", "Set a custom customer ID to more easily tie this customer record to your external data systems") | ||
| cmd.Flags().StringArrayVar(&opts.ChannelNames, "channel", []string{}, "Release channel to which the customer should be assigned (can be specified multiple times)") | ||
| cmd.Flags().StringVar(&opts.DefaultChannel, "default-channel", "", "Which of the specified channels should be the default channel. if not set, the first channel specified will be the default channel.") | ||
| cmd.Flags().StringVar(&opts.ChannelName, "channel", "", "Release channel to which the customer should be assigned") | ||
| cmd.Flags().DurationVar(&opts.ExpiryDuration, "expires-in", 0, "If set, an expiration date will be set on the license. Supports Go durations like '72h' or '3600m'") | ||
| cmd.Flags().BoolVar(&opts.EnsureChannel, "ensure-channel", false, "If set, channel will be created if it does not exist.") | ||
| cmd.Flags().BoolVar(&opts.IsAirgapEnabled, "airgap", false, "If set, the license will allow airgap installs.") | ||
|
|
@@ -126,50 +118,24 @@ func (r *runners) createCustomer(cmd *cobra.Command, opts createCustomerOpts, ou | |
| opts.CustomerType = "prod" | ||
| } | ||
|
|
||
| channels := []kotsclient.CustomerChannel{} | ||
|
|
||
| foundDefaultChannel := false | ||
| for _, requestedChannel := range opts.ChannelNames { | ||
| getOrCreateChannelOptions := client.GetOrCreateChannelOptions{ | ||
| AppID: r.appID, | ||
| AppType: r.appType, | ||
| NameOrID: requestedChannel, | ||
| Description: "", | ||
| CreateIfAbsent: opts.EnsureChannel, | ||
| } | ||
|
|
||
| channel, err := r.api.GetOrCreateChannelByName(getOrCreateChannelOptions) | ||
| if err != nil { | ||
| return errors.Wrap(err, "get channel") | ||
| } | ||
|
|
||
| customerChannel := kotsclient.CustomerChannel{ | ||
| ID: channel.ID, | ||
| } | ||
|
|
||
| if opts.DefaultChannel == requestedChannel { | ||
| customerChannel.IsDefault = true | ||
| foundDefaultChannel = true | ||
| } | ||
|
|
||
| channels = append(channels, customerChannel) | ||
| } | ||
|
|
||
| if len(channels) == 0 { | ||
| return errors.New("no channels found") | ||
| getOrCreateChannelOptions := client.GetOrCreateChannelOptions{ | ||
| AppID: r.appID, | ||
| AppType: r.appType, | ||
| NameOrID: opts.ChannelName, | ||
marcw-replicated marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Description: "", | ||
| CreateIfAbsent: opts.EnsureChannel, | ||
| } | ||
|
|
||
| if opts.DefaultChannel != "" && !foundDefaultChannel { | ||
| return errors.New("default channel not found in specified channels") | ||
| channel, err := r.api.GetOrCreateChannelByName(getOrCreateChannelOptions) | ||
| if err != nil { | ||
| return errors.Wrap(err, "get channel") | ||
| } | ||
|
|
||
| if !foundDefaultChannel { | ||
| if len(channels) > 1 { | ||
| fmt.Fprintln(os.Stderr, "No default channel specified, defaulting to the first channel specified.") | ||
| } | ||
| firstChannel := channels[0] | ||
| firstChannel.IsDefault = true | ||
| channels[0] = firstChannel | ||
| channels := []kotsclient.CustomerChannel{ | ||
| { | ||
| ID: channel.ID, | ||
| IsDefault: true, | ||
| }, | ||
| } | ||
|
|
||
| createOpts := kotsclient.CreateCustomerOpts{ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just commenting here, because there's no good place for it. I noticed in the output of your screenshots the column header still said "CHANNELS" (plural). That needs to be updated here. There might be other places too, but I'm not familiar with this repo, but it looks like maybe this customer type too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i saw that
CHANNELStoo! But I looked up the git history for that line of code and it has always been plural (since 2019/ before multi-channel). I'd be down to change it to singular but since its always been plural i just left it.Also that customer type is the API contract which still technically is an array.
Thanks for reviewing all this so well!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point! 😉 I don't see any reason not to change it to singular though, especially since we're removing this functionality now.