mirror of
https://github.com/crazy-max/diun.git
synced 2025-12-21 13:23:09 +01:00
Add TLS config options for notifiers using HTTP client
This commit is contained in:
25
pkg/utl/http.go
Normal file
25
pkg/utl/http.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package utl
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"os"
|
||||
)
|
||||
|
||||
func LoadTLSConfig(insecureSkipVerify bool, caCertFiles []string) (*tls.Config, error) {
|
||||
tlsConfig := &tls.Config{
|
||||
InsecureSkipVerify: insecureSkipVerify,
|
||||
}
|
||||
if len(caCertFiles) > 0 {
|
||||
certPool := x509.NewCertPool()
|
||||
for _, caCertFile := range caCertFiles {
|
||||
caCert, err := os.ReadFile(caCertFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
certPool.AppendCertsFromPEM(caCert)
|
||||
}
|
||||
tlsConfig.RootCAs = certPool
|
||||
}
|
||||
return tlsConfig, nil
|
||||
}
|
||||
Reference in New Issue
Block a user