From fbd47e1161827d3365d84ab2fb848706c9d7116f Mon Sep 17 00:00:00 2001 From: Luke Kysow <1034429+lkysow@users.noreply.github.com> Date: Tue, 25 Oct 2022 10:55:15 -0700 Subject: [PATCH] config entry: hardcode proxy-defaults name as global (#14833) * config entry: hardcode proxy-defaults name as global proxy-defaults can only have the name global. Because of this, we support not even setting the name in the config file: ``` kind = "proxy-defaults" ``` Previously, writing this would result in the output: ``` Config entry written: proxy-defaults/ ``` Now it will output: ``` Config entry written: proxy-defaults/global ``` This change follows what was done for the new Mesh config entry. --- .changelog/14833.txt | 3 +++ api/config_entry.go | 2 +- command/config/write/config_write_test.go | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 .changelog/14833.txt diff --git a/.changelog/14833.txt b/.changelog/14833.txt new file mode 100644 index 0000000000..fd8f911e27 --- /dev/null +++ b/.changelog/14833.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: always use name "global" for proxy-defaults config entries +``` diff --git a/api/config_entry.go b/api/config_entry.go index b1827fb595..7e9ceffdac 100644 --- a/api/config_entry.go +++ b/api/config_entry.go @@ -273,7 +273,7 @@ type ProxyConfigEntry struct { } func (p *ProxyConfigEntry) GetKind() string { return p.Kind } -func (p *ProxyConfigEntry) GetName() string { return p.Name } +func (p *ProxyConfigEntry) GetName() string { return ProxyConfigGlobal } func (p *ProxyConfigEntry) GetPartition() string { return p.Partition } func (p *ProxyConfigEntry) GetNamespace() string { return p.Namespace } func (p *ProxyConfigEntry) GetMeta() map[string]string { return p.Meta } diff --git a/command/config/write/config_write_test.go b/command/config/write/config_write_test.go index 3ea5a8be2a..7671ffdea3 100644 --- a/command/config/write/config_write_test.go +++ b/command/config/write/config_write_test.go @@ -147,6 +147,25 @@ http { require.True(t, proxy.HTTP.SanitizeXForwardedClientCert) }) + + // Test that if name isn't set (which isn't required for proxy-defaults because the name defaults to + // "global"), the CLI response still says "config entry written proxy-defaults/global". + t.Run("proxy defaults config entry without name set", func(t *testing.T) { + stdin := new(bytes.Buffer) + stdin.WriteString(` +kind = "proxy-defaults" +`) + + ui := cli.NewMockUi() + c := New(ui) + c.testStdin = stdin + + code := c.Run([]string{"-http-addr=" + a.HTTPAddr(), "-"}) + require.Empty(t, ui.ErrorWriter.String()) + require.Contains(t, ui.OutputWriter.String(), + `Config entry written: proxy-defaults/global`) + require.Equal(t, 0, code) + }) } func requireContainsLower(t *testing.T, haystack, needle string) {