Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/unleash.rb')
-rw-r--r--lib/api/unleash.rb33
1 files changed, 27 insertions, 6 deletions
diff --git a/lib/api/unleash.rb b/lib/api/unleash.rb
index 37fe540cde1..2d528ad47a2 100644
--- a/lib/api/unleash.rb
+++ b/lib/api/unleash.rb
@@ -25,14 +25,22 @@ module API
desc 'Get a list of features (deprecated, v2 client support)'
get 'features' do
- present :version, 1
- present :features, feature_flags, with: ::API::Entities::UnleashFeature
+ if ::Feature.enabled?(:cache_unleash_client_api, project)
+ present_feature_flags
+ else
+ present :version, 1
+ present :features, feature_flags, with: ::API::Entities::UnleashFeature
+ end
end
desc 'Get a list of features'
get 'client/features' do
- present :version, 1
- present :features, feature_flags, with: ::API::Entities::UnleashFeature
+ if ::Feature.enabled?(:cache_unleash_client_api, project)
+ present_feature_flags
+ else
+ present :version, 1
+ present :features, feature_flags, with: ::API::Entities::UnleashFeature
+ end
end
post 'client/register' do
@@ -49,10 +57,24 @@ module API
end
helpers do
+ def present_feature_flags
+ present_cached feature_flags_client,
+ with: ::API::Entities::Unleash::ClientFeatureFlags,
+ cache_context: -> (client) { client.unleash_api_cache_key }
+ end
+
def project
@project ||= find_project(params[:project_id])
end
+ def feature_flags_client
+ strong_memoize(:feature_flags_client) do
+ client = Operations::FeatureFlagsClient.find_for_project_and_token(project, unleash_instance_id)
+ client.unleash_app_name = unleash_app_name if client
+ client
+ end
+ end
+
def unleash_instance_id
env['HTTP_UNLEASH_INSTANCEID'] || params[:instance_id]
end
@@ -62,8 +84,7 @@ module API
end
def authorize_by_unleash_instance_id!
- unauthorized! unless Operations::FeatureFlagsClient
- .find_for_project_and_token(project, unleash_instance_id)
+ unauthorized! unless feature_flags_client
end
def feature_flags