-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathsys_feature_flags.go
52 lines (42 loc) · 995 Bytes
/
sys_feature_flags.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package http
import (
"encoding/json"
"net/http"
"os"
"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")
w.WriteHeader(http.StatusOK)
// Generate the response
enc := json.NewEncoder(w)
enc.Encode(response)
})
}