Commit 4643d944 authored by Kamil Trzciński's avatar Kamil Trzciński

Fix after code review

parent 95ed2c38
......@@ -1959,7 +1959,7 @@ ActiveRecord::Schema.define(version: 20180926140319) do
t.string "token", null: false
end
add_index "operations_feature_flags_clients", ["token"], name: "index_operations_feature_flags_clients_on_token", unique: true, using: :btree
add_index "operations_feature_flags_clients", ["project_id", "token"], name: "index_operations_feature_flags_clients_on_project_id_and_token", unique: true, using: :btree
create_table "packages_maven_metadata", id: :bigserial, force: :cascade do |t|
t.integer "package_id", limit: 8, null: false
......
# frozen_string_literal: true
module FeatureFlagsHelper
include ::API::Helpers::RelatedResourcesHelpers
def unleash_api_url(project)
"#{root_url(only_path: false)}api/v4/feature_flags/unleash/#{project.id}"
expose_url(api_v4_feature_flags_unleash_path(project_id: project.id))
end
def unleash_api_instanceid(project)
def unleash_api_instance_id(project)
project.feature_flags_client_token
end
end
......@@ -33,7 +33,7 @@
= label_tag :instance_id, s_('FeatureFlags|Instance ID'), class: 'label-bold'
.input-group
= text_field_tag :instance_id,
unleash_api_instanceid(@project),
unleash_api_instance_id(@project),
readonly: true,
class: "form-control js-select-on-focus"
%span.input-group-append
......
#error_explanation
.alert.alert-danger
- @feature_flag.errors.full_messages.each do |msg|
%p= msg
- @feature_flag.errors.full_messages.each do |message|
%p= message
......@@ -23,7 +23,7 @@ class AddFeatureFlagsToProjects < ActiveRecord::Migration
t.integer :project_id, null: false
t.string :token, null: false
t.index :token, unique: true
t.index [:project_id, :token], unique: true
t.foreign_key :projects, column: :project_id, on_delete: :cascade
end
......
......@@ -6,14 +6,19 @@ module API
resource :unleash, requirements: API::PROJECT_ENDPOINT_REQUIREMENTS do
params do
requires :project_id, type: String, desc: 'The ID of a project'
optional :instanceid, type: String, desc: 'The Instance ID of Unleash Client'
optional :instance_id, type: String, desc: 'The Instance ID of Unleash Client'
end
route_param :project_id do
before do
authorize_by_unleash_instanceid!
authorize_by_unleash_instance_id!
authorize_feature_flags_feature!
end
get do
# not supported yet
status :ok
end
get 'features' do
present project, with: ::EE::API::Entities::UnleashFeatures
end
......@@ -36,13 +41,13 @@ module API
@project ||= find_project(params[:project_id])
end
def unleash_instanceid
params[:instanceid] || env['HTTP_UNLEASH_INSTANCEID']
def unleash_instance_id
params[:instance_id] || env['HTTP_UNLEASH_INSTANCEID']
end
def authorize_by_unleash_instanceid!
def authorize_by_unleash_instance_id!
unauthorized! unless Operations::FeatureFlagsClient
.find_for_project_and_token(project, unleash_instanceid)
.find_for_project_and_token(project, unleash_instance_id)
end
def authorize_feature_flags_feature!
......
require 'spec_helper'
describe Projects::FeatureFlagsController do
include Rails.application.routes.url_helpers
include Gitlab::Routing
set(:user) { create(:user) }
set(:project) { create(:project) }
......
......@@ -9,8 +9,8 @@ describe FeatureFlagsHelper do
it { is_expected.to end_with("/api/v4/feature_flags/unleash/#{project.id}") }
end
context '#unleash_api_instanceid' do
subject { helper.unleash_api_instanceid(project) }
context '#unleash_api_instance_id' do
subject { helper.unleash_api_instance_id(project) }
it { is_expected.not_to be_empty }
end
......
......@@ -12,9 +12,9 @@ describe API::Unleash do
end
shared_examples 'authenticated request' do
context 'when using instanceid' do
context 'when using instance id' do
let(:client) { create(:operations_feature_flags_client, project: project) }
let(:params) { { instanceid: client.token } }
let(:params) { { instance_id: client.token } }
it 'responds with OK' do
subject
......@@ -44,8 +44,8 @@ describe API::Unleash do
end
end
context 'when using bogus instanceid' do
let(:params) { { instanceid: 'token' } }
context 'when using bogus instance id' do
let(:params) { { instance_id: 'token' } }
it 'responds with unauthorized' do
subject
......@@ -56,7 +56,7 @@ describe API::Unleash do
context 'when using not existing project' do
let(:project_id) { -5000 }
let(:params) { { instanceid: 'token' } }
let(:params) { { instance_id: 'token' } }
it 'responds with unauthorized' do
subject
......
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