34 lines
802 B
Go
34 lines
802 B
Go
package mxgateway
|
|
|
|
import "strings"
|
|
|
|
// Options configures future gateway connections.
|
|
type Options struct {
|
|
Endpoint string
|
|
APIKey string
|
|
Plaintext bool
|
|
CACertFile string
|
|
ServerNameOverride string
|
|
}
|
|
|
|
// RedactedAPIKey returns a display-safe representation of the configured API
|
|
// key for diagnostics and CLI output.
|
|
func (o Options) RedactedAPIKey() string {
|
|
return RedactAPIKey(o.APIKey)
|
|
}
|
|
|
|
// RedactAPIKey hides credential material while keeping enough shape for
|
|
// troubleshooting whether a key was supplied.
|
|
func RedactAPIKey(apiKey string) string {
|
|
if apiKey == "" {
|
|
return ""
|
|
}
|
|
|
|
if len(apiKey) <= 8 {
|
|
return "<redacted>"
|
|
}
|
|
|
|
prefix, suffix := apiKey[:4], apiKey[len(apiKey)-4:]
|
|
return prefix + strings.Repeat("*", len(apiKey)-8) + suffix
|
|
}
|