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 ...@@ -2,49 +2,54 @@ module API
class Unleash < Grape::API class Unleash < Grape::API
include PaginationParams include PaginationParams
resource :feature_flags do namespace :feature_flags do
resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do resource :unleash, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
params 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 end
route_param :id do route_param :project_id do
resource :unleash do before do
before do authenticate_by_unleash_access_token!
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
end end
end
end
helpers do get 'features' do
def project present project, with: ::EE::API::Entities::UnleashFeatures
@project ||= find_project(params[:id]) end
end
def unleash_instanceid post 'client/register' do
params[:instanceid] || env[:HTTP_UNLEASH_INSTANCEID] # not supported yet
end status :ok
end
def authenticate_by_unleash_access_token! post 'client/metrics' do
unless Operations::FeatureFlagsAccessToken.find_by(token: unleash_instanceid, project: project) # not supported yet
unauthorized! status :ok
end end
end end
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
end end
...@@ -166,8 +166,8 @@ module API ...@@ -166,8 +166,8 @@ module API
## EE-specific API V4 endpoints START ## EE-specific API V4 endpoints START
mount ::EE::API::Boards mount ::EE::API::Boards
mount ::EE::API::GroupBoards mount ::EE::API::GroupBoards
mount ::API::Unleash mount ::API::Unleash
mount ::API::EpicIssues mount ::API::EpicIssues
mount ::API::Epics mount ::API::Epics
mount ::API::Geo 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