Skip to content

Commit

Permalink
Merge pull request #183 from amazeeio/current-fix
Browse files Browse the repository at this point in the history
make sure the cli correctly knows which lagoon to use
  • Loading branch information
shreddedbacon authored Mar 19, 2021
2 parents a2464e6 + 5d7055b commit dacaf11
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ var configLagoonVersionCmd = &cobra.Command{
Aliases: []string{"l"},
Short: "Checks the current Lagoon for its version and sets it in the config file",
PreRunE: func(_ *cobra.Command, _ []string) error {
return validateTokenE(cmdLagoon)
return validateTokenE(lagoonCLIConfig.Current)
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
Expand Down
8 changes: 4 additions & 4 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func loginToken() error {
defer closeSSHAgent()

sshHost := fmt.Sprintf("%s:%s",
lagoonCLIConfig.Lagoons[cmdLagoon].HostName,
lagoonCLIConfig.Lagoons[cmdLagoon].Port)
lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current].HostName,
lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current].Port)
conn, err := ssh.Dial("tcp", sshHost, config)
if err != nil {
return fmt.Errorf("couldn't connect to %s: %v", sshHost, err)
Expand All @@ -100,9 +100,9 @@ func loginToken() error {
return fmt.Errorf("couldn't get token: %v", err)
}

lc := lagoonCLIConfig.Lagoons[cmdLagoon]
lc := lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current]
lc.Token = strings.TrimSpace(string(out))
lagoonCLIConfig.Lagoons[cmdLagoon] = lc
lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current] = lc
if err = writeLagoonConfig(&lagoonCLIConfig, filepath.Join(configFilePath, configName+configExtension)); err != nil {
return fmt.Errorf("couldn't write config: %v", err)
}
Expand Down
7 changes: 4 additions & 3 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func initConfig() {
output.RenderError(err.Error(), outputOptions)
os.Exit(1)
}
err = getLagoonContext(&cmdLagoon, rootCmd)
err = getLagoonContext(&lagoonCLIConfig, &cmdLagoon, rootCmd)
if err != nil {
output.RenderError(err.Error(), outputOptions)
os.Exit(1)
Expand Down Expand Up @@ -439,8 +439,7 @@ func getLagoonConfigFile(configPath *string, configName *string, configExtension
return nil
}

func getLagoonContext(lagoon *string, cmd *cobra.Command) error {
lagoonCLIConfig.Current = strings.TrimSpace(string(cmdLagoon))
func getLagoonContext(lagoonCLIConfig *lagoon.Config, lagoon *string, cmd *cobra.Command) error {
// check if we have an envvar or flag to define our lagoon context
var lagoonContext string
lagoonContext, err := cmd.Flags().GetString("lagoon")
Expand All @@ -461,5 +460,7 @@ func getLagoonContext(lagoon *string, cmd *cobra.Command) error {
*lagoon = lagoonCLIConfig.Default
}
}
// set the Current lagoon to the one we've determined it needs to be
lagoonCLIConfig.Current = strings.TrimSpace(*lagoon)
return nil
}
4 changes: 2 additions & 2 deletions cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ var sshEnvCmd = &cobra.Command{
os.Exit(1)
}
sshConfig := map[string]string{
"hostname": lagoonCLIConfig.Lagoons[cmdLagoon].HostName,
"port": lagoonCLIConfig.Lagoons[cmdLagoon].Port,
"hostname": lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current].HostName,
"port": lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current].Port,
"username": cmdProjectName + "-" + cmdProjectEnvironment,
}
if sshConnString {
Expand Down
8 changes: 4 additions & 4 deletions cmd/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ var webCmd = &cobra.Command{
}

urlBuilder := strings.Builder{}
urlBuilder.WriteString(lagoonCLIConfig.Lagoons[cmdLagoon].UI)
if lagoonCLIConfig.Lagoons[cmdLagoon].UI != "" {
urlBuilder.WriteString(lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current].UI)
if lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current].UI != "" {
urlBuilder.WriteString(fmt.Sprintf("/projects/%s", cmdProjectName))
} else {
output.RenderError("unable to determine url for ui, is one set?", outputOptions)
Expand All @@ -42,8 +42,8 @@ var kibanaCmd = &cobra.Command{
Short: "Launch the kibana interface",
Run: func(cmd *cobra.Command, args []string) {
urlBuilder := strings.Builder{}
urlBuilder.WriteString(lagoonCLIConfig.Lagoons[cmdLagoon].Kibana)
if lagoonCLIConfig.Lagoons[cmdLagoon].Kibana == "" {
urlBuilder.WriteString(lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current].Kibana)
if lagoonCLIConfig.Lagoons[lagoonCLIConfig.Current].Kibana == "" {
output.RenderError("unable to determine url for kibana, is one set?", outputOptions)
os.Exit(1)
}
Expand Down

0 comments on commit dacaf11

Please sign in to comment.