MCPcopy Create free account
hub / github.com/prometheus/common / LoadTLSConfig

Function LoadTLSConfig

config/tls_config_test.go:31–52  ·  view source on GitHub ↗

LoadTLSConfig parses the given file into a tls.Config.

(filename string)

Source from the content-addressed store, hash-verified

29
30// LoadTLSConfig parses the given file into a tls.Config.
31func LoadTLSConfig(filename string) (*tls.Config, error) {
32 content, err := os.ReadFile(filename)
33 if err != nil {
34 return nil, err
35 }
36 cfg := TLSConfig{}
37 switch filepath.Ext(filename) {
38 case ".yml":
39 if err = yaml.UnmarshalStrict(content, &cfg); err != nil {
40 return nil, err
41 }
42 case ".json":
43 decoder := json.NewDecoder(bytes.NewReader(content))
44 decoder.DisallowUnknownFields()
45 if err = decoder.Decode(&cfg); err != nil {
46 return nil, err
47 }
48 default:
49 return nil, fmt.Errorf("Unknown extension: %s", filepath.Ext(filename))
50 }
51 return NewTLSConfig(&cfg)
52}
53
54var expectedTLSConfigs = []struct {
55 filename string

Callers 2

TestValidTLSConfigFunction · 0.85
TestInvalidTLSConfigFunction · 0.85

Calls 2

DecodeMethod · 0.95
NewTLSConfigFunction · 0.85

Tested by

no test coverage detected