Skip to content

Commit

Permalink
comments and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
seankhliao committed Oct 19, 2022
1 parent 46817ba commit 0407417
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -11,6 +11,16 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
### Added

- Prometheus exporter will register with a prometheus registerer on creation, there are options to control this. (#3239)
- OTLP exporters now recognize:
- `OTEL_EXPORTER_OTLP_INSECURE`
- `OTEL_EXPORTER_OTLP_TRACES_INSECURE`
- `OTEL_EXPORTER_OTLP_METRICS_INSECURE`
- `OTEL_EXPORTER_OTLP_CLIENT_KEY`
- `OTEL_EXPORTER_OTLP_TRACES_CLIENT_KEY`
- `OTEL_EXPORTER_OTLP_METRICS_CLIENT_KEY`
- `OTEL_EXPORTER_OTLP_CLIENT_CERTIFICATE`
- `OTEL_EXPORTER_OTLP_TRACES_CLIENT_CERTIFICATE`
- `OTEL_EXPORTER_OTLP_METRICS_CLIENT_CERTIFICATE`

### Changed

Expand Down
10 changes: 6 additions & 4 deletions exporters/otlp/internal/envconfig/envconfig.go
Expand Up @@ -63,9 +63,8 @@ func WithString(n string, fn func(string)) func(e *EnvOptionsReader) {
func WithBool(n string, fn func(bool)) func(e *EnvOptionsReader) {
return func(e *EnvOptionsReader) {
if v, ok := e.GetEnvValue(n); ok {
if b, err := strconv.ParseBool(v); err == nil {
fn(b)
}
b := strings.ToLower(v) == "true"
fn(b)
}
}
}
Expand Down Expand Up @@ -101,7 +100,8 @@ func WithURL(n string, fn func(*url.URL)) func(e *EnvOptionsReader) {
}
}

// WithTLSConfig retrieves the specified config and passes it to ConfigFn as a crypto/tls.Config.
// WithCertPool retrieves the specified config and passes it to ConfigFn as a crypto/x509.CertPool
// constructed from reading the certificate at the given path.
func WithCertPool(n string, fn func(*x509.CertPool)) func(e *EnvOptionsReader) {
return func(e *EnvOptionsReader) {
if v, ok := e.GetEnvValue(n); ok {
Expand All @@ -114,6 +114,8 @@ func WithCertPool(n string, fn func(*x509.CertPool)) func(e *EnvOptionsReader) {
}
}

// WithCertPool retrieves the specified configs and passes it to ConfigFn as a crypto/tls.Certificate
// constructed from reading the key pair at the given paths. Both files must exist.
func WithClientCert(nc, nk string, fn func(tls.Certificate)) func(e *EnvOptionsReader) {
return func(e *EnvOptionsReader) {
vc, okc := e.GetEnvValue(nc)
Expand Down
24 changes: 23 additions & 1 deletion exporters/otlp/internal/envconfig/envconfig_test.go
Expand Up @@ -188,7 +188,11 @@ func TestEnvConfig(t *testing.T) {
options = append(options, testOption{TestBool: b})
}),
},
expectedOptions: []testOption{},
expectedOptions: []testOption{
{
TestBool: false,
},
},
},
{
name: "with a duration config",
Expand Down Expand Up @@ -382,6 +386,24 @@ func TestWithClientCert(t *testing.T) {
}),
)
assert.Equal(t, cert, option.TestTLS.Certificates[0])

reader.ReadFile = func(s string) ([]byte, error) { return []byte{}, nil }
option.TestTLS = nil
reader.Apply(
WithClientCert("CLIENT_CERTIFICATE", "CLIENT_KEY", func(c tls.Certificate) {
option = testOption{TestTLS: &tls.Config{Certificates: []tls.Certificate{c}}}
}),
)
assert.Equal(t, nil, option.TestTLS.Certificates)

reader.GetEnv = func(s string) string { return "" }
option.TestTLS = nil
reader.Apply(
WithClientCert("CLIENT_CERTIFICATE", "CLIENT_KEY", func(c tls.Certificate) {
option = testOption{TestTLS: &tls.Config{Certificates: []tls.Certificate{c}}}
}),
)
assert.Equal(t, nil, option.TestTLS.Certificates)
}

func TestStringToHeader(t *testing.T) {
Expand Down

0 comments on commit 0407417

Please sign in to comment.