debian-mirror-gitlab/lib/api/unleash.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

88 lines
2.5 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
module API
class Unleash < ::API::Base
include PaginationParams
2023-01-13 00:05:48 +05:30
unleash_tags = %w[unleash_api]
2021-01-29 00:20:46 +05:30
feature_category :feature_flags
2021-01-03 14:25:43 +05:30
namespace :feature_flags do
resource :unleash, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
params do
requires :project_id, type: String, desc: 'The ID of a project'
2023-01-13 00:05:48 +05:30
optional :instance_id, type: String, desc: 'The instance ID of Unleash Client'
optional :app_name, type: String, desc: 'The application name of Unleash Client'
2021-01-03 14:25:43 +05:30
end
route_param :project_id do
before do
authorize_by_unleash_instance_id!
end
get do
# not supported yet
status :ok
end
2023-01-13 00:05:48 +05:30
desc 'Get a list of features (deprecated, v2 client support)' do
is_array true
tags unleash_tags
end
get 'features', urgency: :low do
present_feature_flags
2021-01-03 14:25:43 +05:30
end
2022-08-27 11:52:29 +05:30
# We decrease the urgency of this endpoint until the maxmemory issue of redis-cache has been resolved.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/365575#note_1033611872 for more information.
2023-01-13 00:05:48 +05:30
desc 'Get a list of features' do
is_array true
tags unleash_tags
end
2022-08-27 11:52:29 +05:30
get 'client/features', urgency: :low do
2023-01-13 00:05:48 +05:30
present_feature_flags
2021-01-03 14:25:43 +05:30
end
post 'client/register' do
# not supported yet
status :ok
end
2023-01-13 00:05:48 +05:30
post 'client/metrics', urgency: :low do
2021-01-03 14:25:43 +05:30
# not supported yet
status :ok
end
end
end
end
helpers do
2022-08-13 15:12:31 +05:30
def present_feature_flags
present_cached feature_flags_client,
with: ::API::Entities::Unleash::ClientFeatureFlags,
cache_context: -> (client) { client.unleash_api_cache_key }
end
def feature_flags_client
strong_memoize(:feature_flags_client) do
2023-03-04 22:38:38 +05:30
client = Operations::FeatureFlagsClient.find_for_project_and_token(params[:project_id], unleash_instance_id)
2022-08-13 15:12:31 +05:30
client.unleash_app_name = unleash_app_name if client
client
end
end
2021-01-03 14:25:43 +05:30
def unleash_instance_id
env['HTTP_UNLEASH_INSTANCEID'] || params[:instance_id]
end
def unleash_app_name
env['HTTP_UNLEASH_APPNAME'] || params[:app_name]
end
def authorize_by_unleash_instance_id!
2022-08-13 15:12:31 +05:30
unauthorized! unless feature_flags_client
2021-01-03 14:25:43 +05:30
end
end
end
end