mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-31 02:28:09 +00:00 
			
		
		
		
	 0ddc32f2ab
			
		
	
	0ddc32f2ab
	
	
	
		
			
			* Added sys/internal/ui/feature-flags endpoint. * Added documentation for new API endpoint. * Added integration test. Co-authored-by: swayne275 <swayne@hashicorp.com>
		
			
				
	
	
		
			53 lines
		
	
	
		
			995 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			53 lines
		
	
	
		
			995 B
		
	
	
	
		
			Go
		
	
	
	
	
	
| 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)
 | |
| 	})
 | |
| }
 |