Skip to content

Commit

Permalink
[configtls] Rename config structs for consistancy
Browse files Browse the repository at this point in the history
TLSClientSetting to ClientConfig
TLSServerSetting to ServerConfig
TLSSetting to Config
  • Loading branch information
arjunmahishi committed Feb 6, 2024
1 parent 52c914d commit b08a147
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 224 deletions.
12 changes: 6 additions & 6 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ type ClientConfig struct {
// The compression key for supported compression types within collector.
Compression configcompression.Type `mapstructure:"compression"`

// TLSSetting struct exposes TLS client configuration.
TLSSetting configtls.TLSClientSetting `mapstructure:"tls"`
// Config struct exposes TLS client configuration.
Config configtls.ClientConfig `mapstructure:"tls"`

// The keepalive parameters for gRPC client. See grpc.WithKeepaliveParams.
// (https://godoc.org/google.golang.org/grpc#WithKeepaliveParams).
Expand Down Expand Up @@ -131,7 +131,7 @@ type ServerConfig struct {

// Configures the protocol to use TLS.
// The default value is nil, which will cause the protocol to not use TLS.
TLSSetting *configtls.TLSServerSetting `mapstructure:"tls"`
Config *configtls.ServerConfig `mapstructure:"tls"`

// MaxRecvMsgSizeMiB sets the maximum size (in MiB) of messages accepted by the server.
MaxRecvMsgSizeMiB uint64 `mapstructure:"max_recv_msg_size_mib"`
Expand Down Expand Up @@ -202,7 +202,7 @@ func (gcs *ClientConfig) toDialOptions(host component.Host, settings component.T
opts = append(opts, grpc.WithDefaultCallOptions(grpc.UseCompressor(cp)))
}

tlsCfg, err := gcs.TLSSetting.LoadTLSConfig()
tlsCfg, err := gcs.Config.LoadTLSConfig()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -304,8 +304,8 @@ func (gss *ServerConfig) toServerOption(host component.Host, settings component.

var opts []grpc.ServerOption

if gss.TLSSetting != nil {
tlsCfg, err := gss.TLSSetting.LoadTLSConfig()
if gss.Config != nil {
tlsCfg, err := gss.Config.LoadTLSConfig()
if err != nil {
return nil, err
}
Expand Down
98 changes: 49 additions & 49 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestDefaultGrpcClientSettings(t *testing.T) {
t.Cleanup(func() { require.NoError(t, tt.Shutdown(context.Background())) })

gcs := &ClientConfig{
TLSSetting: configtls.TLSClientSetting{
Config: configtls.ClientConfig{
Insecure: true,
},
}
Expand All @@ -90,7 +90,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
},
Endpoint: "localhost:1234",
Compression: configcompression.TypeGzip,
TLSSetting: configtls.TLSClientSetting{
Config: configtls.ClientConfig{
Insecure: false,
},
Keepalive: &KeepaliveClientConfig{
Expand Down Expand Up @@ -119,7 +119,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
},
Endpoint: "localhost:1234",
Compression: configcompression.TypeSnappy,
TLSSetting: configtls.TLSClientSetting{
Config: configtls.ClientConfig{
Insecure: false,
},
Keepalive: &KeepaliveClientConfig{
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestAllGrpcClientSettings(t *testing.T) {
},
Endpoint: "localhost:1234",
Compression: configcompression.TypeZstd,
TLSSetting: configtls.TLSClientSetting{
Config: configtls.ClientConfig{
Insecure: false,
},
Keepalive: &KeepaliveClientConfig{
Expand Down Expand Up @@ -196,8 +196,8 @@ func TestAllGrpcServerSettingsExceptAuth(t *testing.T) {
Endpoint: "localhost:1234",
Transport: "tcp",
},
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{},
Config: &configtls.ServerConfig{
Config: configtls.Config{},
ClientCAFile: "",
},
MaxRecvMsgSizeMiB: 1,
Expand Down Expand Up @@ -258,8 +258,8 @@ func TestGRPCClientSettingsError(t *testing.T) {
Headers: nil,
Endpoint: "",
Compression: "",
TLSSetting: configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
Config: configtls.ClientConfig{
Config: configtls.Config{
CAFile: "/doesnt/exist",
},
Insecure: false,
Expand All @@ -274,8 +274,8 @@ func TestGRPCClientSettingsError(t *testing.T) {
Headers: nil,
Endpoint: "",
Compression: "",
TLSSetting: configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
Config: configtls.ClientConfig{
Config: configtls.Config{
CertFile: "/doesnt/exist",
},
Insecure: false,
Expand All @@ -292,7 +292,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
},
Endpoint: "localhost:1234",
Compression: "gzip",
TLSSetting: configtls.TLSClientSetting{
Config: configtls.ClientConfig{
Insecure: false,
},
Keepalive: &KeepaliveClientConfig{
Expand Down Expand Up @@ -326,7 +326,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
err: "unsupported compression type \"zlib\"",
settings: ClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Config: configtls.ClientConfig{
Insecure: true,
},
Compression: "zlib",
Expand All @@ -337,7 +337,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
err: "unsupported compression type \"deflate\"",
settings: ClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Config: configtls.ClientConfig{
Insecure: true,
},
Compression: "deflate",
Expand All @@ -348,7 +348,7 @@ func TestGRPCClientSettingsError(t *testing.T) {
err: "unsupported compression type \"bad\"",
settings: ClientConfig{
Endpoint: "localhost:1234",
TLSSetting: configtls.TLSClientSetting{
Config: configtls.ClientConfig{
Insecure: true,
},
Compression: "bad",
Expand All @@ -374,7 +374,7 @@ func TestUseSecure(t *testing.T) {
Headers: nil,
Endpoint: "",
Compression: "",
TLSSetting: configtls.TLSClientSetting{},
Config: configtls.ClientConfig{},
Keepalive: nil,
}
dialOpts, err := gcs.toDialOptions(componenttest.NewNopHost(), tt.TelemetrySettings())
Expand Down Expand Up @@ -445,8 +445,8 @@ func TestGRPCServerSettingsError(t *testing.T) {
Endpoint: "127.0.0.1:1234",
Transport: "tcp",
},
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
Config: &configtls.ServerConfig{
Config: configtls.Config{
CAFile: "/doesnt/exist",
},
},
Expand All @@ -459,8 +459,8 @@ func TestGRPCServerSettingsError(t *testing.T) {
Endpoint: "127.0.0.1:1234",
Transport: "tcp",
},
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
Config: &configtls.ServerConfig{
Config: configtls.Config{
CertFile: "/doesnt/exist",
},
},
Expand All @@ -473,7 +473,7 @@ func TestGRPCServerSettingsError(t *testing.T) {
Endpoint: "127.0.0.1:1234",
Transport: "tcp",
},
TLSSetting: &configtls.TLSServerSetting{
Config: &configtls.ServerConfig{
ClientCAFile: "/doesnt/exist",
},
},
Expand All @@ -493,8 +493,8 @@ func TestGRPCServerSettings_ToListener_Error(t *testing.T) {
Endpoint: "127.0.0.1:1234567",
Transport: "tcp",
},
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
Config: &configtls.ServerConfig{
Config: configtls.Config{
CertFile: "/doesnt/exist",
},
},
Expand All @@ -511,42 +511,42 @@ func TestHttpReception(t *testing.T) {

tests := []struct {
name string
tlsServerCreds *configtls.TLSServerSetting
tlsClientCreds *configtls.TLSClientSetting
tlsServerCreds *configtls.ServerConfig
tlsClientCreds *configtls.ClientConfig
hasError bool
}{
{
name: "noTLS",
tlsServerCreds: nil,
tlsClientCreds: &configtls.TLSClientSetting{
tlsClientCreds: &configtls.ClientConfig{
Insecure: true,
},
},
{
name: "TLS",
tlsServerCreds: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
tlsServerCreds: &configtls.ServerConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "ca.crt"),
CertFile: filepath.Join("testdata", "server.crt"),
KeyFile: filepath.Join("testdata", "server.key"),
},
},
tlsClientCreds: &configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
tlsClientCreds: &configtls.ClientConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "ca.crt"),
},
ServerName: "localhost",
},
},
{
name: "NoServerCertificates",
tlsServerCreds: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
tlsServerCreds: &configtls.ServerConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "ca.crt"),
},
},
tlsClientCreds: &configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
tlsClientCreds: &configtls.ClientConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "ca.crt"),
},
ServerName: "localhost",
Expand All @@ -555,16 +555,16 @@ func TestHttpReception(t *testing.T) {
},
{
name: "mTLS",
tlsServerCreds: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
tlsServerCreds: &configtls.ServerConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "ca.crt"),
CertFile: filepath.Join("testdata", "server.crt"),
KeyFile: filepath.Join("testdata", "server.key"),
},
ClientCAFile: filepath.Join("testdata", "ca.crt"),
},
tlsClientCreds: &configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
tlsClientCreds: &configtls.ClientConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "ca.crt"),
CertFile: filepath.Join("testdata", "client.crt"),
KeyFile: filepath.Join("testdata", "client.key"),
Expand All @@ -574,16 +574,16 @@ func TestHttpReception(t *testing.T) {
},
{
name: "NoClientCertificate",
tlsServerCreds: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
tlsServerCreds: &configtls.ServerConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "ca.crt"),
CertFile: filepath.Join("testdata", "server.crt"),
KeyFile: filepath.Join("testdata", "server.key"),
},
ClientCAFile: filepath.Join("testdata", "ca.crt"),
},
tlsClientCreds: &configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
tlsClientCreds: &configtls.ClientConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "ca.crt"),
},
ServerName: "localhost",
Expand All @@ -592,16 +592,16 @@ func TestHttpReception(t *testing.T) {
},
{
name: "WrongClientCA",
tlsServerCreds: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
tlsServerCreds: &configtls.ServerConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "ca.crt"),
CertFile: filepath.Join("testdata", "server.crt"),
KeyFile: filepath.Join("testdata", "server.key"),
},
ClientCAFile: filepath.Join("testdata", "server.crt"),
},
tlsClientCreds: &configtls.TLSClientSetting{
TLSSetting: configtls.TLSSetting{
tlsClientCreds: &configtls.ClientConfig{
Config: configtls.Config{
CAFile: filepath.Join("testdata", "ca.crt"),
CertFile: filepath.Join("testdata", "client.crt"),
KeyFile: filepath.Join("testdata", "client.key"),
Expand All @@ -620,7 +620,7 @@ func TestHttpReception(t *testing.T) {
Endpoint: "localhost:0",
Transport: "tcp",
},
TLSSetting: test.tlsServerCreds,
Config: test.tlsServerCreds,
}
ln, err := gss.ToListenerContext(context.Background())
assert.NoError(t, err)
Expand All @@ -634,7 +634,7 @@ func TestHttpReception(t *testing.T) {

gcs := &ClientConfig{
Endpoint: ln.Addr().String(),
TLSSetting: *test.tlsClientCreds,
Config: *test.tlsClientCreds,
}
grpcClientConn, errClient := gcs.ToClientConn(context.Background(), componenttest.NewNopHost(), tt.TelemetrySettings())
assert.NoError(t, errClient)
Expand Down Expand Up @@ -681,7 +681,7 @@ func TestReceiveOnUnixDomainSocket(t *testing.T) {

gcs := &ClientConfig{
Endpoint: "unix://" + ln.Addr().String(),
TLSSetting: configtls.TLSClientSetting{
Config: configtls.ClientConfig{
Insecure: true,
},
}
Expand Down Expand Up @@ -883,7 +883,7 @@ func TestClientInfoInterceptors(t *testing.T) {
{
gcs := &ClientConfig{
Endpoint: l.Addr().String(),
TLSSetting: configtls.TLSClientSetting{
Config: configtls.ClientConfig{
Insecure: true,
},
}
Expand Down
14 changes: 7 additions & 7 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type ClientConfig struct {
// ProxyURL setting for the collector
ProxyURL string `mapstructure:"proxy_url"`

// TLSSetting struct exposes TLS client configuration.
TLSSetting configtls.TLSClientSetting `mapstructure:"tls"`
// Config struct exposes TLS client configuration.
Config configtls.ClientConfig `mapstructure:"tls"`

// ReadBufferSize for HTTP client. See http.Transport.ReadBufferSize.
ReadBufferSize int `mapstructure:"read_buffer_size"`
Expand Down Expand Up @@ -129,7 +129,7 @@ func NewDefaultClientConfig() ClientConfig {

// ToClient creates an HTTP client.
func (hcs *ClientConfig) ToClient(host component.Host, settings component.TelemetrySettings) (*http.Client, error) {
tlsCfg, err := hcs.TLSSetting.LoadTLSConfig()
tlsCfg, err := hcs.Config.LoadTLSConfig()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -265,8 +265,8 @@ type ServerConfig struct {
// Endpoint configures the listening address for the server.
Endpoint string `mapstructure:"endpoint"`

// TLSSetting struct exposes TLS client configuration.
TLSSetting *configtls.TLSServerSetting `mapstructure:"tls"`
// Config struct exposes TLS client configuration.
Config *configtls.ServerConfig `mapstructure:"tls"`

// CORS configures the server for HTTP cross-origin resource sharing (CORS).
CORS *CORSConfig `mapstructure:"cors"`
Expand All @@ -293,9 +293,9 @@ func (hss *ServerConfig) ToListener() (net.Listener, error) {
return nil, err
}

if hss.TLSSetting != nil {
if hss.Config != nil {
var tlsCfg *tls.Config
tlsCfg, err = hss.TLSSetting.LoadTLSConfig()
tlsCfg, err = hss.Config.LoadTLSConfig()
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit b08a147

Please sign in to comment.