Commit 65891560 authored by Kamil Trzciński's avatar Kamil Trzciński

Put Unleash API interface in `/api/v4`

The Unleash API is mounted in:
/api/v4/feature_flags/unleash/:project_id/
parent f8a140c8
......@@ -2,49 +2,54 @@ module API
class Unleash < Grape::API
include PaginationParams
resource :feature_flags do
resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
namespace :feature_flags do
resource :unleash, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
params do
requires :id, type: String, desc: 'The ID of a project'
requires :project_id, type: String, desc: 'The ID of a project'
optional :instanceid, type: String, desc: 'The Instance ID of Unleash Client'
end
route_param :id do
resource :unleash do
before do
authenticate_by_unleash_access_token!
end
get 'features' do
present project, with: Entities::UnleashFeatures
end
post 'client/register' do
# not supported yet
status :ok
end
post 'client/metrics' do
# not supported yet
status :ok
end
route_param :project_id do
before do
authenticate_by_unleash_access_token!
end
end
end
helpers do
def project
@project ||= find_project(params[:id])
end
get 'features' do
present project, with: ::EE::API::Entities::UnleashFeatures
end
def unleash_instanceid
params[:instanceid] || env[:HTTP_UNLEASH_INSTANCEID]
end
post 'client/register' do
# not supported yet
status :ok
end
def authenticate_by_unleash_access_token!
unless Operations::FeatureFlagsAccessToken.find_by(token: unleash_instanceid, project: project)
unauthorized!
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_instanceid
params[:instanceid] || env[:HTTP_UNLEASH_INSTANCEID]
end
def unleash_access_token
return unless unleash_instanceid
return unless project
@unleash_access_token ||= Operations::FeatureFlagsAccessToken.find_by(
token: unleash_instanceid, project: project)
end
def authenticate_by_unleash_access_token!
unauthorized! unless unleash_access_token
end
end
end
end
......@@ -166,8 +166,8 @@ module API
## EE-specific API V4 endpoints START
mount ::EE::API::Boards
mount ::EE::API::GroupBoards
mount ::API::Unleash
mount ::API::EpicIssues
mount ::API::Epics
mount ::API::Geo
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment