vault/http/sys_feature_flags.go
Violet Hynes 664dfbe838
VAULT-35384 Add new telemetry metrics for HTTP response status codes (#30354)
* VAULT-35384 Add new telemetry metrics for HTTP status codes

* VAULT-35384 Add new telemetry metrics for HTTP status codes

* Changelog

* Changelog

* Typo

* Missed metrics

* VAULT-35384 sys/health
2025-05-06 10:15:19 -04:00

58 lines
1.1 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package http
import (
"encoding/json"
"net/http"
"os"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
)
type FeatureFlagsResponse struct {
FeatureFlags []string `json:"feature_flags"`
}
var FeatureFlag_EnvVariables = [...]string{
"VAULT_CLOUD_ADMIN_NAMESPACE",
}
func featureFlagIsSet(name string) bool {
switch os.Getenv(name) {
case "", "0":
return false
default:
return true
}
}
func handleSysInternalFeatureFlags(core *vault.Core) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
break
default:
respondError(w, http.StatusMethodNotAllowed, nil)
}
response := &FeatureFlagsResponse{}
for _, f := range FeatureFlag_EnvVariables {
if featureFlagIsSet(f) {
response.FeatureFlags = append(response.FeatureFlags, f)
}
}
w.Header().Set("Content-Type", "application/json")
defer logical.IncrementResponseStatusCodeMetric(http.StatusOK)
w.WriteHeader(http.StatusOK)
// Generate the response
enc := json.NewEncoder(w)
enc.Encode(response)
})
}