mirror of
https://github.com/hanzoai/metrics.git
synced 2026-10-30 20:03:39 +00:00
### Describe Your Changes The PR https://github.com/VictoriaMetrics/VictoriaMetrics/pull/9942 was reverted in https://github.com/VictoriaMetrics/VictoriaMetrics/commit/9f787f9582ca9aec8d159f825e20c32d47116707 because of the import cycle in the enterprise VM. Needs more work. ### Checklist The following checks are **mandatory**: - [ ] My change adheres to [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/victoriametrics/contributing/#pull-request-checklist). - [ ] My change adheres to [VictoriaMetrics development goals](https://docs.victoriametrics.com/victoriametrics/goals/).
35 lines
946 B
Go
35 lines
946 B
Go
package flagutil
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// RegisterSecretFlag registers flagName as secret.
|
|
//
|
|
// This function must be called before starting logging.
|
|
// It cannot be called from concurrent goroutines.
|
|
//
|
|
// Secret flags aren't exported at `/metrics` page.
|
|
func RegisterSecretFlag(flagName string) {
|
|
lname := strings.ToLower(flagName)
|
|
secretFlags[lname] = true
|
|
}
|
|
|
|
// UnregisterAllSecretFlags unregisters all secret flags.
|
|
//
|
|
// This function must be used in tests only.
|
|
// It cannot be called from concurrent goroutines.
|
|
func UnregisterAllSecretFlags() {
|
|
secretFlags = make(map[string]bool)
|
|
}
|
|
|
|
var secretFlags = make(map[string]bool)
|
|
|
|
// IsSecretFlag returns true of s contains flag name with secret value, which shouldn't be exposed.
|
|
func IsSecretFlag(s string) bool {
|
|
if strings.Contains(s, "pass") || strings.Contains(s, "key") || strings.Contains(s, "secret") || strings.Contains(s, "token") {
|
|
return true
|
|
}
|
|
return secretFlags[s]
|
|
}
|