Skip to content
Merged
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
2 changes: 1 addition & 1 deletion build/Makefile.deps
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ VERSION_DIR:=$(GOBIN)/versions

VERSION_GOLICENSER:=v0.4.1
VERSION_GOLICENCEDETECTOR:=v0.6.0
VERSION_GOLANGCILINT:=v2.8.0
VERSION_GOLANGCILINT:=v2.10.1
VERSION_GOBINDATA:=v0.0.0-20190711162640-ee3c2418e368
VERSION_GORELEASER:=v2.13.3
VERSION_VERSIONBUMP:=v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
cmdcomment "github.com/elastic/ecctl/cmd/comment"
cmddeployment "github.com/elastic/ecctl/cmd/deployment"
cmdplatform "github.com/elastic/ecctl/cmd/platform"
cmdproject "github.com/elastic/ecctl/cmd/project"
cmdstack "github.com/elastic/ecctl/cmd/stack"
cmduser "github.com/elastic/ecctl/cmd/user"
)
Expand All @@ -32,6 +33,7 @@ func init() {
cmdcomment.Command,
cmddeployment.Command,
cmdplatform.Command,
cmdproject.Command,
cmduser.Command,
cmdstack.Command,
)
Expand Down
32 changes: 32 additions & 0 deletions cmd/project/command.go
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()
},
}
54 changes: 54 additions & 0 deletions cmd/project/list.go
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)")
Copy link
Member

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 type flags?

project list --type elasticsearch --type security

Copy link
Contributor Author

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.

}
209 changes: 209 additions & 0 deletions cmd/project/list_test.go
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()
})
}
}
31 changes: 31 additions & 0 deletions docs/reference/ecctl_project.md
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

31 changes: 31 additions & 0 deletions docs/reference/ecctl_project_list.md
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

2 changes: 2 additions & 0 deletions docs/reference/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ toc:
- file: ecctl_platform_runner_resync.md
- file: ecctl_platform_runner_search.md
- file: ecctl_platform_runner_show.md
- file: ecctl_project.md
- file: ecctl_project_list.md
- file: ecctl_stack.md
- file: ecctl_stack_delete.md
- file: ecctl_stack_list.md
Expand Down
Loading
Loading