Skip to content

Commit

Permalink
Validate license key if supplied before running fleetctl preview
Browse files Browse the repository at this point in the history
For #22884
  • Loading branch information
iansltx committed Dec 10, 2024
1 parent 149e5b1 commit 9f535c9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/22884-license-error-fleetctl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Added license key validation on `fleetctl preview` if a license key is provided; fixes cases where an invalid license key would cause `fleetctl preview` to hang.
12 changes: 10 additions & 2 deletions cmd/fleetctl/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"time"

"github.com/cenkalti/backoff/v4"
"github.com/fleetdm/fleet/v4/ee/server/licensing"
"github.com/fleetdm/fleet/v4/orbit/pkg/constant"
"github.com/fleetdm/fleet/v4/orbit/pkg/packaging"
"github.com/fleetdm/fleet/v4/orbit/pkg/update"
Expand Down Expand Up @@ -48,6 +49,8 @@ const (
previewConfigPathFlagName = "preview-config-path"
disableOpenBrowser = "disable-open-browser"

licenseError = "License key is invalid. Please check your license key and try again, or run `fleetctl preview` without the --license-key option to try Fleet Free."

dockerComposeV1 dockerComposeVersion = 1
dockerComposeV2 dockerComposeVersion = 2
)
Expand Down Expand Up @@ -158,6 +161,11 @@ Use the stop and reset subcommands to manage the server and dependencies once st
},
},
Action: func(c *cli.Context) error {
licenseKey := c.String(licenseKeyFlagName)
if _, err := licensing.LoadLicense(licenseKey); err != nil {
return errors.New(licenseError)
}

if err := checkDocker(); err != nil {
return err
}
Expand Down Expand Up @@ -273,7 +281,7 @@ Use the stop and reset subcommands to manage the server and dependencies once st

fmt.Println("Starting Docker containers...")
cmd := compose.Command("up", "-d", "--remove-orphans", "mysql01", "redis01", "fleet01")
cmd.Env = append(os.Environ(), "FLEET_LICENSE_KEY="+c.String(licenseKeyFlagName))
cmd.Env = append(os.Environ(), "FLEET_LICENSE_KEY="+licenseKey)
out, err = cmd.CombinedOutput()
if err != nil {
fmt.Println(string(out))
Expand All @@ -289,7 +297,7 @@ Use the stop and reset subcommands to manage the server and dependencies once st
// has finished starting up so that there is no conflict with
// running database migrations.
cmd = compose.Command("up", "-d", "--remove-orphans", "fleet02")
cmd.Env = append(os.Environ(), "FLEET_LICENSE_KEY="+c.String(licenseKeyFlagName))
cmd.Env = append(os.Environ(), "FLEET_LICENSE_KEY="+licenseKey)
out, err = cmd.CombinedOutput()
if err != nil {
fmt.Println(string(out))
Expand Down

0 comments on commit 9f535c9

Please sign in to comment.