-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the deployment list command and an associated text template. Signed-off-by: Marc Lopez <marc5.12@outlook.com>
- Loading branch information
Showing
10 changed files
with
416 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,45 @@ | ||
// 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 cmddeployment | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/elastic/ecctl/pkg/deployment" | ||
"github.com/elastic/ecctl/pkg/ecctl" | ||
) | ||
|
||
var listCmd = &cobra.Command{ | ||
Use: "list", | ||
Short: "Lists the platform's deployments", | ||
PreRunE: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
res, err := deployment.List(deployment.ListParams{ | ||
API: ecctl.Get().API, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return ecctl.Get().Formatter.Format("deployment/list", res) | ||
}, | ||
} | ||
|
||
func init() { | ||
Command.AddCommand(listCmd) | ||
} |
This file contains 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 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,43 @@ | ||
## ecctl deployment list | ||
|
||
Lists the platform's deployments | ||
|
||
### Synopsis | ||
|
||
Lists the platform's deployments | ||
|
||
``` | ||
ecctl deployment list [flags] | ||
``` | ||
|
||
### Options | ||
|
||
``` | ||
-h, --help help for list | ||
``` | ||
|
||
### Options inherited from parent commands | ||
|
||
``` | ||
--apikey string API key to use to authenticate (If empty will look for EC_APIKEY environment variable) | ||
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config") | ||
--force Do not ask for confirmation | ||
--format string Formats the output using a Go template | ||
--host string Base URL to use (default "https://api.elastic-cloud.com") | ||
--insecure Skips all TLS validation | ||
--message string A message to set on cluster operation | ||
--output string Output format [text|json] (default "text") | ||
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable) | ||
--pprof Enables pprofing and saves the profile to pprof-20060102150405 | ||
-q, --quiet Suppresses the configuration file used for the run, if any | ||
--region string Elastic Cloud region | ||
--timeout duration Timeout to use on all HTTP calls (default 30s) | ||
--trace Enables tracing saves the trace to trace-20060102150405 | ||
--user string Username to use to authenticate (If empty will look for EC_USER environment variable) | ||
--verbose Enable verbose mode | ||
``` | ||
|
||
### SEE ALSO | ||
|
||
* [ecctl deployment](ecctl_deployment.md) - Manages deployments | ||
|
This file contains 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,57 @@ | ||
// 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 deployment | ||
|
||
import ( | ||
"github.com/elastic/cloud-sdk-go/pkg/api" | ||
"github.com/elastic/cloud-sdk-go/pkg/client/deployments" | ||
"github.com/elastic/cloud-sdk-go/pkg/models" | ||
|
||
"github.com/elastic/ecctl/pkg/util" | ||
) | ||
|
||
// ListParams is consumed by List. | ||
type ListParams struct { | ||
*api.API | ||
} | ||
|
||
// Validate ensures the parameters are usable. | ||
func (params ListParams) Validate() error { | ||
if params.API == nil { | ||
return util.ErrAPIReq | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// List returns the platform deployemnts | ||
func List(params ListParams) (*models.DeploymentsListResponse, error) { | ||
if err := params.Validate(); err != nil { | ||
return nil, err | ||
} | ||
|
||
res, err := params.V1API.Deployments.ListDeployments( | ||
deployments.NewListDeploymentsParams(), | ||
params.AuthWriter, | ||
) | ||
if err != nil { | ||
return nil, api.UnwrapError(err) | ||
} | ||
|
||
return res.Payload, nil | ||
} |
This file contains 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,173 @@ | ||
// 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 deployment | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/elastic/cloud-sdk-go/pkg/api" | ||
"github.com/elastic/cloud-sdk-go/pkg/api/mock" | ||
"github.com/elastic/cloud-sdk-go/pkg/models" | ||
"github.com/elastic/cloud-sdk-go/pkg/util/ec" | ||
|
||
"github.com/elastic/ecctl/pkg/util" | ||
) | ||
|
||
var deploymentList = `{ | ||
"deployments": [ | ||
{ | ||
"id": "709551ecd21143adbb7a37bbf36c4321", | ||
"name": "admin-console-elasticsearch", | ||
"resources": [ | ||
{ | ||
"cloud_id": "admin-console-elasticsearch:MTkyLjE2OC40NC4xMC5pcC5lcy5pbzo5MjQzJDcwOTU1MWVjZDIxMTQzYWRiYjdhMzdiYmYzNmM0MzIxJA==", | ||
"id": "709551ecd21143adbb7a37bbf36c4321", | ||
"kind": "elasticsearch", | ||
"ref_id": "elasticsearch", | ||
"region": "ece-region" | ||
} | ||
] | ||
}, | ||
{ | ||
"id": "83c2027d92c44aeba34378f44cf08137", | ||
"name": "logging-and-metrics", | ||
"resources": [ | ||
{ | ||
"cloud_id": "logging-and-metrics:MTkyLjE2OC40NC4xMC5pcC5lcy5pbzo5MjQzJDgzYzIwMjdkOTJjNDRhZWJhMzQzNzhmNDRjZjA4MTM3JGQxNDBiNmUzNWIwNDQ1YTlhZmQ0NDIwZjZjMWIzYjIx", | ||
"id": "83c2027d92c44aeba34378f44cf08137", | ||
"kind": "elasticsearch", | ||
"ref_id": "elasticsearch", | ||
"region": "ece-region" | ||
}, | ||
{ | ||
"elasticsearch_cluster_ref_id": "elasticsearch", | ||
"id": "d140b6e35b0445a9afd4420f6c1b3b21", | ||
"kind": "kibana", | ||
"ref_id": "kibana", | ||
"region": "ece-region" | ||
} | ||
] | ||
}, | ||
{ | ||
"id": "89a54cee4a2847c291f520ac00760886", | ||
"name": "security-cluster", | ||
"resources": [ | ||
{ | ||
"cloud_id": "security-cluster:MTkyLjE2OC40NC4xMC5pcC5lcy5pbzo5MjQzJDg5YTU0Y2VlNGEyODQ3YzI5MWY1MjBhYzAwNzYwODg2JA==", | ||
"id": "89a54cee4a2847c291f520ac00760886", | ||
"kind": "elasticsearch", | ||
"ref_id": "elasticsearch", | ||
"region": "ece-region" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
` | ||
|
||
func TestList(t *testing.T) { | ||
type args struct { | ||
params ListParams | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *models.DeploymentsListResponse | ||
err error | ||
}{ | ||
{ | ||
name: "fails on parameter validation", | ||
err: util.ErrAPIReq, | ||
}, | ||
{ | ||
name: "fails on API error", | ||
args: args{params: ListParams{ | ||
API: api.NewMock(mock.New500Response(mock.NewStringBody("error"))), | ||
}}, | ||
err: errors.New("unknown error (status 500)"), | ||
}, | ||
{ | ||
name: "Succeeds", | ||
args: args{params: ListParams{ | ||
API: api.NewMock(mock.New200Response(mock.NewStringBody(deploymentList))), | ||
}}, | ||
want: &models.DeploymentsListResponse{Deployments: []*models.DeploymentsListingData{ | ||
{ | ||
ID: ec.String("709551ecd21143adbb7a37bbf36c4321"), | ||
Name: ec.String("admin-console-elasticsearch"), | ||
Resources: []*models.DeploymentResource{ | ||
{ | ||
CloudID: "admin-console-elasticsearch:MTkyLjE2OC40NC4xMC5pcC5lcy5pbzo5MjQzJDcwOTU1MWVjZDIxMTQzYWRiYjdhMzdiYmYzNmM0MzIxJA==", | ||
ID: ec.String("709551ecd21143adbb7a37bbf36c4321"), | ||
Kind: ec.String("elasticsearch"), | ||
RefID: ec.String("elasticsearch"), | ||
Region: ec.String("ece-region"), | ||
}, | ||
}, | ||
}, | ||
{ | ||
ID: ec.String("83c2027d92c44aeba34378f44cf08137"), | ||
Name: ec.String("logging-and-metrics"), | ||
Resources: []*models.DeploymentResource{ | ||
{ | ||
CloudID: "logging-and-metrics:MTkyLjE2OC40NC4xMC5pcC5lcy5pbzo5MjQzJDgzYzIwMjdkOTJjNDRhZWJhMzQzNzhmNDRjZjA4MTM3JGQxNDBiNmUzNWIwNDQ1YTlhZmQ0NDIwZjZjMWIzYjIx", | ||
ID: ec.String("83c2027d92c44aeba34378f44cf08137"), | ||
Kind: ec.String("elasticsearch"), | ||
RefID: ec.String("elasticsearch"), | ||
Region: ec.String("ece-region"), | ||
}, | ||
{ | ||
ElasticsearchClusterRefID: "elasticsearch", | ||
ID: ec.String("d140b6e35b0445a9afd4420f6c1b3b21"), | ||
Kind: ec.String("kibana"), | ||
RefID: ec.String("kibana"), | ||
Region: ec.String("ece-region"), | ||
}, | ||
}, | ||
}, | ||
{ | ||
ID: ec.String("89a54cee4a2847c291f520ac00760886"), | ||
Name: ec.String("security-cluster"), | ||
Resources: []*models.DeploymentResource{ | ||
{ | ||
CloudID: "security-cluster:MTkyLjE2OC40NC4xMC5pcC5lcy5pbzo5MjQzJDg5YTU0Y2VlNGEyODQ3YzI5MWY1MjBhYzAwNzYwODg2JA==", | ||
ID: ec.String("89a54cee4a2847c291f520ac00760886"), | ||
Kind: ec.String("elasticsearch"), | ||
RefID: ec.String("elasticsearch"), | ||
Region: ec.String("ece-region"), | ||
}, | ||
}, | ||
}, | ||
}}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := List(tt.args.params) | ||
if !reflect.DeepEqual(err, tt.err) { | ||
t.Errorf("List() error = %v, wantErr %v", err, tt.err) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("List() = %+v, want %+v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains 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 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,15 @@ | ||
{{- define "override" }}{{ range .Deployments }}{{ executeTemplate .}} | ||
{{ end }}{{ end }}{{ define "default" }} | ||
{{- "ID" }}{{tab}}{{ "NAME"}}{{tab}}{{"ELASTICSEARCH"}}{{tab}}{{"KIBANA"}}{{tab}}{{"APM"}}{{tab}}{{"APPSEARCH"}} | ||
{{- range .Deployments }} | ||
{{- $kibana := "-"}} | ||
{{- $apm := "-"}} | ||
{{- $appsearch := "-"}} | ||
{{- range .Resources}} | ||
{{- if equal .Kind "kibana" }}{{ $kibana = .ID }}{{end}} | ||
{{- if equal .Kind "apm" }}{{ $apm = .ID }}{{end}} | ||
{{- if equal .Kind "appsearch" }}{{ $appsearch = .ID }}{{end}} | ||
{{- end}} | ||
{{ .ID }}{{tab}}{{ .Name }}{{ tab }}{{.ID}}{{tab}}{{ $kibana }}{{ tab }}{{ $apm }}{{ tab }}{{ $appsearch }} | ||
{{- end}} | ||
{{end}} |
Oops, something went wrong.