Skip to content

Commit

Permalink
Merge branch 'main' into fix-user-sshkey
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 authored Dec 5, 2023
2 parents b2ebedd + fb8a37a commit 8ee5f4a
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 20 deletions.
90 changes: 71 additions & 19 deletions cmd/get.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
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"
"os"
"strconv"

l "github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"
)

// GetFlags .
Expand Down Expand Up @@ -44,30 +48,78 @@ var getProjectCmd = &cobra.Command{
Use: "project",
Aliases: []string{"p"},
Short: "Get details about a project",
Run: func(cmd *cobra.Command, args []string) {
getProjectFlags := parseGetFlags(*cmd.Flags())
if getProjectFlags.Project == "" {
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
}
if cmdProjectName == "" {
fmt.Println("Missing arguments: Project name is not defined")
cmd.Help()
os.Exit(1)
return nil
}
returnedJSON, err := pClient.GetProjectInfo(getProjectFlags.Project)
current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
&token,
debug)

project, err := l.GetProjectByName(context.TODO(), cmdProjectName, lc)
if err != nil {
output.RenderError(err.Error(), outputOptions)
os.Exit(1)
return err
}
var dataMain output.Table
err = json.Unmarshal([]byte(returnedJSON), &dataMain)
if err != nil {
output.RenderError(err.Error(), outputOptions)
os.Exit(1)

if project == nil {
output.RenderInfo(fmt.Sprintf("No details for project '%s'", cmdProjectName), outputOptions)
return nil
}
if len(dataMain.Data) == 0 {
output.RenderInfo(fmt.Sprintf("No details for project '%s'", getProjectFlags.Project), outputOptions)
os.Exit(0)

DevEnvironments := 0
productionRoute := "none"
deploymentsDisabled, err := strconv.ParseBool(strconv.Itoa(int(project.DeploymentsDisabled)))
handleError(err)
autoIdle, err := strconv.ParseBool(strconv.Itoa(int(project.AutoIdle)))
handleError(err)
factsUI, err := strconv.ParseBool(strconv.Itoa(int(project.FactsUI)))
handleError(err)
problemsUI, err := strconv.ParseBool(strconv.Itoa(int(project.ProblemsUI)))
handleError(err)
for _, environment := range project.Environments {
if environment.EnvironmentType == "development" {
DevEnvironments++
}
if environment.EnvironmentType == "production" {
productionRoute = environment.Route
}
}
output.RenderOutput(dataMain, outputOptions)

data := []output.Data{}
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%d", project.ID)),
returnNonEmptyString(fmt.Sprintf("%v", project.Name)),
returnNonEmptyString(fmt.Sprintf("%v", project.GitURL)),
returnNonEmptyString(fmt.Sprintf("%v", project.Branches)),
returnNonEmptyString(fmt.Sprintf("%v", project.PullRequests)),
returnNonEmptyString(fmt.Sprintf("%v", productionRoute)),
returnNonEmptyString(fmt.Sprintf("%v/%v", DevEnvironments, project.DevelopmentEnvironmentsLimit)),
returnNonEmptyString(fmt.Sprintf("%v", project.DevelopmentEnvironmentsLimit)),
returnNonEmptyString(fmt.Sprintf("%v", project.ProductionEnvironment)),
returnNonEmptyString(fmt.Sprintf("%v", project.RouterPattern)),
returnNonEmptyString(fmt.Sprintf("%v", autoIdle)),
returnNonEmptyString(fmt.Sprintf("%v", factsUI)),
returnNonEmptyString(fmt.Sprintf("%v", problemsUI)),
returnNonEmptyString(fmt.Sprintf("%v", deploymentsDisabled)),
})
dataMain := output.Table{
Header: []string{"ID", "ProjectName", "GitURL", "Branches", "PullRequests", "ProductionRoute", "DevEnvironments", "DevEnvLimit", "ProductionEnv", "RouterPattern", "AutoIdle", "FactsUI", "ProblemsUI", "DeploymentsDisabled"},
Data: data,
}
output.RenderOutput(dataMain, outputOptions)
return nil
},
}

