From 659685e6e514b6b0f4c29bbef989917888f8572e Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 27 Feb 2024 19:58:20 -0600 Subject: [PATCH 1/2] Add NewDefault* funcs --- .chloggen/configtls-add-newdefault-funcs.yaml | 25 +++++++++++++++++++ config/configtls/configtls.go | 19 ++++++++++++++ config/configtls/configtls_test.go | 22 ++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100755 .chloggen/configtls-add-newdefault-funcs.yaml diff --git a/.chloggen/configtls-add-newdefault-funcs.yaml b/.chloggen/configtls-add-newdefault-funcs.yaml new file mode 100755 index 00000000000..2ee397e49af --- /dev/null +++ b/.chloggen/configtls-add-newdefault-funcs.yaml @@ -0,0 +1,25 @@ +# Use this changelog template to create an entry for release notes. + +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) +component: configtls + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Adds `NewDefault*` functions for all the config structs. + +# One or more tracking issues or pull requests related to the change +issues: [9658] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: + +# Optional: The change log or logs in which this entry should be included. +# e.g. '[user]' or '[user, api]' +# Include 'user' if the change is relevant to end users. +# Include 'api' if there is a change to a library API. +# Default: '[user]' +change_logs: [api] diff --git a/config/configtls/configtls.go b/config/configtls/configtls.go index 4f97346e6af..61733e696d6 100644 --- a/config/configtls/configtls.go +++ b/config/configtls/configtls.go @@ -72,6 +72,11 @@ type Config struct { ReloadInterval time.Duration `mapstructure:"reload_interval"` } +// NewDefaultConfig creates a new TLSSetting with any default values set. +func NewDefaultConfig() Config { + return Config{} +} + // ClientConfig contains TLS configurations that are specific to client // connections in addition to the common configurations. This should be used by // components configuring TLS client connections. @@ -96,6 +101,13 @@ type ClientConfig struct { ServerName string `mapstructure:"server_name_override"` } +// NewDefaultClientConfig creates a new TLSClientSetting with any default values set. +func NewDefaultClientConfig() ClientConfig { + return ClientConfig{ + Config: NewDefaultConfig(), + } +} + // ServerConfig contains TLS configurations that are specific to server // connections in addition to the common configurations. This should be used by // components configuring TLS server connections. @@ -115,6 +127,13 @@ type ServerConfig struct { ReloadClientCAFile bool `mapstructure:"client_ca_file_reload"` } +// NewDefaultServerConfig creates a new TLSServerSetting with any default values set. +func NewDefaultServerConfig() ServerConfig { + return ServerConfig{ + Config: NewDefaultConfig(), + } +} + // certReloader is a wrapper object for certificate reloading // Its GetCertificate method will either return the current certificate or reload from disk // if the last reload happened more than ReloadInterval ago diff --git a/config/configtls/configtls_test.go b/config/configtls/configtls_test.go index b6c26cb0beb..f08c1363aa2 100644 --- a/config/configtls/configtls_test.go +++ b/config/configtls/configtls_test.go @@ -21,6 +21,28 @@ import ( "go.opentelemetry.io/collector/config/configopaque" ) +func TestNewDefaultConfig(t *testing.T) { + expectedConfig := TLSSetting{} + config := NewDefaultConfig() + require.Equal(t, expectedConfig, config) +} + +func TestNewDefaultClientConfig(t *testing.T) { + expectedConfig := TLSClientSetting{ + TLSSetting: NewDefaultConfig(), + } + config := NewDefaultClientConfig() + require.Equal(t, expectedConfig, config) +} + +func TestNewDefaultServerConfig(t *testing.T) { + expectedConfig := TLSServerSetting{ + TLSSetting: NewDefaultConfig(), + } + config := NewDefaultServerConfig() + require.Equal(t, expectedConfig, config) +} + func TestOptionsToConfig(t *testing.T) { tests := []struct { name string From b0189916a865dbfbaec4c93f7a15d9d638dbfb7f Mon Sep 17 00:00:00 2001 From: Tyler Helmuth <12352919+TylerHelmuth@users.noreply.github.com> Date: Tue, 2 Apr 2024 14:36:21 -0600 Subject: [PATCH 2/2] fix bad merge --- config/configtls/configtls_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/config/configtls/configtls_test.go b/config/configtls/configtls_test.go index f08c1363aa2..c7cca73f824 100644 --- a/config/configtls/configtls_test.go +++ b/config/configtls/configtls_test.go @@ -22,22 +22,22 @@ import ( ) func TestNewDefaultConfig(t *testing.T) { - expectedConfig := TLSSetting{} + expectedConfig := Config{} config := NewDefaultConfig() require.Equal(t, expectedConfig, config) } func TestNewDefaultClientConfig(t *testing.T) { - expectedConfig := TLSClientSetting{ - TLSSetting: NewDefaultConfig(), + expectedConfig := ClientConfig{ + Config: NewDefaultConfig(), } config := NewDefaultClientConfig() require.Equal(t, expectedConfig, config) } func TestNewDefaultServerConfig(t *testing.T) { - expectedConfig := TLSServerSetting{ - TLSSetting: NewDefaultConfig(), + expectedConfig := ServerConfig{ + Config: NewDefaultConfig(), } config := NewDefaultServerConfig() require.Equal(t, expectedConfig, config)