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

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

77 lines
2 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
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'
optional :instance_id, type: String, desc: 'The Instance ID of Unleash Client'
optional :app_name, type: String, desc: 'The Application Name of Unleash Client'
end
route_param :project_id do
before do
authorize_by_unleash_instance_id!
end
get do
# not supported yet
status :ok
end
desc 'Get a list of features (deprecated, v2 client support)'
get 'features' do
present :version, 1
present :features, feature_flags, with: ::API::Entities::UnleashFeature
end
desc 'Get a list of features'
2022-07-16 23:28:13 +05:30
get 'client/features' do
2021-01-03 14:25:43 +05:30
present :version, 1
present :features, feature_flags, with: ::API::Entities::UnleashFeature
end
post 'client/register' do
# not supported yet
status :ok
end
post 'client/metrics' do
# not supported yet
status :ok
end
end
end
end
helpers do
def project
@project ||= find_project(params[:project_id])
end
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!
unauthorized! unless Operations::FeatureFlagsClient
.find_for_project_and_token(project, unleash_instance_id)
end
def feature_flags
return [] unless unleash_app_name.present?
2021-09-04 01:27:46 +05:30
Operations::FeatureFlag.for_unleash_client(project, unleash_app_name)
2021-01-03 14:25:43 +05:30
end
end
end
end