Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Organizations support #292

Merged
merged 24 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6b16ca3
Initial commit
CGoodwin90 Sep 26, 2023
ccb628f
Add Org cmd
CGoodwin90 Sep 27, 2023
a77b506
Delete organization functionality
CGoodwin90 Sep 28, 2023
ac2723b
Fixed duplicate cmd
CGoodwin90 Sep 28, 2023
fe9078e
Included update Org functionality
CGoodwin90 Sep 28, 2023
4fac406
Extends add & update cmd
CGoodwin90 Oct 3, 2023
8b836cb
List cmd for groups & projects by org id
CGoodwin90 Oct 4, 2023
da89300
Add project to org
CGoodwin90 Oct 6, 2023
d8464e3
Pointing to correct machinery version
CGoodwin90 Oct 9, 2023
994ac3a
Updated group organization cmd
CGoodwin90 Oct 11, 2023
bbb3db5
Included deploy targets & users cmds
CGoodwin90 Oct 13, 2023
d31a6fb
cmd & flag cleanup
CGoodwin90 Oct 16, 2023
2a6d686
Moved org list commands to sub commands
CGoodwin90 Oct 18, 2023
bb8acfe
Introduced addProjectToOrganization & updated add organizations to us…
CGoodwin90 Oct 19, 2023
3a55ad3
add & remove deploytarget
CGoodwin90 Oct 20, 2023
55fdf00
RemoveUserCmd & implement shared function
CGoodwin90 Oct 20, 2023
86e5fb4
Updated add project cmd + various fixes
CGoodwin90 Oct 23, 2023
bbb125b
Updated to account for negative quota
CGoodwin90 Oct 23, 2023
32d3884
Updated listOrganizationDeployTargetsCmd & included listOrganizationsCmd
CGoodwin90 Nov 28, 2023
3d8bd61
Updated to machinery v0.0.13
CGoodwin90 Nov 28, 2023
e0318db
Resolved test err
CGoodwin90 Nov 28, 2023
58a2fdd
Merge branch 'main' into feature/organizations
CGoodwin90 Nov 28, 2023
b692d1d
Merged main & generated docs
CGoodwin90 Dec 5, 2023
1d6fdc9
Merge branch 'feature/organizations' of https://github.com/uselagoon/…
CGoodwin90 Dec 5, 2023
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
2 changes: 2 additions & 0 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func init() {
addCmd.AddCommand(addProjectToGroupCmd)
addCmd.AddCommand(addNotificationCmd)
addCmd.AddCommand(addUserCmd)
addCmd.AddCommand(addGroupToOrganizationCmd)
addCmd.AddCommand(addOrganizationCmd)
addCmd.AddCommand(addUserToGroupCmd)
addCmd.AddCommand(addUserSSHKeyCmd)
addCmd.AddCommand(addVariableCmd)
Expand Down
1 change: 1 addition & 0 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ func init() {
deleteCmd.AddCommand(deleteUserFromGroupCmd)
deleteCmd.AddCommand(deleteVariableCmd)
deleteCmd.AddCommand(deleteDeployTargetConfigCmd)
deleteCmd.AddCommand(deleteOrganizationCmd)
}
16 changes: 1 addition & 15 deletions cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ var updateEnvironmentCmd = &cobra.Command{
Route: nullStrCheck(route),
Routes: nullStrCheck(routes),
DeployTitle: nullStrCheck(deployTitle),
Openshift: nullIntCheck(openShift),
Openshift: nullUintCheck(openShift),
}
if environmentAutoIdleProvided {
environmentFlags.AutoIdle = &environmentAutoIdle
Expand Down Expand Up @@ -158,20 +158,6 @@ var updateEnvironmentCmd = &cobra.Command{
},
}

func nullStrCheck(s string) *string {
if s == "" {
return nil
}
return &s
}

func nullIntCheck(i uint) *uint {
if i == 0 {
return nil
}
return &i
}

func checkFlags(f *pflag.Flag) {
if f.Name == "auto-idle" {
environmentAutoIdleProvided = true
Expand Down
64 changes: 62 additions & 2 deletions cmd/get.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package cmd

import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/uselagoon/lagoon-cli/pkg/api"
"github.com/uselagoon/lagoon-cli/pkg/output"
l "github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
"os"
"strconv"
)

// GetFlags .
Expand Down Expand Up @@ -166,10 +169,66 @@ var getToken = &cobra.Command{
},
}

var getOrganizationCmd = &cobra.Command{
Use: "organization",
Aliases: []string{"o"},
Short: "Get details about an organization",
PreRunE: func(_ *cobra.Command, _ []string) error {
return validateTokenE(cmdLagoon)
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
if err != nil {
return err
}
organizationName, err := cmd.Flags().GetString("name")
if err != nil {
return err
}
if organizationName == "" {
return fmt.Errorf("missing arguments: Organization is not defined")
}

current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
&token,
debug)
organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
handleError(err)

if organization.Name == "" {
output.RenderInfo(fmt.Sprintf("No organization found for '%s'", organizationName), outputOptions)
os.Exit(0)
CGoodwin90 marked this conversation as resolved.
Show resolved Hide resolved
}

data := []output.Data{}
data = append(data, []string{
strconv.Itoa(int(organization.ID)),
organization.Name,
organization.Description,
strconv.Itoa(int(organization.QuotaProject)),
strconv.Itoa(int(organization.QuotaGroup)),
strconv.Itoa(int(organization.QuotaNotification)),
})

dataMain := output.Table{
Header: []string{"ID", "Name", "Description", "quotaProject", "quotaGroup", "quotaNotification"},
Data: data,
}

output.RenderOutput(dataMain, outputOptions)
return nil
},
}

