Skip to content

Commit d26dad5

Browse files
committed
remove createTLSConfig, reuse refactored code
Signed-off-by: alex boten <[email protected]>
1 parent aa87f2f commit d26dad5

File tree

2 files changed

+0
-86
lines changed

2 files changed

+0
-86
lines changed

otelconf/config.go

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ package otelconf // import "go.opentelemetry.io/contrib/otelconf/v1.0.0-rc.1"
66

77
import (
88
"context"
9-
"crypto/tls"
10-
"crypto/x509"
119
"errors"
1210
"fmt"
13-
"os"
1411

1512
"go.opentelemetry.io/otel/baggage"
1613
"go.opentelemetry.io/otel/log"
@@ -194,33 +191,6 @@ func ParseYAML(file []byte) (*OpenTelemetryConfiguration, error) {
194191
return &cfg, nil
195192
}
196193

197-
// createTLSConfig creates a tls.Config from certificate files.
198-
func createTLSConfig(caCertFile, clientCertFile, clientKeyFile *string) (*tls.Config, error) {
199-
tlsConfig := &tls.Config{}
200-
if caCertFile != nil {
201-
caText, err := os.ReadFile(*caCertFile)
202-
if err != nil {
203-
return nil, err
204-
}
205-
certPool := x509.NewCertPool()
206-
if !certPool.AppendCertsFromPEM(caText) {
207-
return nil, errors.New("could not create certificate authority chain from certificate")
208-
}
209-
tlsConfig.RootCAs = certPool
210-
}
211-
if clientCertFile != nil {
212-
if clientKeyFile == nil {
213-
return nil, errors.New("client certificate was provided but no client key was provided")
214-
}
215-
clientCert, err := tls.LoadX509KeyPair(*clientCertFile, *clientKeyFile)
216-
if err != nil {
217-
return nil, fmt.Errorf("could not use client certificate: %w", err)
218-
}
219-
tlsConfig.Certificates = []tls.Certificate{clientCert}
220-
}
221-
return tlsConfig, nil
222-
}
223-
224194
// createHeadersConfig combines the two header config fields. Headers take precedence over headersList.
225195
func createHeadersConfig(headers []NameStringValuePair, headersList *string) (map[string]string, error) {
226196
result := make(map[string]string)

otelconf/config_test.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package otelconf
55

66
import (
7-
"crypto/tls"
87
"encoding/json"
98
"errors"
109
"os"
@@ -1242,61 +1241,6 @@ func TestUnmarshalPeriodicMetricReader(t *testing.T) {
12421241
})
12431242
}
12441243
}
1245-
func TestCreateTLSConfig(t *testing.T) {
1246-
tests := []struct {
1247-
name string
1248-
caCertFile *string
1249-
clientCertFile *string
1250-
clientKeyFile *string
1251-
wantErrContains string
1252-
want func(*tls.Config, *testing.T)
1253-
}{
1254-
{
1255-
name: "no-input",
1256-
want: func(result *tls.Config, t *testing.T) {
1257-
require.Nil(t, result.Certificates)
1258-
require.Nil(t, result.RootCAs)
1259-
},
1260-
},
1261-
{
1262-
name: "only-cacert-provided",
1263-
caCertFile: ptr(filepath.Join("..", "testdata", "ca.crt")),
1264-
want: func(result *tls.Config, t *testing.T) {
1265-
require.Nil(t, result.Certificates)
1266-
require.NotNil(t, result.RootCAs)
1267-
},
1268-
},
1269-
{
1270-
name: "nonexistent-cacert-file",
1271-
caCertFile: ptr("nowhere.crt"),
1272-
wantErrContains: "open nowhere.crt:",
1273-
},
1274-
{
1275-
name: "nonexistent-clientcert-file",
1276-
clientCertFile: ptr("nowhere.crt"),
1277-
clientKeyFile: ptr("nowhere.crt"),
1278-
wantErrContains: "could not use client certificate: open nowhere.crt:",
1279-
},
1280-
{
1281-
name: "bad-cacert-file",
1282-
caCertFile: ptr(filepath.Join("..", "testdata", "bad_cert.crt")),
1283-
wantErrContains: "could not create certificate authority chain from certificate",
1284-
},
1285-
}
1286-
1287-
for _, tt := range tests {
1288-
t.Run(tt.name, func(t *testing.T) {
1289-
got, err := createTLSConfig(tt.caCertFile, tt.clientCertFile, tt.clientKeyFile)
1290-
1291-
if tt.wantErrContains != "" {
1292-
require.Contains(t, err.Error(), tt.wantErrContains)
1293-
} else {
1294-
require.NoError(t, err)
1295-
tt.want(got, t)
1296-
}
1297-
})
1298-
}
1299-
}
13001244

13011245
func TestUnmarshalCardinalityLimits(t *testing.T) {
13021246
for _, tt := range []struct {

0 commit comments

Comments
 (0)