Implement OFREP compatible feature flag service (#105632)
* Add ofrep pkg * api server: Use namespace from request in case user is not authenticated * Add handlers to ofrep api builder * Add NewOpenFeatureService to initialize mt apiserver * allow specifying CA and insecure * Compare namespace with eval ctx stackID * Organize ofrep package * Implement AllowedV0Alpha1Resources * Revert folderimpl changes * Handle default namespace * Fix extracting stack id from eval ctx * Add more logs * Update pkg/registry/apis/ofrep/register.go Co-authored-by: Dave Henderson <dave.henderson@grafana.com> * Update pkg/registry/apis/ofrep/register.go Co-authored-by: Dave Henderson <dave.henderson@grafana.com> * Apply review feedback * Replace contexthandler with types * Fix identifying authed request * Refactor checks in the handlers * Remove anonymous from isAuthenticatedRequest check --------- Co-authored-by: Todd Treece <360020+toddtreece@users.noreply.github.com> Co-authored-by: Gabriel Mabille <gabriel.mabille@grafana.com> Co-authored-by: Charandas Batra <charandas.batra@grafana.com> Co-authored-by: Dave Henderson <dave.henderson@grafana.com>
This commit is contained in:
co-authored by
Dave Henderson
Todd Treece
Gabriel Mabille
Charandas Batra
parent
45dabd2862
commit
67a952c34e
@@ -0,0 +1,41 @@
|
||||
package ofrep
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/featuremgmt"
|
||||
)
|
||||
|
||||
func (b *APIBuilder) evalAllFlagsStatic(isAuthedUser bool, w http.ResponseWriter, r *http.Request) {
|
||||
result, err := b.staticEvaluator.EvalAllFlags(r.Context())
|
||||
if err != nil {
|
||||
b.logger.Error("Failed to evaluate all static flags", "error", err)
|
||||
http.Error(w, "failed to evaluate flags", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if !isAuthedUser {
|
||||
var publicOnly []featuremgmt.OFREPFlag
|
||||
|
||||
for _, flag := range result.Flags {
|
||||
if isPublicFlag(flag.Key) {
|
||||
publicOnly = append(publicOnly, flag)
|
||||
}
|
||||
}
|
||||
|
||||
result.Flags = publicOnly
|
||||
}
|
||||
|
||||
writeResponse(http.StatusOK, result, b.logger, w)
|
||||
}
|
||||
|
||||
func (b *APIBuilder) evalFlagStatic(flagKey string, w http.ResponseWriter, r *http.Request) {
|
||||
result, err := b.staticEvaluator.EvalFlag(r.Context(), flagKey)
|
||||
if err != nil {
|
||||
b.logger.Error("Failed to evaluate static flag", "key", flagKey, "error", err)
|
||||
http.Error(w, "failed to evaluate flag", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
writeResponse(http.StatusOK, result, b.logger, w)
|
||||
}
|
||||
Reference in New Issue
Block a user