Debian Codegraph @

internal/shared/otlp/otlpmetric/oconf/tls.go.tmpl

raw
1 // Code generated by gotmpl. DO NOT MODIFY.
2 // source: internal/shared/otlp/otlpmetric/oconf/tls.go.tmpl
3
4 // Copyright The OpenTelemetry Authors
5 // SPDX-License-Identifier: Apache-2.0
6
7 package oconf
8
9 import (
10 "crypto/tls"
11 "crypto/x509"
12 "errors"
13 "os"
14 )
15
16 // ReadTLSConfigFromFile reads a PEM certificate file and creates
17 // a tls.Config that will use this certificate to verify a server certificate.
18 func ReadTLSConfigFromFile(path string) (*tls.Config, error) {
19 b, err := os.ReadFile(path)
20 if err != nil {
21 return nil, err
22 }
23
24 return CreateTLSConfig(b)
25 }
26
27 // CreateTLSConfig creates a tls.Config from a raw certificate bytes
28 // to verify a server certificate.
29 func CreateTLSConfig(certBytes []byte) (*tls.Config, error) {
30 cp := x509.NewCertPool()
31 if ok := cp.AppendCertsFromPEM(certBytes); !ok {
32 return nil, errors.New("failed to append certificate to the cert pool")
33 }
34
35 return &tls.Config{
36 RootCAs: cp,
37 }, nil
38 }