package check import ( "crypto/tls" "errors" "net" "strings" ) // TLS modes of services with optional encryption: "require" encrypts // without verifying the certificate, "verify" also verifies it. func validTLSMode(m string) bool { return m == "disable" || m == "require" || m == "verify" } // tlsFor returns the client TLS settings for mode, or nil for "disable". func tlsFor(mode, target string) *tls.Config { if mode == "disable" { return nil } host, _, _ := net.SplitHostPort(target) return &tls.Config{ServerName: host, InsecureSkipVerify: mode == "require"} //nolint:gosec // "require" encrypts without verifying, as chosen per monitor } // redact shortens err for customers and removes secrets some clients // repeat in their errors. Secrets shorter than four characters are left: // replacing them would garble the message while hiding little. func redact(err error, secrets ...string) string { var op *net.OpError if errors.As(err, &op) && op.Op == "dial" { return describeNetErr(err) } msg := err.Error() for _, s := range secrets { if len(s) >= 4 { msg = strings.ReplaceAll(msg, s, "***") } } return truncate(msg, 300) }