Skip to content

Commit

Permalink
Use tls_settings consistently between gRPC and HTTP (#1233)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Jun 30, 2020
1 parent 1e6596b commit 28d10c8
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 27 deletions.
6 changes: 3 additions & 3 deletions config/configgrpc/configgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ type GRPCServerSettings struct {

// Configures the protocol to use TLS.
// The default value is nil, which will cause the protocol to not use TLS.
TLSCredentials *configtls.TLSServerSetting `mapstructure:"tls_credentials,omitempty"`
TLSSetting *configtls.TLSServerSetting `mapstructure:"tls_settings,omitempty"`

// 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 @@ -193,8 +193,8 @@ func (gss *GRPCServerSettings) ToListener() (net.Listener, error) {
func (gss *GRPCServerSettings) ToServerOption() ([]grpc.ServerOption, error) {
var opts []grpc.ServerOption

if gss.TLSCredentials != nil {
tlsCfg, err := gss.TLSCredentials.LoadTLSConfig()
if gss.TLSSetting != nil {
tlsCfg, err := gss.TLSSetting.LoadTLSConfig()
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions config/configgrpc/configgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestDefaultGrpcServerSettings(t *testing.T) {
func TestAllGrpcServerSettings(t *testing.T) {
gss := &GRPCServerSettings{
Endpoint: "localhost:1234",
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{},
ClientCAFile: "",
},
Expand Down Expand Up @@ -167,7 +167,7 @@ func TestGRPCServerSettingsError(t *testing.T) {
err: "^failed to load TLS config: failed to load CA CertPool: failed to load CA /doesnt/exist:",
settings: GRPCServerSettings{
Endpoint: "",
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CAFile: "/doesnt/exist",
},
Expand All @@ -179,7 +179,7 @@ func TestGRPCServerSettingsError(t *testing.T) {
err: "^failed to load TLS config: for auth via TLS, either both certificate and key must be supplied, or neither",
settings: GRPCServerSettings{
Endpoint: "",
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CertFile: "/doesnt/exist",
},
Expand All @@ -191,7 +191,7 @@ func TestGRPCServerSettingsError(t *testing.T) {
err: "^failed to load TLS config: failed to load client CA CertPool: failed to load CA /doesnt/exist:",
settings: GRPCServerSettings{
Endpoint: "",
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
ClientCAFile: "/doesnt/exist",
},
},
Expand All @@ -208,7 +208,7 @@ func TestGRPCServerSettingsError(t *testing.T) {
func TestGRPCServerSettings_ToListener_Error(t *testing.T) {
settings := GRPCServerSettings{
Endpoint: "127.0.0.1:1234567",
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CertFile: "/doesnt/exist",
},
Expand Down Expand Up @@ -341,8 +341,8 @@ func TestHttpReception(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gss := &GRPCServerSettings{
Endpoint: "localhost:0",
TLSCredentials: tt.tlsServerCreds,
Endpoint: "localhost:0",
TLSSetting: tt.tlsServerCreds,
}
ln, err := gss.ToListener()
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion config/configprotocol/configprotocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ type ProtocolServerSettings struct {

// Configures the protocol to use TLS.
// The default value is nil, which will cause the protocol to not use TLS.
TLSCredentials *configtls.TLSServerSetting `mapstructure:"tls_credentials, omitempty"`
TLSSettings *configtls.TLSServerSetting `mapstructure:"tls_settings, omitempty"`
}
4 changes: 2 additions & 2 deletions receiver/jaegerreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ documented [here](./config.go).
## Communicating over TLS
The Jaeger receiver supports communication using Transport Layer Security (TLS), but
only using the gRPC protocol. It can be configured by specifying a
`tls_credentials` object in the gRPC receiver configuration.
`tls_settings` object in the gRPC receiver configuration.
```yaml
receivers:
jaeger:
protocols:
grpc:
tls_credentials:
tls_settings:
key_file: /key.pem # path to private key
cert_file: /cert.pem # path to certificate
endpoint: "0.0.0.0:9876"
Expand Down
2 changes: 1 addition & 1 deletion receiver/jaegerreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestLoadConfig(t *testing.T) {
Protocols: Protocols{
GRPC: &configgrpc.GRPCServerSettings{
Endpoint: "localhost:9876",
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CertFile: "/test.crt",
KeyFile: "/test.key",
Expand Down
2 changes: 1 addition & 1 deletion receiver/jaegerreceiver/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestCreateTLSGPRCEndpoint(t *testing.T) {

cfg.(*Config).Protocols.GRPC = &configgrpc.GRPCServerSettings{
Endpoint: defaultGRPCBindEndpoint,
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CertFile: "./testdata/certificate.pem",
KeyFile: "./testdata/key.pem",
Expand Down
2 changes: 1 addition & 1 deletion receiver/jaegerreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ receivers:
jaeger/tls:
protocols:
grpc:
tls_credentials:
tls_settings:
cert_file: /test.crt
key_file: /test.key
endpoint: "localhost:9876"
Expand Down
4 changes: 2 additions & 2 deletions receiver/opencensusreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ with detailed sample configurations [here](./testdata/config.yaml).
## Communicating over TLS
This receiver supports communication using Transport Layer Security (TLS). TLS
can be configured by specifying a `tls_credentials` object in the receiver
can be configured by specifying a `tls_settings` object in the receiver
configuration for receivers that support it.
```yaml
receivers:
opencensus:
tls_credentials:
tls_settings:
key_file: /key.pem # path to private key
cert_file: /cert.pem # path to certificate
```
Expand Down
6 changes: 3 additions & 3 deletions receiver/opencensusreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestLoadConfig(t *testing.T) {
GRPCServerSettings: configgrpc.GRPCServerSettings{
Endpoint: "0.0.0.0:55678",
ReadBufferSize: 512 * 1024,
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CertFile: "test.crt",
KeyFile: "test.key",
Expand Down Expand Up @@ -165,7 +165,7 @@ func TestBuildOptions_TLSCredentials(t *testing.T) {
NameVal: "IncorrectTLS",
},
GRPCServerSettings: configgrpc.GRPCServerSettings{
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CertFile: "willfail",
},
Expand All @@ -175,7 +175,7 @@ func TestBuildOptions_TLSCredentials(t *testing.T) {
_, err := cfg.buildOptions()
assert.EqualError(t, err, `failed to load TLS config: for auth via TLS, either both certificate and key must be supplied, or neither`)

cfg.TLSCredentials = &configtls.TLSServerSetting{}
cfg.TLSSetting = &configtls.TLSServerSetting{}
opt, err := cfg.buildOptions()
assert.NoError(t, err)
assert.NotNil(t, opt)
Expand Down
2 changes: 1 addition & 1 deletion receiver/opencensusreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ receivers:
# The following entry demonstrates how to specify TLS credentials for the server.
# Note: These files do not exist. If the receiver is started with this configuration, it will fail.
opencensus/tlscredentials:
tls_credentials:
tls_settings:
cert_file: test.crt
key_file: test.key
# The following entry demonstrates how to specify a Unix Domain Socket for the server.
Expand Down
4 changes: 2 additions & 2 deletions receiver/otlpreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ receivers:
## Communicating over TLS
This receiver supports communication using Transport Layer Security (TLS). TLS
can be configured by specifying a `tls_credentials` object in the receiver
can be configured by specifying a `tls_settings` object in the receiver
configuration for receivers that support it.
```yaml
receivers:
otlp:
protocols:
grpc:
tls_credentials:
tls_settings:
key_file: /key.pem # path to private key
cert_file: /cert.pem # path to certificate
```
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func TestLoadConfig(t *testing.T) {
Protocols: Protocols{
GRPC: &configgrpc.GRPCServerSettings{
Endpoint: "0.0.0.0:55680",
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CertFile: "test.crt",
KeyFile: "test.key",
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func TestGRPCInvalidTLSCredentials(t *testing.T) {
Protocols: Protocols{
GRPC: &configgrpc.GRPCServerSettings{
Endpoint: "localhost:50000",
TLSCredentials: &configtls.TLSServerSetting{
TLSSetting: &configtls.TLSServerSetting{
TLSSetting: configtls.TLSSetting{
CertFile: "willfail",
},
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ receivers:
otlp/tlscredentials:
protocols:
grpc:
tls_credentials:
tls_settings:
cert_file: test.crt
key_file: test.key
http:
Expand Down

0 comments on commit 28d10c8

Please sign in to comment.