Skip to content

Commit 841ddef

Browse files
authored
elasticsearch: Add keystore management commands (#58)
Adds two new commands, which allow an Elasticsearch cluster's keystore to be updated and to be shown: * ecctl deployment elasticsearch keystore set <cluster id> -f def.json * ecctl deployment elasticsearch keystore show <cluster id> The specified keystore definition is treated as a partial and the values in it are used to either create / update the keystore values. Existing keystore values will not be affected if missing from the request. Signed-off-by: Marc Lopez <marc5.12@outlook.com>
1 parent 72fc278 commit 841ddef

12 files changed

+710
-0
lines changed

cmd/deployment/elasticsearch/command.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/spf13/cobra"
2222

2323
cmdelasticsearchinstances "github.com/elastic/ecctl/cmd/deployment/elasticsearch/instances"
24+
cmdelasticsearchkeystore "github.com/elastic/ecctl/cmd/deployment/elasticsearch/keystore"
2425
cmdelasticsearchmonitoring "github.com/elastic/ecctl/cmd/deployment/elasticsearch/monitoring"
2526
cmdelasticsearchplan "github.com/elastic/ecctl/cmd/deployment/elasticsearch/plan"
2627
)
@@ -40,5 +41,6 @@ func init() {
4041
cmdelasticsearchmonitoring.Command,
4142
cmdelasticsearchplan.Command,
4243
cmdelasticsearchinstances.Command,
44+
cmdelasticsearchkeystore.Command,
4345
)
4446
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package cmdelasticsearchkeystore
19+
20+
import (
21+
"github.com/spf13/cobra"
22+
)
23+
24+
// Command is the elasticsearch keystore command
25+
var Command = &cobra.Command{
26+
Use: `keystore`,
27+
Short: "Manages an Elasticsearch cluster's keystore",
28+
PreRunE: cobra.NoArgs,
29+
RunE: func(cmd *cobra.Command, args []string) error {
30+
return cmd.Help()
31+
},
32+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package cmdelasticsearchkeystore
19+
20+
import (
21+
"github.com/elastic/cloud-sdk-go/pkg/models"
22+
"github.com/spf13/cobra"
23+
24+
cmdutil "github.com/elastic/ecctl/cmd/util"
25+
"github.com/elastic/ecctl/pkg/deployment/elasticsearch"
26+
"github.com/elastic/ecctl/pkg/ecctl"
27+
)
28+
29+
const setKeystoreLong = `Manages the keystore settings of an Elasticsearch cluster.
30+
Note that each operation is add/modify only, unspecified existing keystore values will be unchanged.`
31+
32+
var setKeystoreExamples = `
33+
$ cat keystore_example.json
34+
{
35+
"secrets": {
36+
"s3.client.foobar.access_key": {
37+
"value": "AKIXAIQFKXPHIFXSILUWPA",
38+
"as_file": false
39+
},
40+
"s3.client.foobar.secret_key": {
41+
"value": "18qXOpY2zGlApay1237dLXh+LG1X5LUNWjTHq5X1SWjf++m+p0"
42+
}
43+
}
44+
}
45+
$ ecctl deployment elasticsearch keystore set 4c052fb17f65467a9b3c36d060106377 --file keystore_example.json
46+
{
47+
"secrets": {
48+
"s3.client.foobar.access_key": {
49+
"as_file": false
50+
},
51+
"s3.client.foobar.secret_key": {
52+
"as_file": false
53+
}
54+
}
55+
}`[1:]
56+
57+
var setCmd = &cobra.Command{
58+
Use: `set <cluster id> -f <file definition.json>`,
59+
Short: "Updates an Elasticsearch cluster keystore with the contents of a file",
60+
Long: setKeystoreLong,
61+
Example: setKeystoreExamples,
62+
PreRunE: cmdutil.MinimumNArgsAndUUID(1),
63+
RunE: func(cmd *cobra.Command, args []string) error {
64+
filename, _ := cmd.Flags().GetString("file")
65+
var req models.KeystoreContents
66+
if err := cmdutil.DecodeFile(filename, &req); err != nil {
67+
return err
68+
}
69+
70+
res, err := elasticsearch.SetKeystore(elasticsearch.SetKeystoreParams{
71+
API: ecctl.Get().API,
72+
ClusterID: args[0],
73+
Request: &req,
74+
})
75+
if err != nil {
76+
return err
77+
}
78+
79+
return ecctl.Get().Formatter.Format("", res)
80+
},
81+
}
82+
83+
func init() {
84+
Command.AddCommand(setCmd)
85+
setCmd.Flags().StringP("file", "f", "", "JSON file that contains JSON-style domain-specific keystore definition")
86+
setCmd.MarkFlagRequired("file")
87+
setCmd.MarkFlagFilename("file", "*.json")
88+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package cmdelasticsearchkeystore
19+
20+
import (
21+
"github.com/spf13/cobra"
22+
23+
cmdutil "github.com/elastic/ecctl/cmd/util"
24+
"github.com/elastic/ecctl/pkg/deployment/elasticsearch"
25+
"github.com/elastic/ecctl/pkg/ecctl"
26+
)
27+
28+
const keystoreShowExample = `$ ecctl deployment elasticsearch keystore show 4c052fb17f65467a9b3c36d060106377
29+
{
30+
"secrets": {
31+
"s3.client.foobar.access_key": {
32+
"as_file": false
33+
},
34+
"s3.client.foobar.secret_key": {
35+
"as_file": false
36+
}
37+
}
38+
}`
39+
40+
var getCmd = &cobra.Command{
41+
Use: `show <cluster id>`,
42+
Short: "Shows an Elasticsearch cluster's keystore settings",
43+
Example: keystoreShowExample,
44+
PreRunE: cmdutil.MinimumNArgsAndUUID(1),
45+
RunE: func(cmd *cobra.Command, args []string) error {
46+
res, err := elasticsearch.GetKeystore(elasticsearch.GetKeystoreParams{
47+
API: ecctl.Get().API,
48+
ClusterID: args[0],
49+
})
50+
if err != nil {
51+
return err
52+
}
53+
54+
return ecctl.Get().Formatter.Format("", res)
55+
},
56+
}
57+
58+
func init() {
59+
Command.AddCommand(getCmd)
60+
}

docs/ecctl_deployment_elasticsearch.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ecctl deployment elasticsearch [flags]
4444
* [ecctl deployment elasticsearch delete](ecctl_deployment_elasticsearch_delete.md) - Deletes an Elasticsearch cluster
4545
* [ecctl deployment elasticsearch diagnose](ecctl_deployment_elasticsearch_diagnose.md) - Generates a diagnostics bundle for the cluster
4646
* [ecctl deployment elasticsearch instances](ecctl_deployment_elasticsearch_instances.md) - Manages elasticsearch at the instance level
47+
* [ecctl deployment elasticsearch keystore](ecctl_deployment_elasticsearch_keystore.md) - Manages an Elasticsearch cluster's keystore
4748
* [ecctl deployment elasticsearch list](ecctl_deployment_elasticsearch_list.md) - Returns the list of Elasticsearch clusters
4849
* [ecctl deployment elasticsearch monitoring](ecctl_deployment_elasticsearch_monitoring.md) - Manages monitoring for an Elasticsearch cluster
4950
* [ecctl deployment elasticsearch plan](ecctl_deployment_elasticsearch_plan.md) - Manages Elasticsearch plans
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
## ecctl deployment elasticsearch keystore
2+
3+
Manages an Elasticsearch cluster's keystore
4+
5+
### Synopsis
6+
7+
Manages an Elasticsearch cluster's keystore
8+
9+
```
10+
ecctl deployment elasticsearch keystore [flags]
11+
```
12+
13+
### Options
14+
15+
```
16+
-h, --help help for keystore
17+
```
18+
19+
### Options inherited from parent commands
20+
21+
```
22+
--apikey string API key to use to authenticate (If empty will look for EC_APIKEY environment variable)
23+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
24+
--force Do not ask for confirmation
25+
--format string Formats the output using a Go template
26+
--host string Base URL to use
27+
--insecure Skips all TLS validation
28+
--message string A message to set on cluster operation
29+
--output string Output format [text|json] (default "text")
30+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
31+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
32+
-q, --quiet Suppresses the configuration file used for the run, if any
33+
--timeout duration Timeout to use on all HTTP calls (default 30s)
34+
--trace Enables tracing saves the trace to trace-20060102150405
35+
--user string Username to use to authenticate (If empty will look for EC_USER environment variable)
36+
--verbose Enable verbose mode
37+
```
38+
39+
### SEE ALSO
40+
41+
* [ecctl deployment elasticsearch](ecctl_deployment_elasticsearch.md) - Manages Elasticsearch clusters
42+
* [ecctl deployment elasticsearch keystore set](ecctl_deployment_elasticsearch_keystore_set.md) - Updates an Elasticsearch cluster keystore with the contents of a file
43+
* [ecctl deployment elasticsearch keystore show](ecctl_deployment_elasticsearch_keystore_show.md) - Shows an Elasticsearch cluster's keystore settings
44+
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
## ecctl deployment elasticsearch keystore set
2+
3+
Updates an Elasticsearch cluster keystore with the contents of a file
4+
5+
### Synopsis
6+
7+
Manages the keystore settings of an Elasticsearch cluster.
8+
Note that each operation is add/modify only, unspecified existing keystore values will be unchanged.
9+
10+
```
11+
ecctl deployment elasticsearch keystore set <cluster id> -f <file definition.json> [flags]
12+
```
13+
14+
### Examples
15+
16+
```
17+
$ cat keystore_example.json
18+
{
19+
"secrets": {
20+
"s3.client.foobar.access_key": {
21+
"value": "AKIXAIQFKXPHIFXSILUWPA",
22+
"as_file": false
23+
},
24+
"s3.client.foobar.secret_key": {
25+
"value": "18qXOpY2zGlApay1237dLXh+LG1X5LUNWjTHq5X1SWjf++m+p0"
26+
}
27+
}
28+
}
29+
$ ecctl deployment elasticsearch keystore set 4c052fb17f65467a9b3c36d060106377 --file keystore_example.json
30+
{
31+
"secrets": {
32+
"s3.client.foobar.access_key": {
33+
"as_file": false
34+
},
35+
"s3.client.foobar.secret_key": {
36+
"as_file": false
37+
}
38+
}
39+
}
40+
```
41+
42+
### Options
43+
44+
```
45+
-f, --file string JSON file that contains JSON-style domain-specific keystore definition
46+
-h, --help help for set
47+
```
48+
49+
### Options inherited from parent commands
50+
51+
```
52+
--apikey string API key to use to authenticate (If empty will look for EC_APIKEY environment variable)
53+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
54+
--force Do not ask for confirmation
55+
--format string Formats the output using a Go template
56+
--host string Base URL to use
57+
--insecure Skips all TLS validation
58+
--message string A message to set on cluster operation
59+
--output string Output format [text|json] (default "text")
60+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
61+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
62+
-q, --quiet Suppresses the configuration file used for the run, if any
63+
--timeout duration Timeout to use on all HTTP calls (default 30s)
64+
--trace Enables tracing saves the trace to trace-20060102150405
65+
--user string Username to use to authenticate (If empty will look for EC_USER environment variable)
66+
--verbose Enable verbose mode
67+
```
68+
69+
### SEE ALSO
70+
71+
* [ecctl deployment elasticsearch keystore](ecctl_deployment_elasticsearch_keystore.md) - Manages an Elasticsearch cluster's keystore
72+
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
## ecctl deployment elasticsearch keystore show
2+
3+
Shows an Elasticsearch cluster's keystore settings
4+
5+
### Synopsis
6+
7+
Shows an Elasticsearch cluster's keystore settings
8+
9+
```
10+
ecctl deployment elasticsearch keystore show <cluster id> [flags]
11+
```
12+
13+
### Examples
14+
15+
```
16+
$ ecctl deployment elasticsearch keystore show 4c052fb17f65467a9b3c36d060106377
17+
{
18+
"secrets": {
19+
"s3.client.foobar.access_key": {
20+
"as_file": false
21+
},
22+
"s3.client.foobar.secret_key": {
23+
"as_file": false
24+
}
25+
}
26+
}
27+
```
28+
29+
### Options
30+
31+
```
32+
-h, --help help for show
33+
```
34+
35+
### Options inherited from parent commands
36+
37+
```
38+
--apikey string API key to use to authenticate (If empty will look for EC_APIKEY environment variable)
39+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
40+
--force Do not ask for confirmation
41+
--format string Formats the output using a Go template
42+
--host string Base URL to use
43+
--insecure Skips all TLS validation
44+
--message string A message to set on cluster operation
45+
--output string Output format [text|json] (default "text")
46+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
47+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
48+
-q, --quiet Suppresses the configuration file used for the run, if any
49+
--timeout duration Timeout to use on all HTTP calls (default 30s)
50+
--trace Enables tracing saves the trace to trace-20060102150405
51+
--user string Username to use to authenticate (If empty will look for EC_USER environment variable)
52+
--verbose Enable verbose mode
53+
```
54+
55+
### SEE ALSO
56+
57+
* [ecctl deployment elasticsearch keystore](ecctl_deployment_elasticsearch_keystore.md) - Manages an Elasticsearch cluster's keystore
58+

0 commit comments

Comments
 (0)