Skip to content

Commit d5be0f5

Browse files
implement proxies settings show command (#485)
* implement proxies settings show command * update docs * make linter happy * bump sdk to the latest commit * address pr comments
1 parent 056f4d6 commit d5be0f5

13 files changed

+391
-8
lines changed

cmd/platform/proxy/command.go

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

2323
cmdfilteredgroup "github.com/elastic/ecctl/cmd/platform/proxy/filteredgroup"
24+
cmdproxysettings "github.com/elastic/ecctl/cmd/platform/proxy/settings"
2425
cmdutil "github.com/elastic/ecctl/cmd/util"
2526
)
2627

@@ -35,5 +36,5 @@ var Command = &cobra.Command{
3536
}
3637

3738
func init() {
38-
Command.AddCommand(cmdfilteredgroup.Command)
39+
Command.AddCommand(cmdfilteredgroup.Command, cmdproxysettings.Command)
3940
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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 cmdproxysettings
19+
20+
import (
21+
"github.com/spf13/cobra"
22+
23+
cmdutil "github.com/elastic/ecctl/cmd/util"
24+
)
25+
26+
// Command represents the top level proxies settings command.
27+
var Command = &cobra.Command{
28+
Use: "settings",
29+
Short: cmdutil.AdminReqDescription("Manages proxies settings"),
30+
PreRunE: cobra.MaximumNArgs(0),
31+
Run: func(cmd *cobra.Command, args []string) {
32+
cmd.Help()
33+
},
34+
}

cmd/platform/proxy/settings/show.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 cmdproxysettings
19+
20+
import (
21+
"github.com/elastic/cloud-sdk-go/pkg/api/platformapi/proxyapi/settingsapi"
22+
"github.com/spf13/cobra"
23+
24+
cmdutil "github.com/elastic/ecctl/cmd/util"
25+
"github.com/elastic/ecctl/pkg/ecctl"
26+
)
27+
28+
var platformProxySettingsShowCmd = &cobra.Command{
29+
Use: "show",
30+
Short: cmdutil.AdminReqDescription("Shows details for proxies settings"),
31+
PreRunE: cobra.MaximumNArgs(0),
32+
RunE: func(cmd *cobra.Command, args []string) error {
33+
settings, err := settingsapi.Get(settingsapi.GetParams{
34+
API: ecctl.Get().API,
35+
Region: ecctl.Get().Config.Region,
36+
})
37+
38+
if err != nil {
39+
return err
40+
}
41+
return ecctl.Get().Formatter.Format("", settings)
42+
},
43+
}
44+
45+
func init() {
46+
Command.AddCommand(platformProxySettingsShowCmd)
47+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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 cmdproxysettings
19+
20+
import (
21+
"testing"
22+
23+
"github.com/elastic/cloud-sdk-go/pkg/api"
24+
"github.com/elastic/cloud-sdk-go/pkg/api/mock"
25+
26+
"github.com/elastic/ecctl/cmd/util/testutils"
27+
)
28+
29+
func Test_showCmd(t *testing.T) {
30+
const expectedProxiesSettings = `{
31+
"expected_proxies_count": 5,
32+
"http_settings": {
33+
"cookie_secret": "some-secret",
34+
"dashboards_base_url": "some-url",
35+
"disconnected_cutoff": 2,
36+
"minimum_proxy_services": 1,
37+
"sso_settings": {
38+
"cookie_name": "some-cookie",
39+
"default_redirect_path": "some-path",
40+
"dont_log_requests": true,
41+
"maintenance_bypass_cookie_name": "some-other-cookie",
42+
"max_age": 10,
43+
"sso_secret": "sso-secret"
44+
},
45+
"user_cookie_key": "user-cookie"
46+
},
47+
"signature_secret": "signature-secret",
48+
"signature_valid_for_millis": 60
49+
}`
50+
51+
tests := []struct {
52+
name string
53+
args testutils.Args
54+
want testutils.Assertion
55+
}{
56+
{
57+
name: "fails due to provided args",
58+
args: testutils.Args{
59+
Cmd: platformProxySettingsShowCmd,
60+
Args: []string{"show", "some-arg"},
61+
Cfg: testutils.MockCfg{Responses: []mock.Response{
62+
mock.SampleInternalError(),
63+
}},
64+
},
65+
want: testutils.Assertion{
66+
Err: `accepts at most 0 arg(s), received 1`,
67+
},
68+
},
69+
{
70+
name: "fails due to API error",
71+
args: testutils.Args{
72+
Cmd: platformProxySettingsShowCmd,
73+
Args: []string{
74+
"show",
75+
},
76+
Cfg: testutils.MockCfg{Responses: []mock.Response{
77+
mock.SampleInternalError(),
78+
}},
79+
},
80+
want: testutils.Assertion{
81+
Err: mock.MultierrorInternalError.Error(),
82+
},
83+
},
84+
{
85+
name: "succeeds",
86+
args: testutils.Args{
87+
Cmd: platformProxySettingsShowCmd,
88+
Args: []string{
89+
"show",
90+
},
91+
Cfg: testutils.MockCfg{
92+
Responses: []mock.Response{
93+
mock.New200ResponseAssertion(
94+
&mock.RequestAssertion{
95+
Header: api.DefaultReadMockHeaders,
96+
Method: "GET",
97+
Path: "/api/v1/regions/ece-region/platform/infrastructure/proxies/settings",
98+
Host: api.DefaultMockHost,
99+
},
100+
mock.NewStringBody(expectedProxiesSettings),
101+
),
102+
},
103+
},
104+
},
105+
want: testutils.Assertion{
106+
Stdout: expectedProxiesSettings + "\n",
107+
},
108+
},
109+
}
110+
for _, tt := range tests {
111+
t.Run(tt.name, func(t *testing.T) {
112+
testutils.RunCmdAssertion(t, tt.args, tt.want)
113+
tt.args.Cmd.ResetFlags()
114+
})
115+
}
116+
}

docs/ecctl-command-reference-index.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ include::ecctl_platform_proxy_filtered-group_list.adoc[]
102102
include::ecctl_platform_proxy_filtered-group_show.adoc[]
103103
include::ecctl_platform_proxy_filtered-group_update.adoc[]
104104
include::ecctl_platform_proxy_list.adoc[]
105+
include::ecctl_platform_proxy_settings.adoc[]
106+
include::ecctl_platform_proxy_settings_show.adoc[]
105107
include::ecctl_platform_proxy_show.adoc[]
106108
include::ecctl_platform_repository.adoc[]
107109
include::ecctl_platform_repository_create.adoc[]

docs/ecctl_platform_proxy.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ ecctl platform proxy [flags]
4444
* xref:ecctl_platform[ecctl platform] - Manages the platform {ece-icon} (Available for ECE only)
4545
* xref:ecctl_platform_proxy_filtered-group[ecctl platform proxy filtered-group] - Manages proxies filtered group {ece-icon} (Available for ECE only)
4646
* xref:ecctl_platform_proxy_list[ecctl platform proxy list] - Returns all of the proxies in the platform {ece-icon} (Available for ECE only)
47+
* xref:ecctl_platform_proxy_settings[ecctl platform proxy settings] - Manages proxies settings {ece-icon} (Available for ECE only)
4748
* xref:ecctl_platform_proxy_show[ecctl platform proxy show] - Returns information about the proxy with given id {ece-icon} (Available for ECE only)

docs/ecctl_platform_proxy.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,6 @@ ecctl platform proxy [flags]
4040
* [ecctl platform](ecctl_platform.md) - Manages the platform (Available for ECE only)
4141
* [ecctl platform proxy filtered-group](ecctl_platform_proxy_filtered-group.md) - Manages proxies filtered group (Available for ECE only)
4242
* [ecctl platform proxy list](ecctl_platform_proxy_list.md) - Returns all of the proxies in the platform (Available for ECE only)
43+
* [ecctl platform proxy settings](ecctl_platform_proxy_settings.md) - Manages proxies settings (Available for ECE only)
4344
* [ecctl platform proxy show](ecctl_platform_proxy_show.md) - Returns information about the proxy with given id (Available for ECE only)
4445

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
[#ecctl_platform_proxy_settings]
2+
== ecctl platform proxy settings
3+
4+
Manages proxies settings {ece-icon} (Available for ECE only)
5+
6+
----
7+
ecctl platform proxy settings [flags]
8+
----
9+
10+
[float]
11+
=== Options
12+
13+
----
14+
-h, --help help for settings
15+
----
16+
17+
[float]
18+
=== Options inherited from parent commands
19+
20+
----
21+
--api-key string API key to use to authenticate (If empty will look for EC_API_KEY environment variable)
22+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
23+
--force Do not ask for confirmation
24+
--format string Formats the output using a Go template
25+
--host string Base URL to use
26+
--insecure Skips all TLS validation
27+
--message string A message to set on cluster operation
28+
--output string Output format [text|json] (default "text")
29+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
30+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
31+
-q, --quiet Suppresses the configuration file used for the run, if any
32+
--region string Elasticsearch Service region
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+
--verbose-credentials When set, Authorization headers on the request/response trail will be displayed as plain text
38+
--verbose-file string When set, the verbose request/response trail will be written to the defined file
39+
----
40+
41+
[float]
42+
=== SEE ALSO
43+
44+
* xref:ecctl_platform_proxy[ecctl platform proxy] - Manages proxies {ece-icon} (Available for ECE only)
45+
* xref:ecctl_platform_proxy_settings_show[ecctl platform proxy settings show] - Shows details for proxies settings {ece-icon} (Available for ECE only)

docs/ecctl_platform_proxy_settings.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## ecctl platform proxy settings
2+
3+
Manages proxies settings (Available for ECE only)
4+
5+
```
6+
ecctl platform proxy settings [flags]
7+
```
8+
9+
### Options
10+
11+
```
12+
-h, --help help for settings
13+
```
14+
15+
### Options inherited from parent commands
16+
17+
```
18+
--api-key string API key to use to authenticate (If empty will look for EC_API_KEY environment variable)
19+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
20+
--force Do not ask for confirmation
21+
--format string Formats the output using a Go template
22+
--host string Base URL to use
23+
--insecure Skips all TLS validation
24+
--message string A message to set on cluster operation
25+
--output string Output format [text|json] (default "text")
26+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
27+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
28+
-q, --quiet Suppresses the configuration file used for the run, if any
29+
--region string Elasticsearch Service region
30+
--timeout duration Timeout to use on all HTTP calls (default 30s)
31+
--trace Enables tracing saves the trace to trace-20060102150405
32+
--user string Username to use to authenticate (If empty will look for EC_USER environment variable)
33+
--verbose Enable verbose mode
34+
--verbose-credentials When set, Authorization headers on the request/response trail will be displayed as plain text
35+
--verbose-file string When set, the verbose request/response trail will be written to the defined file
36+
```
37+
38+
### SEE ALSO
39+
40+
* [ecctl platform proxy](ecctl_platform_proxy.md) - Manages proxies (Available for ECE only)
41+
* [ecctl platform proxy settings show](ecctl_platform_proxy_settings_show.md) - Shows details for proxies settings (Available for ECE only)
42+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[#ecctl_platform_proxy_settings_show]
2+
== ecctl platform proxy settings show
3+
4+
Shows details for proxies settings {ece-icon} (Available for ECE only)
5+
6+
----
7+
ecctl platform proxy settings show [flags]
8+
----
9+
10+
[float]
11+
=== Options
12+
13+
----
14+
-h, --help help for show
15+
----
16+
17+
[float]
18+
=== Options inherited from parent commands
19+
20+
----
21+
--api-key string API key to use to authenticate (If empty will look for EC_API_KEY environment variable)
22+
--config string Config name, used to have multiple configs in $HOME/.ecctl/<env> (default "config")
23+
--force Do not ask for confirmation
24+
--format string Formats the output using a Go template
25+
--host string Base URL to use
26+
--insecure Skips all TLS validation
27+
--message string A message to set on cluster operation
28+
--output string Output format [text|json] (default "text")
29+
--pass string Password to use to authenticate (If empty will look for EC_PASS environment variable)
30+
--pprof Enables pprofing and saves the profile to pprof-20060102150405
31+
-q, --quiet Suppresses the configuration file used for the run, if any
32+
--region string Elasticsearch Service region
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+
--verbose-credentials When set, Authorization headers on the request/response trail will be displayed as plain text
38+
--verbose-file string When set, the verbose request/response trail will be written to the defined file
39+
----
40+
41+
[float]
42+
=== SEE ALSO
43+
44+
* xref:ecctl_platform_proxy_settings[ecctl platform proxy settings] - Manages proxies settings {ece-icon} (Available for ECE only)

0 commit comments

Comments
 (0)