31 lines
785 B
Go
31 lines
785 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
// Apply to every JSON response, including writes that return configuration views.
|
|
type tokenResponseWriter struct{ http.ResponseWriter }
|
|
|
|
func redactTokenResponse(v any) {
|
|
switch value := v.(type) {
|
|
case map[string]any:
|
|
for k, child := range value {
|
|
switch strings.ToLower(k) {
|
|
case "password", "targetpassword", "gatewaypassword", "privatekey", "passphrase", "hostkey", "kubeconfig", "kubeconfigcontent", "webhookurl", "webhooksecret", "secret":
|
|
// Presence flags in secretStatus are safe and retain their boolean type.
|
|
if _, flag := child.(bool); !flag {
|
|
value[k] = ""
|
|
}
|
|
default:
|
|
redactTokenResponse(child)
|
|
}
|
|
}
|
|
case []any:
|
|
for _, child := range value {
|
|
redactTokenResponse(child)
|
|
}
|
|
}
|
|
}
|