Skip to content

Commit c47b9d5

Browse files
authored
Expose clear_transients in ecctl (#649)
* Add ClearTransients * Add comment * Update test * Update cloud-sdk-go * Adds flag documentation * Update docs * Update flag documentation * Add tests * Fix documentation
1 parent 54341aa commit c47b9d5

File tree

6 files changed

+99
-8
lines changed

6 files changed

+99
-8
lines changed

cmd/deployment/show.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,21 @@ var showCmd = &cobra.Command{
5858
refID, _ := cmd.Flags().GetString("ref-id")
5959

6060
generatePayload, _ := cmd.Flags().GetBool("generate-update-payload")
61+
62+
clearTransient := false
63+
6164
if generatePayload {
62-
showPlans, settings = true, true
65+
showPlans, settings, clearTransient = true, true, true
6366
resourceKind, refID = "", ""
6467
}
6568

69+
// The idea here is that the default of clear-transient depends on the value of `generate-update-payload`. If
70+
// `generate-update-payload` is true then we want `clear-transient` to default to true. If the flag value
71+
// has been passed in we want to use that value instead.
72+
if cmd.Flags().Changed("clear-transient") {
73+
clearTransient, _ = cmd.Flags().GetBool("clear-transient")
74+
}
75+
6676
getParams := deploymentapi.GetParams{
6777
API: ecctl.Get().API,
6878
DeploymentID: args[0],
@@ -74,6 +84,7 @@ var showCmd = &cobra.Command{
7484
ShowPlanHistory: planHistory,
7585
ShowMetadata: metadata,
7686
ShowSettings: settings,
87+
ClearTransient: clearTransient,
7788
},
7889
}
7990

@@ -112,4 +123,5 @@ func initShowFlags() {
112123
showCmd.Flags().BoolP("metadata", "m", false, "Shows the deployment metadata")
113124
showCmd.Flags().BoolP("settings", "s", false, "Shows the deployment settings")
114125
showCmd.Flags().Bool("generate-update-payload", false, "Outputs JSON which can be used as an argument for the --file flag with the update command.")
126+
showCmd.Flags().Bool("clear-transient", false, "Removes the transient field in order to make read - edit - write loop safer. The default value of clear-transient depends on the value of generate-update-payload. If generate-update-payload is true then clear-transient defaults to true. Otherwise defaults to false.")
115127
}

cmd/deployment/show_test.go

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,82 @@ func Test_showCmd(t *testing.T) {
182182
"show", "29337f77410e23ab30e15c280060facf",
183183
"--generate-update-payload",
184184
},
185+
Cfg: testutils.MockCfg{
186+
OutputFormat: "json",
187+
Responses: []mock.Response{
188+
mock.New200ResponseAssertion(
189+
&mock.RequestAssertion{
190+
Header: api.DefaultReadMockHeaders,
191+
Method: "GET",
192+
Path: "/api/v1/deployments/29337f77410e23ab30e15c280060facf",
193+
Host: api.DefaultMockHost,
194+
Query: url.Values{
195+
"clear_transient": {"true"},
196+
"convert_legacy_plans": {"false"},
197+
"show_metadata": {"false"},
198+
"show_plan_defaults": {"false"},
199+
"show_plan_history": {"false"},
200+
"show_plan_logs": {"false"},
201+
"show_plans": {"true"},
202+
"show_settings": {"true"},
203+
"show_system_alerts": {"5"},
204+
},
205+
},
206+
mock.NewByteBody(showApmResp),
207+
),
208+
},
209+
},
210+
},
211+
want: testutils.Assertion{
212+
Stdout: string(wantGeneratePayload),
213+
},
214+
},
215+
{
216+
name: "succeeds with `--clear-transient=false`",
217+
args: testutils.Args{
218+
Cmd: showCmd,
219+
Args: []string{
220+
"show", "29337f77410e23ab30e15c280060facf",
221+
"--clear-transient=false",
222+
},
223+
Cfg: testutils.MockCfg{
224+
OutputFormat: "json",
225+
Responses: []mock.Response{
226+
mock.New200ResponseAssertion(
227+
&mock.RequestAssertion{
228+
Header: api.DefaultReadMockHeaders,
229+
Method: "GET",
230+
Path: "/api/v1/deployments/29337f77410e23ab30e15c280060facf",
231+
Host: api.DefaultMockHost,
232+
Query: url.Values{
233+
"convert_legacy_plans": {"false"},
234+
"show_metadata": {"false"},
235+
"show_plan_defaults": {"false"},
236+
"show_plan_history": {"false"},
237+
"show_plan_logs": {"false"},
238+
"show_plans": {"false"},
239+
"show_settings": {"false"},
240+
"show_system_alerts": {"5"},
241+
},
242+
},
243+
mock.NewByteBody(showRawResp),
244+
),
245+
},
246+
},
247+
},
248+
want: testutils.Assertion{
249+
Stdout: string(showJSONOutput) + "\n",
250+
},
251+
},
252+
{
253+
name: "succeeds with `--generate-update-payload` and `--clear-transient=false`",
254+
args: testutils.Args{
255+
Cmd: showCmd,
256+
Args: []string{
257+
"show", "29337f77410e23ab30e15c280060facf",
258+
"--generate-update-payload",
259+
"--clear-transient=false",
260+
},
185261
Cfg: testutils.MockCfg{
186262
OutputFormat: "json",
187263
Responses: []mock.Response{
@@ -389,7 +465,7 @@ func Test_showCmd(t *testing.T) {
389465
Args: []string{
390466
"show", "29337f77410e23ab30e15c280060facf", "--plans",
391467
"--plan-logs", "--plan-defaults", "--plan-history",
392-
"--metadata", "--settings",
468+
"--metadata", "--settings", "--clear-transient",
393469
},
394470
Cfg: testutils.MockCfg{
395471
OutputFormat: "json",
@@ -401,6 +477,7 @@ func Test_showCmd(t *testing.T) {
401477
Path: "/api/v1/deployments/29337f77410e23ab30e15c280060facf",
402478
Host: api.DefaultMockHost,
403479
Query: url.Values{
480+
"clear_transient": {"true"},
404481
"convert_legacy_plans": {"false"},
405482
"show_metadata": {"true"},
406483
"show_plan_defaults": {"true"},

docs/ecctl_deployment_show.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ ecctl deployment show <deployment-id> [flags]
2626
=== Options
2727

2828
----
29+
--clear-transient Removes the transient field in order to make read - edit - write loop safer. The default value of clear-transient depends on the value of generate-update-payload. If generate-update-payload is true then clear-transient defaults to true. Otherwise defaults to false.
2930
--generate-update-payload Outputs JSON which can be used as an argument for the --file flag with the update command.
3031
-h, --help help for show
3132
--kind string Optional deployment resource kind (apm, appsearch, kibana, elasticsearch)

docs/ecctl_deployment_show.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ecctl deployment show <deployment-id> [flags]
2323
### Options
2424

2525
```
26+
--clear-transient Removes the transient field in order to make read - edit - write loop safer. The default value of clear-transient depends on the value of generate-update-payload. If generate-update-payload is true then clear-transient defaults to true. Otherwise defaults to false.
2627
--generate-update-payload Outputs JSON which can be used as an argument for the --file flag with the update command.
2728
-h, --help help for show
2829
--kind string Optional deployment resource kind (apm, appsearch, kibana, elasticsearch)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.20
55
require (
66
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2
77
github.com/blang/semver/v4 v4.0.0
8-
github.com/elastic/cloud-sdk-go v1.18.0
8+
github.com/elastic/cloud-sdk-go v1.19.0
99
github.com/go-openapi/runtime v0.23.0
1010
github.com/go-openapi/strfmt v0.21.2
1111
github.com/pkg/errors v0.9.1
@@ -53,7 +53,7 @@ require (
5353
go.uber.org/multierr v1.9.0 // indirect
5454
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
5555
golang.org/x/sys v0.20.0 // indirect
56-
golang.org/x/text v0.14.0 // indirect
56+
golang.org/x/text v0.15.0 // indirect
5757
gopkg.in/ini.v1 v1.67.0 // indirect
5858
gopkg.in/yaml.v2 v2.4.0 // indirect
5959
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
2323
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2424
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
2525
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
26-
github.com/elastic/cloud-sdk-go v1.18.0 h1:X3hpCllYfXfEKLpBL8zwLI0n8H7mW6rnb7MUSQM6L3Q=
27-
github.com/elastic/cloud-sdk-go v1.18.0/go.mod h1:ax6+gRTyZm951pyBUk68hfbf7emCQ/Sb0TaunM1/q4s=
26+
github.com/elastic/cloud-sdk-go v1.19.0 h1:Xk8VGcMi3JmKsh0EuyMMvgxwb9OfBnzn2RzzLPps7xY=
27+
github.com/elastic/cloud-sdk-go v1.19.0/go.mod h1:vur6dxodTbEzoFMlgLWnXuTkcctk5E3sKZCBz0gMjJ0=
2828
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
2929
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
3030
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
@@ -368,8 +368,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
368368
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
369369
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
370370
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
371-
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
372-
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
371+
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
372+
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
373373
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
374374
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
375375
golang.org/x/tools v0.0.0-20190125232054-d66bd3c5d5a6/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

0 commit comments

Comments
 (0)