package safemode
import (
"html"
"strings"
)
var exampleAPIKeys = map[string]struct{}{
"your-api-key-1": {},
"your-api-key-2": {},
"your-api-key-3": {},
}
// ExampleAPIKeys returns configured top-level API keys that still use template values.
func ExampleAPIKeys(keys []string) []string {
if len(keys) == 0 {
return nil
}
matches := make([]string, 0, len(keys))
seen := make(map[string]struct{}, len(exampleAPIKeys))
for _, key := range keys {
trimmed := strings.TrimSpace(key)
if _, ok := exampleAPIKeys[trimmed]; !ok {
continue
}
if _, exists := seen[trimmed]; exists {
continue
}
seen[trimmed] = struct{}{}
matches = append(matches, trimmed)
}
if len(matches) == 0 {
return nil
}
return matches
}
// HasExampleAPIKeys reports whether any configured top-level API key is a template value.
func HasExampleAPIKeys(keys []string) bool {
return len(ExampleAPIKeys(keys)) > 0
}
// ExampleAPIKeyWarningPageHTML returns the setup warning page HTML.
func ExampleAPIKeyWarningPageHTML(keys []string, managementPath string) string {
var b strings.Builder
b.WriteString(`
Example API key detectedExample API key detected
Proxy API endpoints are disabled because the top-level api-keys configuration still contains template values.
`)
if len(keys) > 0 {
b.WriteString(`Replace these values before using the proxy:
`)
for _, key := range keys {
b.WriteString(``)
b.WriteString(html.EscapeString(key))
b.WriteString(` `)
}
b.WriteString(`
`)
}
b.WriteString(`Set strong random API keys, then retry the proxy endpoint.
`)
if trimmed := strings.TrimSpace(managementPath); trimmed != "" {
b.WriteString(``)
}
b.WriteString(``)
return b.String()
}