Skip to content

Commit 6dda16f

Browse files
committed
Improved messaging when requested channel slug not allowed by license
1 parent 6c3138d commit 6dda16f

File tree

5 files changed

+39
-6
lines changed

5 files changed

+39
-6
lines changed

cmd/kots/cli/install.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ func InstallCmd() *cobra.Command {
167167
if err != nil {
168168
return errors.Wrap(err, "failed to extract preferred channel slug")
169169
}
170+
if preferredChannelSlug == "" {
171+
preferredChannelSlug = "stable"
172+
log.ActionWithoutSpinner(fmt.Sprintf("No channel specified in upstream URI, falling back to channel %q.", preferredChannelSlug))
173+
}
174+
170175
license, err = kotslicense.VerifyAndUpdateLicense(log, license, preferredChannelSlug, isAirgap)
171176
if err != nil {
172177
return errors.Wrap(err, "failed to verify and update license")

cmd/kots/cli/pull.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cli
22

33
import (
4+
"fmt"
45
"os"
56
"path"
67
"strings"
@@ -101,13 +102,19 @@ func PullCmd() *cobra.Command {
101102
}
102103

103104
upstream := pull.RewriteUpstream(args[0])
105+
106+
log := logger.NewCLILogger(cmd.OutOrStdout())
107+
log.Initialize()
108+
104109
preferredChannelSlug, err := extractPreferredChannelSlug(upstream)
105110
if err != nil {
106111
return errors.Wrap(err, "failed to extract preferred channel slug")
107112
}
108113

109-
log := logger.NewCLILogger(cmd.OutOrStdout())
110-
log.Initialize()
114+
if preferredChannelSlug == "" {
115+
preferredChannelSlug = "stable"
116+
log.ActionWithoutSpinner(fmt.Sprintf("No channel specified in upstream URI, falling back to channel %q.", preferredChannelSlug))
117+
}
111118

112119
// If we are passed a multi-channel license, verify that the requested channel is in the license
113120
// so that we can warn the user immediately if it is not.

cmd/kots/cli/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,5 @@ func extractPreferredChannelSlug(upstreamURI string) (string, error) {
6767
if replicatedUpstream.Channel != nil {
6868
return *replicatedUpstream.Channel, nil
6969
}
70-
return "stable", nil
70+
return "", nil
7171
}

cmd/kots/cli/util_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func Test_extractPreferredChannelSlug(t *testing.T) {
111111
args{
112112
upstreamURI: "replicated://app-slug",
113113
},
114-
"stable", // default channel
114+
"",
115115
false,
116116
},
117117
{

pkg/license/multichannel.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package license
22

33
import (
4+
"fmt"
5+
"strings"
6+
47
"github.com/pkg/errors"
58
"github.com/replicatedhq/kots/pkg/logger"
69
"github.com/replicatedhq/kots/pkg/replicatedapp"
@@ -40,11 +43,20 @@ func VerifyAndUpdateLicense(log *logger.CLILogger, license *kotsv1beta1.License,
4043
return nil, nil
4144
}
4245
if isAirgap {
46+
log.ActionWithSpinner("Verifying channel slug %q allowed by license", preferredChannelSlug)
4347
if !canInstallFromChannel(preferredChannelSlug, license) {
44-
return nil, errors.New("requested channel not found in supplied license")
48+
log.FinishSpinnerWithError()
49+
return license, errors.New(fmt.Sprintf("channel slug %q is not allowed by license", preferredChannelSlug))
50+
}
51+
log.FinishSpinner()
52+
validChannels := []string{}
53+
for _, channel := range license.Spec.Channels {
54+
validChannels = append(validChannels, fmt.Sprintf("%s/%s", license.Spec.AppSlug, channel.ChannelSlug))
4555
}
56+
log.ChildActionWithoutSpinner(fmt.Sprintf("To install from an allowed channel, use one of the following: %s", strings.Join(validChannels, ", ")))
4657
return license, nil
4758
}
59+
4860
log.ActionWithSpinner("Checking for license update")
4961
// we fetch the latest license to ensure that the license is up to date, before proceeding
5062
updatedLicense, err := replicatedapp.GetLatestLicense(license, "")
@@ -53,8 +65,17 @@ func VerifyAndUpdateLicense(log *logger.CLILogger, license *kotsv1beta1.License,
5365
return nil, errors.Wrap(err, "failed to get latest license")
5466
}
5567
log.FinishSpinner()
68+
69+
log.ActionWithSpinner("Verifying channel slug %q allowed by license", preferredChannelSlug)
5670
if canInstallFromChannel(preferredChannelSlug, updatedLicense.License) {
71+
log.FinishSpinner()
5772
return updatedLicense.License, nil
5873
}
59-
return nil, errors.New("requested channel not found in latest license")
74+
log.FinishSpinnerWithError()
75+
validChannels := []string{}
76+
for _, channel := range license.Spec.Channels {
77+
validChannels = append(validChannels, fmt.Sprintf("%s/%s", license.Spec.AppSlug, channel.ChannelSlug))
78+
}
79+
log.ChildActionWithoutSpinner(fmt.Sprintf("To install from an allowed channel, use one of the following: %s", strings.Join(validChannels, ", ")))
80+
return updatedLicense.License, errors.New(fmt.Sprintf("channel slug %q is not allowed by latest license", preferredChannelSlug))
6081
}

0 commit comments

Comments
 (0)