Skip to content

Commit

Permalink
Add project to org
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed Oct 6, 2023
1 parent 8b836cb commit da89300
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func init() {
addCmd.AddCommand(addProjectToGroupCmd)
addCmd.AddCommand(addNotificationCmd)
addCmd.AddCommand(addUserCmd)
addCmd.AddCommand(addProjectToOrganizationCmd)
addCmd.AddCommand(addOrganizationCmd)
addCmd.AddCommand(addUserToGroupCmd)
addCmd.AddCommand(addUserSSHKeyCmd)
Expand Down
41 changes: 41 additions & 0 deletions cmd/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,45 @@ var deleteGroupCmd = &cobra.Command{
},
}

// TODO
//var addGroupToOrganizationCmd = &cobra.Command{
// Use: "organization-group",
// Aliases: []string{"og", "orggroup"},
// Short: "Add a new project to Lagoon",
// 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)
// 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)
//
// 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 +277,6 @@ 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")
}
66 changes: 66 additions & 0 deletions cmd/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ 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"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -364,6 +367,67 @@ var deleteProjectMetadataByKey = &cobra.Command{
},
}

var addProjectToOrganizationCmd = &cobra.Command{
Use: "organization-project",
Aliases: []string{"op", "orgproject"},
Short: "Add a new project to Lagoon",
PreRunE: func(_ *cobra.Command, _ []string) error {
return validateTokenE(lagoonCLIConfig.Current)
},
RunE: func(cmd *cobra.Command, args []string) error {
debug, err := cmd.Flags().GetBool("debug")
organizationName, err := cmd.Flags().GetString("organization")
if organizationName == "" {
fmt.Println("Missing arguments: Organization name is not defined")
cmd.Help()
os.Exit(1)
}

if cmdProjectName == "" {
fmt.Println("Missing arguments: Project 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)
project, err := l.GetMinimalProjectByName(context.TODO(), cmdProjectName, lc)
handleError(err)

if project.Organization == organization.ID {

Check failure on line 405 in cmd/project.go

View workflow job for this annotation

GitHub Actions / test-suite (1.16)

project.Organization undefined (type *"github.com/uselagoon/machinery/api/schema".Project has no field or method Organization)

Check failure on line 405 in cmd/project.go

View workflow job for this annotation

GitHub Actions / test-suite (1.16)

project.Organization undefined (type *"github.com/uselagoon/machinery/api/schema".Project has no field or method Organization)
fmt.Printf("Project %s is already assigned to organization %s\n\n", project.Name, organization.Name)
cmd.Help()
os.Exit(1)
}

projectInput := s.AddProjectToOrganizationInput{

Check failure on line 411 in cmd/project.go

View workflow job for this annotation

GitHub Actions / test-suite (1.16)

undefined: "github.com/uselagoon/machinery/api/schema".AddProjectToOrganizationInput

Check failure on line 411 in cmd/project.go

View workflow job for this annotation

GitHub Actions / test-suite (1.16)

undefined: "github.com/uselagoon/machinery/api/schema".AddProjectToOrganizationInput
Project: project.ID,
Organization: organization.ID,
}
prj := s.Project{}
err = lc.AddProjectToOrganization(context.TODO(), &projectInput, &prj)

Check failure on line 416 in cmd/project.go

View workflow job for this annotation

GitHub Actions / test-suite (1.16)

lc.AddProjectToOrganization undefined (type *"github.com/uselagoon/machinery/api/lagoon/client".Client has no field or method AddProjectToOrganization)

Check failure on line 416 in cmd/project.go

View workflow job for this annotation

GitHub Actions / test-suite (1.16)

lc.AddProjectToOrganization undefined (type *"github.com/uselagoon/machinery/api/lagoon/client".Client has no field or method AddProjectToOrganization)
handleError(err)

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

func init() {
updateProjectCmd.Flags().StringVarP(&jsonPatch, "json", "j", "", "JSON string to patch")

Expand Down Expand Up @@ -405,6 +469,8 @@ func init() {
addProjectCmd.Flags().IntVarP(&projectDevelopmentEnvironmentsLimit, "developmentEnvironmentsLimit", "L", 0, "How many environments can be deployed at one time")
addProjectCmd.Flags().IntVarP(&projectOpenshift, "openshift", "S", 0, "Reference to OpenShift Object this Project should be deployed to")

addProjectToOrganizationCmd.Flags().StringP("organization", "O", "", "The Organization to add the project to")

listCmd.AddCommand(listProjectByMetadata)
listProjectByMetadata.Flags().StringP("key", "K", "", "The key name of the metadata value you are querying on")
listProjectByMetadata.Flags().StringP("value", "V", "", "The value for the key you are querying on")
Expand Down

0 comments on commit da89300

Please sign in to comment.