Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .chloggen/configtls-depr-context-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: deprecation

# 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: Deprecates `ClientConfig.LoadTLSConfigContext` and `ServerConfig.LoadTLSConfigContext`, use `ClientConfig.LoadTLSConfig` and `ServerConfig.LoadTLSConfig` instead.

# One or more tracking issues or pull requests related to the change
issues: [9945]

# (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]
4 changes: 2 additions & 2 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (gcs *ClientConfig) toDialOptions(host component.Host, settings component.T
opts = append(opts, grpc.WithDefaultCallOptions(grpc.UseCompressor(cp)))
}

tlsCfg, err := gcs.TLSSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err := gcs.TLSSetting.LoadTLSConfig(context.Background())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -286,7 +286,7 @@ func (gss *ServerConfig) toServerOption(host component.Host, settings component.
var opts []grpc.ServerOption

if gss.TLSSetting != nil {
tlsCfg, err := gss.TLSSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err := gss.TLSSetting.LoadTLSConfig(context.Background())
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (hcs *ClientConfig) ToClient(host component.Host, settings component.Teleme

// ToClientContext creates an HTTP client.
func (hcs *ClientConfig) ToClientContext(ctx context.Context, host component.Host, settings component.TelemetrySettings) (*http.Client, error) {
tlsCfg, err := hcs.TLSSetting.LoadTLSConfigContext(ctx)
tlsCfg, err := hcs.TLSSetting.LoadTLSConfig(ctx)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -296,7 +296,7 @@ func (hss *ServerConfig) ToListenerContext(ctx context.Context) (net.Listener, e

if hss.TLSSetting != nil {
var tlsCfg *tls.Config
tlsCfg, err = hss.TLSSetting.LoadTLSConfigContext(ctx)
tlsCfg, err = hss.TLSSetting.LoadTLSConfig(ctx)
if err != nil {
return nil, err
}
Expand Down
26 changes: 13 additions & 13 deletions config/configtls/configtls.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,13 @@ func (c Config) loadCert(caPath string) (*x509.CertPool, error) {
}

// LoadTLSConfigContext loads the TLS configuration.
func (c ClientConfig) LoadTLSConfigContext(_ context.Context) (*tls.Config, error) {
// Deprecated: [v0.99.0] Use LoadTLSConfig instead.
func (c ClientConfig) LoadTLSConfigContext(ctx context.Context) (*tls.Config, error) {
return c.LoadTLSConfig(ctx)
}

// LoadTLSConfig loads the TLS configuration.
func (c ClientConfig) LoadTLSConfig(_ context.Context) (*tls.Config, error) {
if c.Insecure && !c.hasCA() {
return nil, nil
}
Expand All @@ -372,14 +378,14 @@ func (c ClientConfig) LoadTLSConfigContext(_ context.Context) (*tls.Config, erro
return tlsCfg, nil
}

// LoadTLSConfig loads the TLS configuration.
// Deprecated: [v0.97.0] Use LoadTLSConfigContext instead.
func (c ClientConfig) LoadTLSConfig() (*tls.Config, error) {
return c.LoadTLSConfigContext(context.Background())
// LoadTLSConfigContext loads the TLS configuration.
// Deprecated: [v0.99.0] Use LoadTLSConfig instead.
func (c ServerConfig) LoadTLSConfigContext(ctx context.Context) (*tls.Config, error) {
return c.LoadTLSConfig(ctx)
}

// LoadTLSConfigContext loads the TLS configuration.
func (c ServerConfig) LoadTLSConfigContext(_ context.Context) (*tls.Config, error) {
// LoadTLSConfig loads the TLS configuration.
func (c ServerConfig) LoadTLSConfig(_ context.Context) (*tls.Config, error) {
tlsCfg, err := c.loadTLSConfig()
if err != nil {
return nil, fmt.Errorf("failed to load TLS config: %w", err)
Expand All @@ -402,12 +408,6 @@ func (c ServerConfig) LoadTLSConfigContext(_ context.Context) (*tls.Config, erro
return tlsCfg, nil
}

// LoadTLSConfig loads the TLS configuration.
// Deprecated: [v0.97.0] Use LoadTLSConfigContext instead.
func (c ServerConfig) LoadTLSConfig() (*tls.Config, error) {
return c.LoadTLSConfigContext(context.Background())
}

func (c ServerConfig) loadClientCAFile() (*x509.CertPool, error) {
return c.loadCert(c.ClientCAFile)
}
Expand Down
28 changes: 14 additions & 14 deletions config/configtls/configtls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,27 +255,27 @@ func TestLoadTLSClientConfigError(t *testing.T) {
KeyFile: "doesnt/exist",
},
}
_, err := tlsSetting.LoadTLSConfigContext(context.Background())
_, err := tlsSetting.LoadTLSConfig(context.Background())
assert.Error(t, err)
}

func TestLoadTLSClientConfig(t *testing.T) {
tlsSetting := ClientConfig{
Insecure: true,
}
tlsCfg, err := tlsSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background())
assert.NoError(t, err)
assert.Nil(t, tlsCfg)

tlsSetting = ClientConfig{}
tlsCfg, err = tlsSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err = tlsSetting.LoadTLSConfig(context.Background())
assert.NoError(t, err)
assert.NotNil(t, tlsCfg)

tlsSetting = ClientConfig{
InsecureSkipVerify: true,
}
tlsCfg, err = tlsSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err = tlsSetting.LoadTLSConfig(context.Background())
assert.NoError(t, err)
assert.NotNil(t, tlsCfg)
assert.True(t, tlsCfg.InsecureSkipVerify)
Expand All @@ -288,19 +288,19 @@ func TestLoadTLSServerConfigError(t *testing.T) {
KeyFile: "doesnt/exist",
},
}
_, err := tlsSetting.LoadTLSConfigContext(context.Background())
_, err := tlsSetting.LoadTLSConfig(context.Background())
assert.Error(t, err)

tlsSetting = ServerConfig{
ClientCAFile: "doesnt/exist",
}
_, err = tlsSetting.LoadTLSConfigContext(context.Background())
_, err = tlsSetting.LoadTLSConfig(context.Background())
assert.Error(t, err)
}

func TestLoadTLSServerConfig(t *testing.T) {
tlsSetting := ServerConfig{}
tlsCfg, err := tlsSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background())
assert.NoError(t, err)
assert.NotNil(t, tlsCfg)
}
Expand All @@ -316,7 +316,7 @@ func TestLoadTLSServerConfigReload(t *testing.T) {
ReloadClientCAFile: true,
}

tlsCfg, err := tlsSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background())
assert.NoError(t, err)
assert.NotNil(t, tlsCfg)

Expand Down Expand Up @@ -347,7 +347,7 @@ func TestLoadTLSServerConfigFailingReload(t *testing.T) {
ReloadClientCAFile: true,
}

tlsCfg, err := tlsSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background())
assert.NoError(t, err)
assert.NotNil(t, tlsCfg)

Expand Down Expand Up @@ -378,7 +378,7 @@ func TestLoadTLSServerConfigFailingInitialLoad(t *testing.T) {
ReloadClientCAFile: true,
}

tlsCfg, err := tlsSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background())
assert.Error(t, err)
assert.Nil(t, tlsCfg)
}
Expand All @@ -392,7 +392,7 @@ func TestLoadTLSServerConfigWrongPath(t *testing.T) {
ReloadClientCAFile: true,
}

tlsCfg, err := tlsSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background())
assert.Error(t, err)
assert.Nil(t, tlsCfg)
}
Expand All @@ -408,7 +408,7 @@ func TestLoadTLSServerConfigFailing(t *testing.T) {
ReloadClientCAFile: true,
}

tlsCfg, err := tlsSetting.LoadTLSConfigContext(context.Background())
tlsCfg, err := tlsSetting.LoadTLSConfig(context.Background())
assert.NoError(t, err)
assert.NotNil(t, tlsCfg)

Expand Down Expand Up @@ -774,7 +774,7 @@ func TestSystemCertPool(t *testing.T) {
serverConfig := ServerConfig{
Config: test.tlsConfig,
}
c, err := serverConfig.LoadTLSConfig()
c, err := serverConfig.LoadTLSConfig(context.Background())
if test.wantErr != nil {
assert.ErrorContains(t, err, test.wantErr.Error())
} else {
Expand All @@ -784,7 +784,7 @@ func TestSystemCertPool(t *testing.T) {
clientConfig := ClientConfig{
Config: test.tlsConfig,
}
c, err = clientConfig.LoadTLSConfig()
c, err = clientConfig.LoadTLSConfig(context.Background())
if test.wantErr != nil {
assert.ErrorContains(t, err, test.wantErr.Error())
} else {
Expand Down