Skip to content

Commit

Permalink
Add NewDefault* funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
TylerHelmuth committed Feb 29, 2024
1 parent df6f8fd commit d03acab
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .chloggen/configtls-add-newdefault-funcs.yaml
Original file line number Diff line number Diff line change
@@ -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]
21 changes: 20 additions & 1 deletion config/configtls/configtls.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,17 @@ type Config struct {
ReloadInterval time.Duration `mapstructure:"reload_interval"`
}

// NewDefaultConfig creates a new TLSSetting with any default values set.
func NewDefaultConfig() Config {
return Config{}
}

// TSLClientSetting contains TLS configurations that are specific to client
// connections in addition to the common configurations.
// Deprecated: [v0.96.0] Use ClientConfig instead.
type TLSClientSetting = ClientConfig

// ClientConfig contains TLS configurations that are specific to client
// TLSClientSetting 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.
type ClientConfig struct {
Expand All @@ -104,6 +109,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{
TLSSetting: NewDefaultConfig(),
}
}

// TLSServerSetting contains TLS configurations that are specific to server
// connections in addition to the common configurations.
// Deprecated: [v0.96.0] Use ServerConfig instead.
Expand All @@ -128,6 +140,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{
TLSSetting: 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
Expand Down
22 changes: 22 additions & 0 deletions config/configtls/configtls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,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
Expand Down

0 comments on commit d03acab

Please sign in to comment.