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

feat: list environments services #386

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
72 changes: 72 additions & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strconv"
"strings"

"github.com/spf13/cobra"
"github.com/uselagoon/lagoon-cli/pkg/output"
Expand Down Expand Up @@ -1243,6 +1244,76 @@ var listOrganizationsCmd = &cobra.Command{
},
}

var listEnvironmentServicesCmd = &cobra.Command{
Use: "environment-services",
Aliases: []string{"e"},
Short: "Get information about an environments services",
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 err := requiredInputCheck("Project name", cmdProjectName, "Environment name", cmdProjectEnvironment); err != nil {
return err
}
current := lagoonCLIConfig.Current
token := lagoonCLIConfig.Lagoons[current].Token
lc := lclient.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIVersion,
lagoonCLIConfig.Lagoons[current].Version,
&token,
debug)

project, err := lagoon.GetProjectByName(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
environment, err := lagoon.GetEnvironmentByName(context.TODO(), cmdProjectEnvironment, project.ID, lc)
if err != nil {
return err
}

if project.Name == "" || environment.Name == "" {
if project.Name == "" {
return handleNilResults("Project '%s' not found\n", cmd, cmdProjectName)
} else {
return handleNilResults("Environment '%s' not found in project '%s'\n", cmd, cmdProjectEnvironment, cmdProjectName)
}
}

data := []output.Data{}
envHeader := []string{"EnvironmentID", "EnvironmentName", "ServiceID", "ServiceName", "ServiceType", "Containers", "Updated", "Created"}
for _, es := range environment.Services {
containers := []string{}
for _, c := range es.Containers {
containers = append(containers, c.Name)
}
envData := []string{
returnNonEmptyString(fmt.Sprintf("%d", environment.ID)),
returnNonEmptyString(fmt.Sprintf("%v", environment.Name)),
returnNonEmptyString(fmt.Sprintf("%d", es.ID)),
returnNonEmptyString(fmt.Sprintf("%v", es.Name)),
returnNonEmptyString(fmt.Sprintf("%v", es.Type)),
returnNonEmptyString(fmt.Sprintf("%v", strings.Join(containers, ","))),
returnNonEmptyString(fmt.Sprintf("%v", es.Updated)),
returnNonEmptyString(fmt.Sprintf("%v", es.Created)),
}
data = append(data, envData)
}
dataMain := output.Table{
Header: envHeader,
Data: data,
}
r := output.RenderOutput(dataMain, outputOptions)
fmt.Fprintf(cmd.OutOrStdout(), "%s", r)
return nil
},
}

func init() {
listCmd.AddCommand(listDeployTargetsCmd)
listCmd.AddCommand(listDeploymentsCmd)
Expand All @@ -1267,6 +1338,7 @@ func init() {
listCmd.AddCommand(listOrganizationGroupsCmd)
listCmd.AddCommand(listOrganizationDeployTargetsCmd)
listCmd.AddCommand(listOrganizationsCmd)
listCmd.AddCommand(listEnvironmentServicesCmd)
listAllUsersCmd.Flags().StringP("email", "E", "", "The email address of a user")
listUsersGroupsCmd.Flags().StringP("email", "E", "", "The email address of a user")
listCmd.Flags().BoolVarP(&listAllProjects, "all-projects", "", false, "All projects (if supported)")
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 @@ -38,6 +38,7 @@ List projects, environments, deployments, variables or notifications
* [lagoon list deployments](lagoon_list_deployments.md) - List deployments for an environment (alias: d)
* [lagoon list deploytarget-configs](lagoon_list_deploytarget-configs.md) - List deploytarget configs for a project
* [lagoon list deploytargets](lagoon_list_deploytargets.md) - List all DeployTargets in Lagoon
* [lagoon list environment-services](lagoon_list_environment-services.md) - Get information about an environments services
* [lagoon list environments](lagoon_list_environments.md) - List environments for a project (alias: e)
* [lagoon list group-projects](lagoon_list_group-projects.md) - List projects in a group (alias: gp)
* [lagoon list group-users](lagoon_list_group-users.md) - List all users in groups
Expand Down
39 changes: 39 additions & 0 deletions docs/commands/lagoon_list_environment-services.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## lagoon list environment-services

Get information about an environments services

```
lagoon list environment-services [flags]
```

### Options

```
-h, --help help for environment-services
```

### 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
--ssh-publickey string Specify path to a specific SSH public key to use for lagoon authentication using ssh-agent.
This will override any public key identities defined in configuration
--strict-host-key-checking string Similar to SSH StrictHostKeyChecking (accept-new, no, ignore) (default "accept-new")
-v, --verbose Enable verbose output to stderr (if supported)
```

### SEE ALSO

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