diff --git a/pkg/registry/apis/ofrep/proxy.go b/pkg/registry/apis/ofrep/proxy.go index c75524272da..793a099339e 100644 --- a/pkg/registry/apis/ofrep/proxy.go +++ b/pkg/registry/apis/ofrep/proxy.go @@ -1,15 +1,20 @@ package ofrep import ( + "bytes" "crypto/tls" "crypto/x509" "encoding/json" "fmt" + "io" "net/http" "net/http/httputil" "os" "path" + "strconv" + "github.com/grafana/grafana/pkg/cmd/grafana-cli/logger" + "github.com/grafana/grafana/pkg/services/featuremgmt" "github.com/grafana/grafana/pkg/util/proxyutil" ) @@ -22,20 +27,31 @@ func (b *APIBuilder) proxyAllFlagReq(isAuthedUser bool, w http.ResponseWriter, r proxy.ModifyResponse = func(resp *http.Response) error { if resp.StatusCode == http.StatusOK && !isAuthedUser { - var result map[string]interface{} + var result featuremgmt.OFREPBulkResponse if err := json.NewDecoder(resp.Body).Decode(&result); err != nil { return err } _ = resp.Body.Close() - filtered := make(map[string]any) - for k, v := range result { - if isPublicFlag(k) { - filtered[k] = v + var filteredFlags []featuremgmt.OFREPFlag + for _, f := range result.Flags { + if isPublicFlag(f.Key) { + filteredFlags = append(filteredFlags, f) } } - writeResponse(http.StatusOK, filtered, b.logger, w) + result.Flags = filteredFlags + newBodyBytes, err := json.Marshal(result) + if err != nil { + logger.Error("Failed to encode filtered result", "error", err) + return err + } + + // Replace the body + resp.Body = io.NopCloser(bytes.NewReader(newBodyBytes)) + resp.ContentLength = int64(len(newBodyBytes)) + resp.Header.Set("Content-Length", strconv.Itoa(len(newBodyBytes))) + resp.Header.Set("Content-Type", "application/json") } return nil diff --git a/pkg/services/featuremgmt/static_evaluator.go b/pkg/services/featuremgmt/static_evaluator.go index 99f1f5e1b5d..1d4b05d9ece 100644 --- a/pkg/services/featuremgmt/static_evaluator.go +++ b/pkg/services/featuremgmt/static_evaluator.go @@ -98,7 +98,7 @@ type OFREPBulkResponse struct { // OFREPFlag represents a single flag in the bulk response type OFREPFlag struct { Key string `json:"key"` - Value bool `json:"value"` + Value any `json:"value"` Reason string `json:"reason"` Variant string `json:"variant,omitempty"` Metadata map[string]any `json:"metadata,omitempty"` diff --git a/pkg/services/featuremgmt/static_provider_test.go b/pkg/services/featuremgmt/static_provider_test.go index 1916890d169..d47711f6269 100644 --- a/pkg/services/featuremgmt/static_provider_test.go +++ b/pkg/services/featuremgmt/static_provider_test.go @@ -80,7 +80,7 @@ ABCD = true openFeatureEnabledFlags := map[string]bool{} for _, flag := range allFlags.Flags { - if flag.Value { + if v, ok := flag.Value.(bool); ok && v { openFeatureEnabledFlags[flag.Key] = true } }