-
Notifications
You must be signed in to change notification settings - Fork 59
Add ecctl project list command for serverless projects
#753
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4f0019b
Add `ecctl project list` command for serverless projects
Kushmaro 9362f71
Update docs/ecctl_project.md
Kushmaro 4f58e53
docs: fix ecctl_project link formatting
Kushmaro e87c75d
Update link format for ecctl reference
Kushmaro cc0c846
Bump golangci-lint
tobio 566f6ea
make docs?
tobio ad26394
Maybe we could document how to make the docs?
tobio 995dc39
Should they be committed in the reference docs?
tobio c366fb7
What is a title?
tobio 8348be9
Surely we could be using a template for this?
tobio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you under | ||
| // the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package cmdproject | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // Command is the top level project command. | ||
| var Command = &cobra.Command{ | ||
| Use: "project", | ||
| Short: "Manages serverless projects", | ||
| PreRunE: cobra.MaximumNArgs(0), | ||
| Run: func(cmd *cobra.Command, args []string) { | ||
| cmd.Help() | ||
| }, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you under | ||
| // the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package cmdproject | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/elastic/ecctl/pkg/ecctl" | ||
| "github.com/elastic/ecctl/pkg/project" | ||
| ) | ||
|
|
||
| var listCmd = &cobra.Command{ | ||
| Use: "list", | ||
| Short: "Lists serverless projects", | ||
| PreRunE: cobra.NoArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| projectType, _ := cmd.Flags().GetString("type") | ||
|
|
||
| res, err := project.List(project.ListParams{ | ||
| API: ecctl.Get().API, | ||
| Host: ecctl.Get().Config.Host, | ||
| Type: projectType, | ||
| Client: ecctl.Get().Config.Client, | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| return ecctl.Get().Formatter.Format(filepath.Join("project", "list"), res) | ||
| }, | ||
| } | ||
|
|
||
| func init() { | ||
| Command.AddCommand(listCmd) | ||
|
|
||
| listCmd.Flags().String("type", "", "Filters by project type (elasticsearch, observability, security)") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,209 @@ | ||
| // Licensed to Elasticsearch B.V. under one or more contributor | ||
| // license agreements. See the NOTICE file distributed with | ||
| // this work for additional information regarding copyright | ||
| // ownership. Elasticsearch B.V. licenses this file to you under | ||
| // the Apache License, Version 2.0 (the "License"); you may | ||
| // not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|
|
||
| package cmdproject | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "testing" | ||
|
|
||
| "github.com/elastic/cloud-sdk-go/pkg/api/mock" | ||
|
|
||
| "github.com/elastic/ecctl/cmd/util/testutils" | ||
| "github.com/elastic/ecctl/pkg/project" | ||
| ) | ||
|
|
||
| func newProjectListBody(projects []project.Project) mock.Response { | ||
| body := project.ListResponse{Items: projects} | ||
| b, _ := json.Marshal(body) | ||
| return mock.New200Response(mock.NewByteBody(b)) | ||
| } | ||
|
|
||
| func initListFlags() { | ||
| listCmd.ResetFlags() | ||
| listCmd.Flags().String("type", "", "Filters by project type (elasticsearch, observability, security)") | ||
| } | ||
|
|
||
| func Test_listCmd(t *testing.T) { | ||
| var esProjects = []project.Project{ | ||
| { | ||
| ID: "abc123", | ||
| Name: "my-es-project", | ||
| Type: "elasticsearch", | ||
| RegionID: "aws-us-east-1", | ||
| Alias: "my-es-project-abc123", | ||
| }, | ||
| } | ||
| var obsProjects = []project.Project{ | ||
| { | ||
| ID: "def456", | ||
| Name: "my-obs-project", | ||
| Type: "observability", | ||
| RegionID: "gcp-us-central1", | ||
| Alias: "my-obs-project-def456", | ||
| }, | ||
| } | ||
| var secProjects = []project.Project{ | ||
| { | ||
| ID: "ghi789", | ||
| Name: "my-sec-project", | ||
| Type: "security", | ||
| RegionID: "azure-eastus2", | ||
| Alias: "", | ||
| }, | ||
| } | ||
|
|
||
| var allProjects project.ListResult | ||
| allProjects.Projects = append(allProjects.Projects, esProjects...) | ||
| allProjects.Projects = append(allProjects.Projects, obsProjects...) | ||
| allProjects.Projects = append(allProjects.Projects, secProjects...) | ||
|
|
||
| allProjectsJSON, _ := json.MarshalIndent(allProjects, "", " ") | ||
|
|
||
| var esResult = project.ListResult{Projects: esProjects} | ||
| esResultJSON, _ := json.MarshalIndent(esResult, "", " ") | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| args testutils.Args | ||
| want testutils.Assertion | ||
| }{ | ||
| { | ||
| name: "fails due to arguments passed", | ||
| args: testutils.Args{ | ||
| Cmd: listCmd, | ||
| Args: []string{"list", "some-argument"}, | ||
| Cfg: testutils.MockCfg{Responses: []mock.Response{ | ||
| mock.SampleInternalError(), | ||
| }}, | ||
| }, | ||
| want: testutils.Assertion{ | ||
| Err: `unknown command "some-argument" for "project list"`, | ||
| }, | ||
| }, | ||
| { | ||
| name: "fails due to invalid type", | ||
| args: testutils.Args{ | ||
| Cmd: listCmd, | ||
| Args: []string{"list", "--type", "invalid"}, | ||
| Cfg: testutils.MockCfg{Responses: []mock.Response{ | ||
| mock.SampleInternalError(), | ||
| }}, | ||
| }, | ||
| want: testutils.Assertion{ | ||
| Err: `invalid project type "invalid", must be one of: elasticsearch, observability, security`, | ||
| }, | ||
| }, | ||
| { | ||
| name: "succeeds filtering by elasticsearch type with JSON format", | ||
| args: testutils.Args{ | ||
| Cmd: listCmd, | ||
| Args: []string{"list", "--type", "elasticsearch"}, | ||
| Cfg: testutils.MockCfg{ | ||
| OutputFormat: "json", | ||
| Responses: []mock.Response{ | ||
| newProjectListBody(esProjects), | ||
| }, | ||
| }, | ||
| }, | ||
| want: testutils.Assertion{ | ||
| Stdout: string(esResultJSON) + "\n", | ||
| }, | ||
| }, | ||
| { | ||
| name: "succeeds filtering by elasticsearch type with text format", | ||
| args: testutils.Args{ | ||
| Cmd: listCmd, | ||
| Args: []string{"list", "--type", "elasticsearch"}, | ||
| Cfg: testutils.MockCfg{ | ||
| OutputFormat: "text", | ||
| Responses: []mock.Response{ | ||
| newProjectListBody(esProjects), | ||
| }, | ||
| }, | ||
| }, | ||
| want: testutils.Assertion{ | ||
| Stdout: "ID NAME TYPE REGION ALIAS\n" + | ||
| "abc123 my-es-project elasticsearch aws-us-east-1 my-es-project-abc123\n", | ||
| }, | ||
| }, | ||
| { | ||
| name: "succeeds listing all project types with JSON format", | ||
| args: testutils.Args{ | ||
| Cmd: listCmd, | ||
| Args: []string{"list"}, | ||
| Cfg: testutils.MockCfg{ | ||
| OutputFormat: "json", | ||
| Responses: []mock.Response{ | ||
| newProjectListBody(esProjects), | ||
| newProjectListBody(obsProjects), | ||
| newProjectListBody(secProjects), | ||
| }, | ||
| }, | ||
| }, | ||
| want: testutils.Assertion{ | ||
| Stdout: string(allProjectsJSON) + "\n", | ||
| }, | ||
| }, | ||
| { | ||
| name: "succeeds listing all project types with text format", | ||
| args: testutils.Args{ | ||
| Cmd: listCmd, | ||
| Args: []string{"list"}, | ||
| Cfg: testutils.MockCfg{ | ||
| OutputFormat: "text", | ||
| Responses: []mock.Response{ | ||
| newProjectListBody(esProjects), | ||
| newProjectListBody(obsProjects), | ||
| newProjectListBody(secProjects), | ||
| }, | ||
| }, | ||
| }, | ||
| want: testutils.Assertion{ | ||
| Stdout: "ID NAME TYPE REGION ALIAS\n" + | ||
| "abc123 my-es-project elasticsearch aws-us-east-1 my-es-project-abc123\n" + | ||
| "def456 my-obs-project observability gcp-us-central1 my-obs-project-def456\n" + | ||
| "ghi789 my-sec-project security azure-eastus2 -\n", | ||
| }, | ||
| }, | ||
| { | ||
| name: "succeeds with empty project list", | ||
| args: testutils.Args{ | ||
| Cmd: listCmd, | ||
| Args: []string{"list", "--type", "security"}, | ||
| Cfg: testutils.MockCfg{ | ||
| OutputFormat: "json", | ||
| Responses: []mock.Response{ | ||
| newProjectListBody(nil), | ||
| }, | ||
| }, | ||
| }, | ||
| want: testutils.Assertion{ | ||
| Stdout: `{ | ||
| "projects": null | ||
| } | ||
| `, | ||
| }, | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| testutils.RunCmdAssertion(t, tt.args, tt.want) | ||
| initListFlags() | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| mapped_pages: | ||
| - https://www.elastic.co/guide/en/ecctl/current/ecctl_project.html | ||
| applies_to: | ||
| deployment: | ||
| ess: all | ||
| --- | ||
| # ecctl project [ecctl_project] | ||
|
|
||
| Manages serverless projects | ||
|
|
||
| ``` | ||
| ecctl project [flags] | ||
| ``` | ||
|
|
||
| ## Options [_options_67] | ||
|
|
||
| ``` | ||
| -h, --help help for project | ||
| ``` | ||
|
|
||
| ## Options inherited from parent commands [_options_inherited_from_parent_commands_67] | ||
|
|
||
| :::{include} _snippets/inherited-options.md | ||
| ::: | ||
|
|
||
| ### See also [_see_also_67] | ||
|
|
||
| * [ecctl](/reference/ecctl.md) - Elastic Cloud Control | ||
| * [ecctl project list](ecctl_project_list.md) - Lists serverless projects | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| --- | ||
| mapped_pages: | ||
| - https://www.elastic.co/guide/en/ecctl/current/ecctl_project_list.html | ||
| applies_to: | ||
| deployment: | ||
| ess: all | ||
| --- | ||
| # ecctl project list [ecctl_project_list] | ||
|
|
||
| Lists serverless projects | ||
|
|
||
| ``` | ||
| ecctl project list [flags] | ||
| ``` | ||
|
|
||
| ## Options [_options_68] | ||
|
|
||
| ``` | ||
| -h, --help help for list | ||
| --type string Filters by project type (elasticsearch, observability, security) | ||
| ``` | ||
|
|
||
| ## Options inherited from parent commands [_options_inherited_from_parent_commands_68] | ||
|
|
||
| :::{include} _snippets/inherited-options.md | ||
| ::: | ||
|
|
||
| ## See also [_see_also_68] | ||
|
|
||
| * [ecctl project](/reference/ecctl_project.md) - Manages serverless projects | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense to support multiple
typeflags?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I can also add that as a follow up? didn't want to go deep with this PR since i'm totally vibing it hehe.