summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/api.rb2
-rw-r--r--lib/api/feature_flags.rb50
-rw-r--r--lib/api/unleash.rb41
3 files changed, 51 insertions, 42 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 820f47d1d91..96acaf0d502 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -99,6 +99,7 @@ module API
mount ::API::Environments
mount ::API::Events
mount ::API::Features
+ mount ::API::FeatureFlags
mount ::API::Files
mount ::API::GroupBoards
mount ::API::GroupMilestones
@@ -146,7 +147,6 @@ module API
mount ::API::Templates
mount ::API::Todos
mount ::API::Triggers
- mount ::API::Unleash
mount ::API::Users
mount ::API::Variables
mount ::API::Version
diff --git a/lib/api/feature_flags.rb b/lib/api/feature_flags.rb
new file mode 100644
index 00000000000..dff43544a75
--- /dev/null
+++ b/lib/api/feature_flags.rb
@@ -0,0 +1,50 @@
+module API
+ class FeatureFlags < Grape::API
+ include PaginationParams
+
+ resource :feature_flags do
+ resource :projects, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
+ params do
+ requires :id, type: String, desc: 'The ID of a project'
+ 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
+ end
+ end
+ end
+
+ helpers do
+ def project
+ @project ||= find_project(params[:id])
+ end
+
+ def unleash_instanceid
+ params[:instanceid] || env[:HTTP_UNLEASH_INSTANCEID]
+ end
+
+ def authenticate_by_unleash_access_token!
+ unless Operations::FeatureFlagsAccessToken.find_by(token: unleash_instanceid, project: project)
+ unauthorized!
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/api/unleash.rb b/lib/api/unleash.rb
deleted file mode 100644
index e4f9d00d3ff..00000000000
--- a/lib/api/unleash.rb
+++ /dev/null
@@ -1,41 +0,0 @@
-module API
- class Unleash < Grape::API
- include PaginationParams
-
- before do
- unauthorized! unless access_token
- end
-
- get ':unleash/features' do
- present @project, with: Entities::UnleashFeatures
- end
-
- post 'unleash/client/register' do
- status :ok
- end
-
- post 'unleash/client/metrics' do
- status :ok
- end
-
- private
-
- helpers do
- def project
- @project ||= find_project(unleash_appname)
- end
-
- def access_token
- @access_token ||= ProjectFeatureFlagsAccessToken.find_by(token: unleash_instanceid, project: project)
- end
-
- def unleash_appname
- params[:appname] || env[:HTTP_UNLEASH_APPNAME]
- end
-
- def unleash_instanceid
- params[:instanceid] || env[:HTTP_UNLEASH_INSTANCEID]
- end
- end
- end
-end