Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions cmd/env_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,17 @@ func TestOptInEnvFlags_AppliesEnvValueToFlag(t *testing.T) {
{flagName: cmdProvider, envName: "DEVSY_PROVIDER", want: "docker", persistent: true},
{flagName: "debug", envName: "DEVSY_DEBUG", want: "true", persistent: true},
{
cmdPath: "pro workspace list",
cmdPath: "platform workspace list",
flagName: "host",
envName: envDevsyHost,
want: "pro.example.com",
},
{cmdPath: "pro cluster list", flagName: "project", envName: envDevsyProject, want: "demo"},
{
cmdPath: "platform cluster list",
flagName: "project",
envName: envDevsyProject,
want: "demo",
},
{
cmdPath: "internal agent container setup",
flagName: "access-key",
Expand Down Expand Up @@ -97,7 +102,7 @@ func TestOptInEnvFlags_EmptyEnvIsNoOp(t *testing.T) {
t.Setenv(envPlatformEnabled, "true")
t.Setenv(envDevsyHost, "")
rootCmd, _ := BuildRoot()
cmd := resolveCommand(t, rootCmd, "pro workspace list")
cmd := resolveCommand(t, rootCmd, "platform workspace list")
f := cmd.Flags().Lookup(names.Host)
require.NotNil(t, f)
assert.False(t, f.Changed, "empty env value must not mark flag as Changed")
Expand All @@ -111,15 +116,15 @@ func TestOptInEnvFlags_CLIOverridesEnv(t *testing.T) {
t.Setenv(envDevsyHost, "env-value")
rootCmd, _ := BuildRoot()
// Replace the leaf command's RunE so Execute() doesn't try to actually
// talk to a pro instance; we only care that flag resolution put cli-value
// talk to a platform instance; we only care that flag resolution put cli-value
// in cmd.Host.
leaf := resolveCommand(t, rootCmd, "pro workspace list")
leaf := resolveCommand(t, rootCmd, "platform workspace list")
var seen string
leaf.RunE = func(c *cobra.Command, _ []string) error {
seen, _ = c.Flags().GetString(names.Host)
return nil
}
rootCmd.SetArgs([]string{"pro", cmdWorkspace, cmdList, "--host", "cli-value"})
rootCmd.SetArgs([]string{"platform", cmdWorkspace, cmdList, "--host", "cli-value"})
require.NoError(t, rootCmd.Execute())
assert.Equal(t, "cli-value", seen, "CLI flag must override env value")
}
Expand All @@ -128,19 +133,19 @@ func TestOptInEnvFlags_EnvSatisfiesRequired(t *testing.T) {
t.Setenv(envPlatformEnabled, "true")
t.Setenv(envDevsyHost, "from-env.example.com")
rootCmd, _ := BuildRoot()
leaf := resolveCommand(t, rootCmd, "pro workspace list")
leaf := resolveCommand(t, rootCmd, "platform workspace list")
var seen string
leaf.RunE = func(c *cobra.Command, _ []string) error {
seen, _ = c.Flags().GetString(names.Host)
return nil
}
rootCmd.SetArgs([]string{"pro", cmdWorkspace, cmdList})
rootCmd.SetArgs([]string{"platform", cmdWorkspace, cmdList})
require.NoError(t, rootCmd.Execute(), "required --host must be satisfied by env")
assert.Equal(t, "from-env.example.com", seen)
}

// TestOptInEnvFlags_PlatformSubcommandSweep asserts that DEVSY_HOST applies to
// every pro subcommand that exposes --host (and similarly for --project).
// every platform subcommand that exposes --host (and similarly for --project).
// This catches the regression where a future addition to cmd/pro/ forgets
// the inline BindEnv call.
func TestOptInEnvFlags_PlatformSubcommandSweep(t *testing.T) {
Expand All @@ -149,7 +154,7 @@ func TestOptInEnvFlags_PlatformSubcommandSweep(t *testing.T) {
t.Setenv(env, "sweep-"+strings.ToLower(env))
}
rootCmd, _ := BuildRoot()
platformCmd := resolveCommand(t, rootCmd, "pro")
platformCmd := resolveCommand(t, rootCmd, "platform")

var walk func(c *cobra.Command)
walk = func(c *cobra.Command) {
Expand All @@ -168,7 +173,7 @@ func TestOptInEnvFlags_PlatformSubcommandSweep(t *testing.T) {
walk(platformCmd)
}

// TestPlatformCommand_HiddenWhenDisabled verifies pro is gated off by default.
// TestPlatformCommand_HiddenWhenDisabled verifies platform is gated off by default.
func TestPlatformCommand_HiddenWhenDisabled(t *testing.T) {
t.Setenv(envPlatformEnabled, "")
rootCmd, _ := BuildRoot()
Expand All @@ -179,9 +184,9 @@ func TestPlatformCommand_HiddenWhenDisabled(t *testing.T) {
}
require.NotEqual(
t,
"pro",
"platform",
use,
"pro command should not be registered when DEVSY_PRO_ENABLED is unset",
"platform command should not be registered when DEVSY_PRO_ENABLED is unset",
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pro/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra"
)

// NewClusterCmd builds the 'devsy pro cluster' parent command for managing
// NewClusterCmd builds the 'devsy platform cluster' parent command for managing
// Platform clusters.
func NewClusterCmd(globalFlags *proflags.GlobalFlags) *cobra.Command {
cmd := &cobra.Command{
Expand Down
36 changes: 18 additions & 18 deletions cmd/pro/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,45 +527,45 @@ binaries:
exec:
proxy:
up: |-
${PRO_PROVIDER} pro provider up
${PRO_PROVIDER} platform provider up
ssh: |-
${PRO_PROVIDER} pro provider ssh
${PRO_PROVIDER} platform provider ssh
stop: |-
${PRO_PROVIDER} pro provider stop
${PRO_PROVIDER} platform provider stop
status: |-
${PRO_PROVIDER} pro provider status
${PRO_PROVIDER} platform provider status
delete: |-
${PRO_PROVIDER} pro provider delete
${PRO_PROVIDER} platform provider delete
health: |-
${PRO_PROVIDER} pro provider health
${PRO_PROVIDER} platform provider health
daemon:
start: |-
${PRO_PROVIDER} pro provider daemon start
${PRO_PROVIDER} platform provider daemon start
status: |-
${PRO_PROVIDER} pro provider daemon status
${PRO_PROVIDER} platform provider daemon status
create:
workspace: |-
${PRO_PROVIDER} pro provider create workspace
${PRO_PROVIDER} platform provider create workspace
get:
workspace: |-
${PRO_PROVIDER} pro provider get workspace
${PRO_PROVIDER} platform provider get workspace
self: |-
${PRO_PROVIDER} pro provider get self
${PRO_PROVIDER} platform provider get self
version: |-
${PRO_PROVIDER} pro provider get version
${PRO_PROVIDER} platform provider get version
update:
workspace: |-
${PRO_PROVIDER} pro provider update workspace
${PRO_PROVIDER} platform provider update workspace
watch:
workspaces: |-
${PRO_PROVIDER} pro provider watch workspaces
${PRO_PROVIDER} platform provider watch workspaces
list:
workspaces: |-
${PRO_PROVIDER} pro provider list workspaces
${PRO_PROVIDER} platform provider list workspaces
projects: |-
${PRO_PROVIDER} pro provider list projects
${PRO_PROVIDER} platform provider list projects
templates: |-
${PRO_PROVIDER} pro provider list templates
${PRO_PROVIDER} platform provider list templates
clusters: |-
${PRO_PROVIDER} pro provider list clusters
${PRO_PROVIDER} platform provider list clusters
`
3 changes: 2 additions & 1 deletion cmd/pro/pro.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import (
func NewPlatformCmd(flags *flags.GlobalFlags) *cobra.Command {
globalFlags := &proflags.GlobalFlags{GlobalFlags: flags}
platformCmd := &cobra.Command{
Use: "pro",
Use: "platform",
Aliases: []string{"pro"},
Short: "Devsy Platform commands",
SilenceUsage: true,
SilenceErrors: true,
Expand Down
43 changes: 43 additions & 0 deletions cmd/pro/pro_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pro

import (
"testing"

"github.com/devsy-org/devsy/cmd/flags"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func newTestRoot(t *testing.T) *cobra.Command {
t.Helper()
root := &cobra.Command{Use: "devsy"}
root.AddCommand(NewPlatformCmd(&flags.GlobalFlags{}))
return root
}

func findCommand(t *testing.T, root *cobra.Command, args ...string) *cobra.Command {
t.Helper()
cmd, _, err := root.Find(args)
require.NoError(t, err)
return cmd
}

func TestPlatformCommand_NameIsPlatform(t *testing.T) {
assert.Equal(t, "platform", NewPlatformCmd(&flags.GlobalFlags{}).Name())
}

func TestPlatformCommand_ProAliasResolvesToSameCommand(t *testing.T) {
root := newTestRoot(t)
platform := findCommand(t, root, "platform")
pro := findCommand(t, root, "pro")
assert.Same(t, platform, pro)
}

func TestPlatformCommand_NestedSubcommandReachableViaBothNames(t *testing.T) {
root := newTestRoot(t)
viaPlatform := findCommand(t, root, "platform", "workspace", "list")
viaPro := findCommand(t, root, "pro", "workspace", "list")
assert.Same(t, viaPlatform, viaPro)
assert.Equal(t, "list", viaPlatform.Name())
}
2 changes: 1 addition & 1 deletion cmd/pro/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra"
)

// NewProjectCmd builds the 'devsy pro project' parent command for managing
// NewProjectCmd builds the 'devsy platform project' parent command for managing
// Platform projects.
func NewProjectCmd(globalFlags *proflags.GlobalFlags) *cobra.Command {
cmd := &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/pro/proutil/proutil.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package proutil contains shared helpers used by the 'devsy pro' command and
// Package proutil contains shared helpers used by the 'devsy platform' command and
// its resource sub-groups (workspace, cluster, project, template). It exists to
// avoid an import cycle between cmd/pro and its child packages.
package proutil
Expand Down
20 changes: 10 additions & 10 deletions cmd/pro/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func (cmd *StartCmd) upgrade(ctx context.Context) error {
return errors.New(
err.Error() + fmt.Sprintf(
"\n\nIf want to purge and reinstall Devsy Platform, run: %s\n",
greenBold("devsy pro start --reset"),
greenBold("devsy platform start --reset"),
),
)
}
Expand Down Expand Up @@ -470,7 +470,7 @@ func (cmd *StartCmd) printRemoteSuccessMessage(host string) {
########################## LOGIN ############################

Username: `+greenBold("admin")+`
Password: `+greenBold(password)+` # Change via UI or via: `+greenBold("devsy pro user reset-password")+`
Password: `+greenBold(password)+` # Change via UI or via: `+greenBold("devsy platform user reset-password")+`

Login via UI: %s
Login via CLI: %s
Expand All @@ -486,7 +486,7 @@ Devsy Platform was successfully installed and can now be reached at: %s
Thanks for using Devsy Platform!
`,
greenBold(url),
greenBold("devsy pro login "+url),
greenBold("devsy platform login "+url),
"https://devsy.sh/docs/administration/ssl",
url)
}
Expand Down Expand Up @@ -550,7 +550,7 @@ func (cmd *StartCmd) successLocal() error {
########################## LOGIN ############################

Username: `+greenBold("admin")+`
Password: `+greenBold(password)+` # Change via UI or via: `+greenBold("devsy pro user reset-password")+`
Password: `+greenBold(password)+` # Change via UI or via: `+greenBold("devsy platform user reset-password")+`

Login via UI: %s
Login via CLI: %s
Expand All @@ -562,7 +562,7 @@ Login via CLI: %s
Devsy Platform was successfully installed.

Thanks for using Devsy Platform!
`, greenBold(url), greenBold("devsy pro login"+" --insecure "+url))
`, greenBold(url), greenBold("devsy platform login"+" --insecure "+url))
blockChan := make(chan bool)
<-blockChan
return nil
Expand Down Expand Up @@ -648,7 +648,7 @@ func (cmd *StartCmd) resolveKubeConfig(
contextToLoad = cmd.Context
} else if cfg.LastInstallContext != "" && cfg.LastInstallContext != contextToLoad {
contextToLoad, err = log.QuestionDefault(&survey.QuestionOptions{
Question: "Seems like you try to use 'devsy pro start' with a different kubernetes context than before. " +
Question: "Seems like you try to use 'devsy platform start' with a different kubernetes context than before. " +
"Choose which kubernetes context you want to use",
DefaultValue: contextToLoad,
Options: []string{contextToLoad, cfg.LastInstallContext},
Expand Down Expand Up @@ -947,7 +947,7 @@ func (cmd *StartCmd) successDevsyRouter(url string) error {
########################## LOGIN ############################

Username: `+greenBold("admin")+`
Password: `+greenBold(password)+` # Change via UI or via: `+greenBold("devsy pro user reset-password")+`
Password: `+greenBold(password)+` # Change via UI or via: `+greenBold("devsy platform user reset-password")+`

Login via UI: %s
Login via CLI: %s
Expand All @@ -959,7 +959,7 @@ Devsy Platform was successfully installed and can now be reached at: %s
Thanks for using Devsy Platform!
`,
greenBold(url),
greenBold("devsy pro login"+" "+url),
greenBold("devsy platform login"+" "+url),
url,
)
return nil
Expand Down Expand Up @@ -1440,14 +1440,14 @@ func isHostReachable(ctx context.Context, host string) (bool, error) {
"error decoding response from %s: %w. Try running '%s --reset'",
url,
err,
"devsy pro start",
"devsy platform start",
)
} else if v.Version == "" {
return false, fmt.Errorf(
"unexpected response from %s: %s. Try running '%s --reset'",
url,
string(out),
"devsy pro start",
"devsy platform start",
)
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/pro/start_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Devsy Platform was successfully installed and can now be reached at: %s
Thanks for using Devsy Platform!
`,
greenBold(url),
greenBold("devsy pro login"+" "+url),
greenBold("devsy platform login"+" "+url),
url,
)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/pro/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra"
)

// NewTemplateCmd builds the 'devsy pro template' parent command for managing
// NewTemplateCmd builds the 'devsy platform template' parent command for managing
// Platform templates.
func NewTemplateCmd(globalFlags *proflags.GlobalFlags) *cobra.Command {
cmd := &cobra.Command{
Expand Down
4 changes: 2 additions & 2 deletions cmd/pro/user/reset_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func NewResetPasswordCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
Resets the password of a user.

Example:
devsy pro user reset-password
devsy pro user reset-password --user admin
devsy platform user reset-password
devsy platform user reset-password --user admin
#######################################################
`
c := &cobra.Command{
Expand Down
2 changes: 1 addition & 1 deletion cmd/pro/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra"
)

// NewUserCmd builds the 'devsy pro user' parent command for managing Platform users.
// NewUserCmd builds the 'devsy platform user' parent command for managing Platform users.
func NewUserCmd(globalFlags *proflags.GlobalFlags) *cobra.Command {
cmd := &cobra.Command{
Use: "user",
Expand Down
2 changes: 1 addition & 1 deletion cmd/pro/workspace/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func NewImportCmd(globalFlags *proflags.GlobalFlags) *cobra.Command {

func (cmd *ImportCmd) Run(ctx context.Context, args []string) error {
if len(args) != 1 {
return fmt.Errorf("usage: devsy pro workspace import <devsy-pro-host>")
return fmt.Errorf("usage: devsy platform workspace import <devsy-platform-host>")
}

platformHost := args[0]
Expand Down
2 changes: 1 addition & 1 deletion cmd/pro/workspace/sleep.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func NewSleepCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
names.PreventWakeup,
-1,
"The amount of seconds this workspace should sleep until it can be woken up again (use 0 for infinite sleeping). "+
"During this time the space can only be woken up by `devsy pro workspace wakeup`, "+
"During this time the space can only be woken up by `devsy platform workspace wakeup`, "+
"manually deleting the annotation on the namespace or through the UI",
),
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/pro/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/spf13/cobra"
)

// NewWorkspaceCmd builds the 'devsy pro workspace' parent command for managing
// NewWorkspaceCmd builds the 'devsy platform workspace' parent command for managing
// Platform workspaces.
func NewWorkspaceCmd(globalFlags *proflags.GlobalFlags) *cobra.Command {
cmd := &cobra.Command{
Expand Down
Loading
Loading