Expand Down
56 changes: 56 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"strconv"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -436,11 +437,66 @@ var listNotificationCmd = &cobra.Command{
},
}

var listProjectGroupsCmd = &cobra.Command{
Use: "project-groups",
Aliases: []string{"pg"},
Short: "List groups in a project (alias: pg)",
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
}
if cmdProjectName == "" {
fmt.Println("Missing arguments: Project 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)
projectGroups, err := l.GetProjectGroups(context.TODO(), cmdProjectName, lc)
handleError(err)

if len(projectGroups.Groups) == 0 {
output.RenderInfo(fmt.Sprintf("There are no projects in group '%s'", groupName), outputOptions)
os.Exit(0)
}

data := []output.Data{}
for _, group := range projectGroups.Groups {
var organization = "null"
if group.Organization != 0 {
organization = strconv.Itoa(group.Organization)
}
data = append(data, []string{
returnNonEmptyString(fmt.Sprintf("%v", group.ID)),
returnNonEmptyString(fmt.Sprintf("%v", group.Name)),
returnNonEmptyString(fmt.Sprintf("%v", organization)),
})
}
dataMain := output.Table{
Header: []string{"Group ID", "Group Name", "Organization"},
Data: data,
}
output.RenderOutput(dataMain, outputOptions)
return nil
},
}

func init() {
listCmd.AddCommand(listDeployTargetsCmd)
listCmd.AddCommand(listDeploymentsCmd)
listCmd.AddCommand(listGroupsCmd)
listCmd.AddCommand(listGroupProjectsCmd)
listCmd.AddCommand(listProjectGroupsCmd)
listCmd.AddCommand(listEnvironmentsCmd)
listCmd.AddCommand(listProjectsCmd)
listCmd.AddCommand(listNotificationCmd)
Expand Down
1 change: 1 addition & 0 deletions docs/commands/lagoon_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ List projects, environments, deployments, variables or notifications
* [lagoon list groups](lagoon_list_groups.md) - List groups you have access to (alias: g)
* [lagoon list invokable-tasks](lagoon_list_invokable-tasks.md) - Print a list of invokable tasks
* [lagoon list notification](lagoon_list_notification.md) - List all notifications or notifications on projects
* [lagoon list project-groups](lagoon_list_project-groups.md) - List groups in a project (alias: pg)
* [lagoon list projects](lagoon_list_projects.md) - List all projects you have access to (alias: p)
* [lagoon list projects-by-metadata](lagoon_list_projects-by-metadata.md) - List projects by a given metadata key or key:value
* [lagoon list tasks](lagoon_list_tasks.md) - List tasks for an environment (alias: t)
Expand Down
39 changes: 39 additions & 0 deletions docs/commands/lagoon_list_project-groups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## lagoon list project-groups

List groups in a project (alias: pg)

### Synopsis

List groups in a project (alias: pg)

```
lagoon list project-groups [flags]
```

### Options

```
-h, --help help for project-groups
```

### Options inherited from parent commands

```
--config-file string Path to the config file to use (must be *.yml or *.yaml)
--debug Enable debugging output (if supported)
-e, --environment string Specify an environment to use
--force Force yes on prompts (if supported)
-l, --lagoon string The Lagoon instance to interact with
--no-header No header on table (if supported)
--output-csv Output as CSV (if supported)
--output-json Output as JSON (if supported)
--pretty Make JSON pretty (if supported)
-p, --project string Specify a project to use
--skip-update-check Skip checking for updates
-i, --ssh-key string Specify path to a specific SSH key to use for lagoon authentication
```

### SEE ALSO

* [lagoon list](lagoon_list.md) - List projects, environments, deployments, variables or notifications

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 8ee5f4a

Please sign in to comment.