Skip to content

Commit

Permalink
Included update Org functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed Sep 28, 2023
1 parent ac2723b commit fe9078e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 9 deletions.
9 changes: 5 additions & 4 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ var getToken = &cobra.Command{
},
}

// TODO - update once the API is updated
var getOrganizationCmd = &cobra.Command{
Use: "organization",
Aliases: []string{"o"},
Expand All @@ -181,7 +182,7 @@ var getOrganizationCmd = &cobra.Command{
if err != nil {
return err
}
organizationID, err := cmd.Flags().GetInt("org")
organizationID, err := cmd.Flags().GetUint("id")
if err != nil {
return err
}
Expand All @@ -199,14 +200,14 @@ var getOrganizationCmd = &cobra.Command{
organization, err := l.GetOrganizationByID(context.TODO(), organizationID, lc)
handleError(err)

if organization == nil {
if organization.Name == "" {
output.RenderInfo(fmt.Sprintf("No organization found for ID '%d'", organizationID), outputOptions)
os.Exit(0)
}

data := []output.Data{}
data = append(data, []string{
strconv.Itoa(organizationID),
strconv.Itoa(int(organizationID)),
organization.Name,
organization.Description,
strconv.Itoa(int(organization.QuotaProject)),
Expand Down Expand Up @@ -238,5 +239,5 @@ func init() {
getTaskByID.Flags().BoolP("logs", "L", false, "Show the task logs if available")
getProjectKeyCmd.Flags().BoolVarP(&revealValue, "reveal", "", false, "Reveal the variable values")
getDeploymentCmd.Flags().StringVarP(&remoteID, "remoteid", "R", "", "The remote ID of the deployment")
getOrganizationCmd.Flags().Int("org", 0, "ID of the organization")
getOrganizationCmd.Flags().Uint("id", 0, "ID of the organization")
}
59 changes: 57 additions & 2 deletions cmd/organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var deleteOrganizationCmd = &cobra.Command{
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
organizationId, err := cmd.Flags().GetInt("id")
organizationId, err := cmd.Flags().GetUint("id")
if err != nil {
return err
}
Expand Down Expand Up @@ -101,7 +101,62 @@ var deleteOrganizationCmd = &cobra.Command{
},
}

// TODO - update once the API is updated
var updateOrganizationCmd = &cobra.Command{
Use: "organization",
Aliases: []string{"o"},
Short: "Update an organization",
PreRunE: func(_ *cobra.Command, _ []string) error {
return validateTokenE(lagoonCLIConfig.Current)
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
return err
}
organizationId, err := cmd.Flags().GetUint("id")
if err != nil {
return err
}
description, err := cmd.Flags().GetString("description")
if err != nil {
return err
}

if organizationId == 0 {
fmt.Println("Missing arguments: Organization ID is not defined")
cmd.Help()
os.Exit(1)
}

current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
&token,
debug)

organizationFlags := s.UpdateOrganizationPatchInput{
Description: description,
}
result, err := l.UpdateOrganization(context.TODO(), organizationId, organizationFlags, lc)
handleError(err)

resultData := output.Result{
Result: "success",
ResultData: map[string]interface{}{
"Organization Name": result.Name,
},
}
output.RenderResult(resultData, outputOptions)
return nil
},
}

func init() {
updateOrganizationCmd.Flags().Uint("id", 0, "ID of the organization to update")
updateOrganizationCmd.Flags().StringP("description", "d", "", "Description of the organization")
addOrganizationCmd.Flags().String("name", "", "Name of the organization")
deleteOrganizationCmd.Flags().Int("id", 0, "ID of the organization")
deleteOrganizationCmd.Flags().Uint("id", 0, "ID of the organization")
}
1 change: 1 addition & 0 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ func init() {
updateCmd.AddCommand(updateUserCmd)
updateCmd.AddCommand(updateDeployTargetConfigCmd)
updateCmd.AddCommand(updateDeployTargetCmd)
updateCmd.AddCommand(updateOrganizationCmd)
}
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/guregu/null v4.0.0+incompatible
// workaround for https://github.com/manifoldco/promptui/issues/98
github.com/nicksnyder/go-i18n v1.10.1 // indirect
github.com/uselagoon/machinery v0.0.11
github.com/uselagoon/machinery v0.0.12-0.20230928085239-eaa5a60c02b6
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780 // indirect
Expand All @@ -39,6 +39,6 @@ require (
// use this version for fixes to formatting of end header
replace github.com/olekukonko/tablewriter => github.com/shreddedbacon/tablewriter v0.0.2-0.20200114082015-d810c4a558bf

// replace github.com/machinebox/graphql => ../../shreddedbacon/graphql
//replace github.com/uselagoon/machinery => ../machinery

// replace github.com/olekukonko/tablewriter => ../../shreddedbacon/tablewriter
// replace github.com/olekukonko/tablewriter => ../../shreddedbacon/tablewriter

0 comments on commit fe9078e

Please sign in to comment.