-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: support add, list, update, and delete of deploytargets (kube…
…rnetes/openshift) (#224) * introducing add and delete openshift cmds, but also bumping to go 1.18 * refactor: add list and update, rename to deploytarget * chore: minor fixes * chore: minor fixes * chore: add created date * chore: minor formatting changes * chore: update docs * chore: bump go versions everywhere else * chore: revert go to 1.16 (mockgen doesnt support 1.18 yet it seems) Co-authored-by: shreddedbacon <[email protected]>
- Loading branch information
1 parent
2282da0
commit c3adc9d
Showing
27 changed files
with
909 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ jobs: | |
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.13 | ||
go-version: 1.16 | ||
- name: Build CLI | ||
run: | | ||
go get github.com/golang/mock/[email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,327 @@ | ||
package cmd | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/uselagoon/lagoon-cli/internal/lagoon" | ||
"github.com/uselagoon/lagoon-cli/internal/lagoon/client" | ||
"github.com/uselagoon/lagoon-cli/internal/schema" | ||
"github.com/uselagoon/lagoon-cli/pkg/output" | ||
) | ||
|
||
var addDeployTargetCmd = &cobra.Command{ | ||
Use: "deploytarget", | ||
Aliases: []string{"dt"}, | ||
Short: "Add a DeployTarget to lagoon", | ||
Long: "Add a DeployTarget (kubernetes or openshift) to lagoon, this requires admin level permissions", | ||
PreRunE: func(_ *cobra.Command, _ []string) error { | ||
return validateTokenE(cmdLagoon) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
name, err := cmd.Flags().GetString("name") | ||
if err != nil { | ||
return err | ||
} | ||
token, err := cmd.Flags().GetString("token") | ||
if err != nil { | ||
return err | ||
} | ||
consoleURL, err := cmd.Flags().GetString("console-url") | ||
if err != nil { | ||
return err | ||
} | ||
routerPattern, err := cmd.Flags().GetString("router-pattern") | ||
if err != nil { | ||
return err | ||
} | ||
sshHost, err := cmd.Flags().GetString("ssh-host") | ||
if err != nil { | ||
return err | ||
} | ||
sshPort, err := cmd.Flags().GetString("ssh-port") | ||
if err != nil { | ||
return err | ||
} | ||
friendlyName, err := cmd.Flags().GetString("friendly-name") | ||
if err != nil { | ||
return err | ||
} | ||
cloudProvider, err := cmd.Flags().GetString("cloud-provider") | ||
if err != nil { | ||
return err | ||
} | ||
cloudRegion, err := cmd.Flags().GetString("cloud-region") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if name == "" { | ||
return fmt.Errorf("Missing arguments: name is not defined") | ||
} | ||
if token == "" { | ||
return fmt.Errorf("Missing arguments: token is not defined") | ||
} | ||
if consoleURL == "" { | ||
return fmt.Errorf("Missing arguments: console-url is not defined") | ||
} | ||
|
||
addDeployTarget := &schema.AddDeployTargetInput{ | ||
Name: name, | ||
FriendlyName: friendlyName, | ||
CloudProvider: cloudProvider, | ||
CloudRegion: cloudRegion, | ||
Token: token, | ||
RouterPattern: routerPattern, | ||
ConsoleURL: consoleURL, | ||
SSHHost: sshHost, | ||
SSHPort: sshPort, | ||
} | ||
id, err := cmd.Flags().GetUint("id") | ||
if err != nil { | ||
return err | ||
} | ||
if id != 0 { | ||
addDeployTarget.ID = id | ||
} | ||
debug, err := cmd.Flags().GetBool("debug") | ||
if err != nil { | ||
handleError(err) | ||
} | ||
current := lagoonCLIConfig.Current | ||
lc := client.New( | ||
lagoonCLIConfig.Lagoons[current].GraphQL, | ||
lagoonCLIConfig.Lagoons[current].Token, | ||
lagoonCLIConfig.Lagoons[current].Version, | ||
lagoonCLIVersion, | ||
debug) | ||
|
||
if yesNo(fmt.Sprintf("You are attempting to add '%s' DeployTarget, are you sure?", addDeployTarget.Name)) { | ||
addDeployTargetResponse, err := lagoon.AddDeployTarget(context.TODO(), addDeployTarget, lc) | ||
if err != nil { | ||
handleError(err) | ||
} | ||
|
||
data := []output.Data{} | ||
data = append(data, []string{ | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.ID)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.Name)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.ConsoleURL)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.Token)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.SSHHost)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.SSHPort)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.CloudRegion)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.CloudProvider)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.FriendlyName)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.RouterPattern)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.Created)), | ||
returnNonEmptyString(fmt.Sprintf("%v", addDeployTargetResponse.MonitoringConfig)), | ||
}) | ||
output.RenderOutput(output.Table{ | ||
Header: []string{ | ||
"ID", | ||
"Name", | ||
"ConsoleUrl", | ||
"Token", | ||
"SshHost", | ||
"SshPort", | ||
"CloudRegion", | ||
"CloudProvider", | ||
"FriendlyName", | ||
"RouterPattern", | ||
"Created", | ||
"MonitoringConfig", | ||
}, | ||
Data: data, | ||
}, outputOptions) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
var updateDeployTargetCmd = &cobra.Command{ | ||
Use: "deploytarget", | ||
Aliases: []string{"dt"}, | ||
Short: "Update a DeployTarget in lagoon", | ||
Long: "Update a DeployTarget (kubernetes or openshift) in lagoon, this requires admin level permissions", | ||
PreRunE: func(_ *cobra.Command, _ []string) error { | ||
return validateTokenE(cmdLagoon) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
id, err := cmd.Flags().GetUint("id") | ||
if err != nil { | ||
return err | ||
} | ||
token, err := cmd.Flags().GetString("token") | ||
if err != nil { | ||
return err | ||
} | ||
consoleURL, err := cmd.Flags().GetString("console-url") | ||
if err != nil { | ||
return err | ||
} | ||
routerPattern, err := cmd.Flags().GetString("router-pattern") | ||
if err != nil { | ||
return err | ||
} | ||
sshHost, err := cmd.Flags().GetString("ssh-host") | ||
if err != nil { | ||
return err | ||
} | ||
sshPort, err := cmd.Flags().GetString("ssh-port") | ||
if err != nil { | ||
return err | ||
} | ||
friendlyName, err := cmd.Flags().GetString("friendly-name") | ||
if err != nil { | ||
return err | ||
} | ||
cloudProvider, err := cmd.Flags().GetString("cloud-provider") | ||
if err != nil { | ||
return err | ||
} | ||
cloudRegion, err := cmd.Flags().GetString("cloud-region") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
debug, err := cmd.Flags().GetBool("debug") | ||
if err != nil { | ||
handleError(err) | ||
} | ||
current := lagoonCLIConfig.Current | ||
lc := client.New( | ||
lagoonCLIConfig.Lagoons[current].GraphQL, | ||
lagoonCLIConfig.Lagoons[current].Token, | ||
lagoonCLIConfig.Lagoons[current].Version, | ||
lagoonCLIVersion, | ||
debug, | ||
) | ||
updateDeployTarget := &schema.UpdateDeployTargetInput{ | ||
AddDeployTargetInput: schema.AddDeployTargetInput{ | ||
ID: id, | ||
Token: token, | ||
FriendlyName: friendlyName, | ||
CloudProvider: cloudProvider, | ||
CloudRegion: cloudRegion, | ||
RouterPattern: routerPattern, | ||
ConsoleURL: consoleURL, | ||
SSHHost: sshHost, | ||
SSHPort: sshPort, | ||
}, | ||
} | ||
if yesNo(fmt.Sprintf("You are attempting to update '%d' DeployTarget, are you sure?", updateDeployTarget.ID)) { | ||
updateDeployTargetResponse, err := lagoon.UpdateDeployTarget(context.TODO(), updateDeployTarget, lc) | ||
if err != nil { | ||
handleError(err) | ||
} | ||
|
||
data := []output.Data{} | ||
data = append(data, []string{ | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.ID)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.Name)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.ConsoleURL)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.Token)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.SSHHost)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.SSHPort)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.CloudRegion)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.CloudProvider)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.FriendlyName)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.RouterPattern)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.Created)), | ||
returnNonEmptyString(fmt.Sprintf("%v", updateDeployTargetResponse.MonitoringConfig)), | ||
}) | ||
output.RenderOutput(output.Table{ | ||
Header: []string{ | ||
"ID", | ||
"Name", | ||
"ConsoleUrl", | ||
"Token", | ||
"SshHost", | ||
"SshPort", | ||
"CloudRegion", | ||
"CloudProvider", | ||
"FriendlyName", | ||
"RouterPattern", | ||
"Created", | ||
"MonitoringConfig", | ||
}, | ||
Data: data, | ||
}, outputOptions) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
var deleteDeployTargetCmd = &cobra.Command{ | ||
Use: "deploytarget", | ||
Aliases: []string{"dt"}, | ||
Short: "Delete a DeployTarget from lagoon", | ||
Long: "Delete a DeployTarget (kubernetes or openshift) from lagoon, this requires admin level permissions", | ||
PreRunE: func(_ *cobra.Command, _ []string) error { | ||
return validateTokenE(cmdLagoon) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
name, err := cmd.Flags().GetString("name") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
debug, err := cmd.Flags().GetBool("debug") | ||
if err != nil { | ||
handleError(err) | ||
} | ||
current := lagoonCLIConfig.Current | ||
lc := client.New( | ||
lagoonCLIConfig.Lagoons[current].GraphQL, | ||
lagoonCLIConfig.Lagoons[current].Token, | ||
lagoonCLIConfig.Lagoons[current].Version, | ||
lagoonCLIVersion, | ||
debug, | ||
) | ||
|
||
deleteDeployTarget := &schema.DeleteDeployTargetInput{ | ||
Name: name, | ||
} | ||
if yesNo(fmt.Sprintf("You are attempting to delete DeployTarget '%s', are you sure?", deleteDeployTarget.Name)) { | ||
deleteDeployTargetResponse, err := lagoon.DeleteDeployTarget(context.TODO(), deleteDeployTarget, lc) | ||
if err != nil { | ||
handleError(err) | ||
} | ||
|
||
handleError(err) | ||
resultData := output.Result{ | ||
Result: deleteDeployTargetResponse.DeleteDeployTarget, | ||
} | ||
output.RenderResult(resultData, outputOptions) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
addDeployTargetCmd.Flags().UintP("id", "", 0, "ID of the DeployTarget") | ||
addDeployTargetCmd.Flags().StringP("name", "", "", "Name of DeployTarget") | ||
addDeployTargetCmd.Flags().StringP("console-url", "", "", "DeployTarget console URL") | ||
addDeployTargetCmd.Flags().StringP("token", "", "", "DeployTarget token") | ||
addDeployTargetCmd.Flags().StringP("router-pattern", "", "", "DeployTarget router-pattern") | ||
addDeployTargetCmd.Flags().StringP("friendly-name", "", "", "DeployTarget friendly name") | ||
addDeployTargetCmd.Flags().StringP("cloud-provider", "", "", "DeployTarget cloud provider") | ||
addDeployTargetCmd.Flags().StringP("cloud-region", "", "", "DeployTarget cloud region") | ||
addDeployTargetCmd.Flags().StringP("ssh-host", "", "", "DeployTarget ssh host") | ||
addDeployTargetCmd.Flags().StringP("ssh-port", "", "", "DeployTarget ssh port") | ||
|
||
deleteDeployTargetCmd.Flags().UintP("id", "", 0, "ID of the DeployTarget") | ||
deleteDeployTargetCmd.Flags().StringP("name", "", "", "Name of DeployTarget") | ||
|
||
updateDeployTargetCmd.Flags().UintP("id", "", 0, "ID of the DeployTarget") | ||
updateDeployTargetCmd.Flags().StringP("console-url", "", "", "DeployTarget console URL") | ||
updateDeployTargetCmd.Flags().StringP("token", "", "", "DeployTarget token") | ||
updateDeployTargetCmd.Flags().StringP("router-pattern", "", "", "DeployTarget router-pattern") | ||
updateDeployTargetCmd.Flags().StringP("friendly-name", "", "", "DeployTarget friendly name") | ||
updateDeployTargetCmd.Flags().StringP("cloud-provider", "", "", "DeployTarget cloud provider") | ||
updateDeployTargetCmd.Flags().StringP("cloud-region", "", "", "DeployTarget cloud region") | ||
updateDeployTargetCmd.Flags().StringP("ssh-host", "", "", "DeployTarget ssh host") | ||
updateDeployTargetCmd.Flags().StringP("ssh-port", "", "", "DeployTarget ssh port") | ||
} |
Oops, something went wrong.