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

Function LoadTLSConfig

config/tls_config_test.go:33–54  ·  view source on GitHub ↗

LoadTLSConfig parses the given file into a tls.Config.

(filename string)

Source from the content-addressed store, hash-verified

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

Callers 2

TestValidTLSConfigFunction · 0.85
TestInvalidTLSConfigFunction · 0.85

Calls 2

DecodeMethod · 0.95
NewTLSConfigFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…