diff options
author | John Cai <jcai@gitlab.com> | 2020-06-15 23:43:44 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2020-06-15 23:43:44 +0300 |
commit | e4251a0f182ee7a89372863ed3fefe987f728df5 (patch) | |
tree | 27267d9272c6155f391f31e8bd92706c93eb9935 | |
parent | 5985ed4c28d1025099fdcc0e9f65fa03de68a29f (diff) |
wip
-rw-r--r-- | internal/metadata/featureflag/feature_flags.go | 8 | ||||
-rw-r--r-- | internal/metadata/featureflag/grpc_header.go | 29 |
2 files changed, 27 insertions, 10 deletions
diff --git a/internal/metadata/featureflag/feature_flags.go b/internal/metadata/featureflag/feature_flags.go index b302fe076..40440b0f9 100644 --- a/internal/metadata/featureflag/feature_flags.go +++ b/internal/metadata/featureflag/feature_flags.go @@ -6,12 +6,6 @@ const ( UploadPackFilter = "upload_pack_filter" // LinguistFileCountStats will invoke an additional git-linguist command to get the number of files per language LinguistFileCountStats = "linguist_file_count_stats" - // HooksRPC will invoke update, pre receive, and post receive hooks by using RPCs - HooksRPC = "hooks_rpc" - // GitalyRubyCallHookRPC will invoke update, pre receive, and post receive hooks from the operations service by using RPCs - // note: there doesn't need to be a separate gitaly ruby feature flag name. The same featureflag string can be used for both the go code - // and being passed into gitaly-ruby - GitalyRubyCallHookRPC = "call_hook_rpc" // GoUpdateHook will bypass the ruby update hook and use the go implementation of custom hooks GoUpdateHook = "go_update_hook" // RemoteBranchesLsRemote will use `ls-remote` for remote branches @@ -25,8 +19,6 @@ const ( ) const ( - // HooksRPCEnvVar is the name of the environment variable we use to pass the feature flag down into gitaly-hooks - HooksRPCEnvVar = "GITALY_HOOK_RPCS_ENABLED" GoUpdateHookEnvVar = "GITALY_GO_UPDATE" GoPreReceiveHookEnvVar = "GITALY_GO_PRERECEIVE" ) diff --git a/internal/metadata/featureflag/grpc_header.go b/internal/metadata/featureflag/grpc_header.go index 10a2472ec..28efde928 100644 --- a/internal/metadata/featureflag/grpc_header.go +++ b/internal/metadata/featureflag/grpc_header.go @@ -49,9 +49,34 @@ func isEnabled(ctx context.Context, flag string) bool { return len(val) > 0 && val[0] == "true" } -// IsDisabled is the inverse operation of IsEnabled +func getFlagVal(ctx context.Context, flag string) (bool, string) { + if flag == "" { + return false, "" + } + + md, ok := metadata.FromIncomingContext(ctx) + if !ok { + return false, "" + } + + val, ok := md[HeaderKey(flag)] + if !ok { + return false, "" + } + + return true, val[0] +} + +// IsDisabled checks if the feature flag is explicitly disabled for the passed context. +// Only return true if the metadata for the feature flag is set to "false" +// For non-explicit disable, use !IsEnabled func IsDisabled(ctx context.Context, flag string) bool { - return !IsEnabled(ctx, flag) + ok, val := getFlagVal(ctx, flag) + if !ok { + return false + } + + return val == "false" } const ffPrefix = "gitaly-feature-" |