func init() {
getCmd.AddCommand(getAllUserKeysCmd)
getCmd.AddCommand(getDeploymentCmd)
getCmd.AddCommand(getEnvironmentCmd)
getCmd.AddCommand(getOrganizationCmd)
getCmd.AddCommand(getProjectCmd)
getCmd.AddCommand(getProjectKeyCmd)
getCmd.AddCommand(getUserKeysCmd)
Expand All @@ -179,4 +238,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().StringP("organization", "O", "", "Name of the organization")
}
63 changes: 63 additions & 0 deletions cmd/groups.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package cmd

import (
"context"
"encoding/json"
"fmt"
l "github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
s "github.com/uselagoon/machinery/api/schema"
"os"
"strings"

Expand Down Expand Up @@ -228,6 +232,62 @@ var deleteGroupCmd = &cobra.Command{
},
}

var addGroupToOrganizationCmd = &cobra.Command{
Use: "organization-group",
Aliases: []string{"og", "orggroup"},
Short: "Add a group to 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")
handleError(err)
orgOwner, err := cmd.Flags().GetBool("orgOwner")
organizationName, err := cmd.Flags().GetString("organization")
if organizationName == "" {
fmt.Println("Missing arguments: Organization name is not defined")
cmd.Help()
os.Exit(1)
}
groupName, err := cmd.Flags().GetString("group")
if groupName == "" {
fmt.Println("Missing arguments: Group name 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)

organization, err := l.GetOrganizationByName(context.TODO(), organizationName, lc)
handleError(err)

groupInput := s.AddGroupToOrganizationInput{
Name: groupName,
Organization: organization.ID,
AddOrgOwner: orgOwner,
}
group := s.OrgGroup{}
err = lc.AddGroupToOrganization(context.TODO(), &groupInput, &group)
handleError(err)

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

func init() {
addGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group")
addUserToGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group")
Expand All @@ -238,4 +298,7 @@ func init() {
deleteUserFromGroupCmd.Flags().StringVarP(&userEmail, "email", "E", "", "Email address of the user")
deleteProjectFromGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group")
deleteGroupCmd.Flags().StringVarP(&groupName, "name", "N", "", "Name of the group")
addGroupToOrganizationCmd.Flags().StringP("organization", "O", "", "Name of the organization")
addGroupToOrganizationCmd.Flags().StringP("group", "G", "", "Name of the group")
addGroupToOrganizationCmd.Flags().Bool("orgOwner", false, "Flag to add the user to the group as an owner")
}
Loading
Loading