Commit 20b6f31d authored by Gabriel Mazetto's avatar Gabriel Mazetto

Merge branch 'disable-cert-based-cluster-api' into 'master'

Disable clusters API if :certificate_based_clusters is disabled

See merge request gitlab-org/gitlab!81867
parents f3a5ca4b 33c56fb6
...@@ -9,6 +9,7 @@ module API ...@@ -9,6 +9,7 @@ module API
before do before do
authenticated_as_admin! authenticated_as_admin!
ensure_feature_enabled!
end end
namespace 'admin' do namespace 'admin' do
...@@ -133,6 +134,10 @@ module API ...@@ -133,6 +134,10 @@ module API
def update_cluster_params def update_cluster_params
declared_params(include_missing: false).without(:cluster_id) declared_params(include_missing: false).without(:cluster_id)
end end
def ensure_feature_enabled!
not_found! unless Feature.enabled?(:certificate_based_clusters, clusterable_instance, default_enabled: :yaml, type: :ops)
end
end end
end end
end end
......
...@@ -4,7 +4,10 @@ module API ...@@ -4,7 +4,10 @@ module API
class GroupClusters < ::API::Base class GroupClusters < ::API::Base
include PaginationParams include PaginationParams
before { authenticate! } before do
authenticate!
ensure_feature_enabled!
end
feature_category :kubernetes_management feature_category :kubernetes_management
...@@ -133,6 +136,10 @@ module API ...@@ -133,6 +136,10 @@ module API
def update_cluster_params def update_cluster_params
declared_params(include_missing: false).without(:cluster_id) declared_params(include_missing: false).without(:cluster_id)
end end
def ensure_feature_enabled!
not_found! unless Feature.enabled?(:certificate_based_clusters, user_group, default_enabled: :yaml, type: :ops)
end
end end
end end
end end
...@@ -4,7 +4,10 @@ module API ...@@ -4,7 +4,10 @@ module API
class ProjectClusters < ::API::Base class ProjectClusters < ::API::Base
include PaginationParams include PaginationParams
before { authenticate! } before do
authenticate!
ensure_feature_enabled!
end
feature_category :kubernetes_management feature_category :kubernetes_management
...@@ -138,6 +141,10 @@ module API ...@@ -138,6 +141,10 @@ module API
def update_cluster_params def update_cluster_params
declared_params(include_missing: false).without(:cluster_id) declared_params(include_missing: false).without(:cluster_id)
end end
def ensure_feature_enabled!
not_found! unless Feature.enabled?(:certificate_based_clusters, user_project, default_enabled: :yaml, type: :ops)
end
end end
end end
end end
...@@ -21,6 +21,10 @@ RSpec.describe ::API::Admin::InstanceClusters do ...@@ -21,6 +21,10 @@ RSpec.describe ::API::Admin::InstanceClusters do
create_list(:cluster, 3, :provided_by_gcp, :instance, :production_environment) create_list(:cluster, 3, :provided_by_gcp, :instance, :production_environment)
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { get api("/admin/clusters", admin_user) }
end
context "when authenticated as a non-admin user" do context "when authenticated as a non-admin user" do
it 'returns 403' do it 'returns 403' do
get api('/admin/clusters', regular_user) get api('/admin/clusters', regular_user)
...@@ -62,6 +66,10 @@ RSpec.describe ::API::Admin::InstanceClusters do ...@@ -62,6 +66,10 @@ RSpec.describe ::API::Admin::InstanceClusters do
let(:cluster_id) { cluster.id } let(:cluster_id) { cluster.id }
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { get api("/admin/clusters/#{cluster_id}", admin_user) }
end
context "when authenticated as admin" do context "when authenticated as admin" do
before do before do
get api("/admin/clusters/#{cluster_id}", admin_user) get api("/admin/clusters/#{cluster_id}", admin_user)
...@@ -188,6 +196,10 @@ RSpec.describe ::API::Admin::InstanceClusters do ...@@ -188,6 +196,10 @@ RSpec.describe ::API::Admin::InstanceClusters do
} }
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { post api('/admin/clusters/add', admin_user), params: cluster_params }
end
context 'authorized user' do context 'authorized user' do
before do before do
post api('/admin/clusters/add', admin_user), params: cluster_params post api('/admin/clusters/add', admin_user), params: cluster_params
...@@ -317,6 +329,10 @@ RSpec.describe ::API::Admin::InstanceClusters do ...@@ -317,6 +329,10 @@ RSpec.describe ::API::Admin::InstanceClusters do
create(:cluster, :instance, :provided_by_gcp, domain: 'old-domain.com') create(:cluster, :instance, :provided_by_gcp, domain: 'old-domain.com')
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { put api("/admin/clusters/#{cluster.id}", admin_user), params: update_params }
end
context 'authorized user' do context 'authorized user' do
before do before do
put api("/admin/clusters/#{cluster.id}", admin_user), params: update_params put api("/admin/clusters/#{cluster.id}", admin_user), params: update_params
...@@ -448,6 +464,10 @@ RSpec.describe ::API::Admin::InstanceClusters do ...@@ -448,6 +464,10 @@ RSpec.describe ::API::Admin::InstanceClusters do
create(:cluster, :instance, :provided_by_gcp) create(:cluster, :instance, :provided_by_gcp)
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { delete api("/admin/clusters/#{cluster.id}", admin_user), params: cluster_params }
end
context 'authorized user' do context 'authorized user' do
before do before do
delete api("/admin/clusters/#{cluster.id}", admin_user), params: cluster_params delete api("/admin/clusters/#{cluster.id}", admin_user), params: cluster_params
......
...@@ -22,6 +22,10 @@ RSpec.describe API::GroupClusters do ...@@ -22,6 +22,10 @@ RSpec.describe API::GroupClusters do
groups: [group]) groups: [group])
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { get api("/groups/#{group.id}/clusters", current_user) }
end
context 'non-authorized user' do context 'non-authorized user' do
it 'responds with 403' do it 'responds with 403' do
get api("/groups/#{group.id}/clusters", unauthorized_user) get api("/groups/#{group.id}/clusters", unauthorized_user)
...@@ -66,6 +70,10 @@ RSpec.describe API::GroupClusters do ...@@ -66,6 +70,10 @@ RSpec.describe API::GroupClusters do
groups: [group]) groups: [group])
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { get api("/groups/#{group.id}/clusters/#{cluster_id}", current_user) }
end
context 'non-authorized user' do context 'non-authorized user' do
it 'responds with 403' do it 'responds with 403' do
get api("/groups/#{group.id}/clusters/#{cluster_id}", unauthorized_user) get api("/groups/#{group.id}/clusters/#{cluster_id}", unauthorized_user)
...@@ -181,6 +189,10 @@ RSpec.describe API::GroupClusters do ...@@ -181,6 +189,10 @@ RSpec.describe API::GroupClusters do
} }
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { post api("/groups/#{group.id}/clusters/user", current_user), params: cluster_params }
end
context 'non-authorized user' do context 'non-authorized user' do
it 'responds with 403' do it 'responds with 403' do
post api("/groups/#{group.id}/clusters/user", unauthorized_user), params: cluster_params post api("/groups/#{group.id}/clusters/user", unauthorized_user), params: cluster_params
...@@ -362,6 +374,10 @@ RSpec.describe API::GroupClusters do ...@@ -362,6 +374,10 @@ RSpec.describe API::GroupClusters do
groups: [group], domain: 'old-domain.com') groups: [group], domain: 'old-domain.com')
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { put api("/groups/#{group.id}/clusters/#{cluster.id}", current_user), params: update_params }
end
context 'non-authorized user' do context 'non-authorized user' do
it 'responds with 403' do it 'responds with 403' do
put api("/groups/#{group.id}/clusters/#{cluster.id}", unauthorized_user), params: update_params put api("/groups/#{group.id}/clusters/#{cluster.id}", unauthorized_user), params: update_params
...@@ -503,6 +519,10 @@ RSpec.describe API::GroupClusters do ...@@ -503,6 +519,10 @@ RSpec.describe API::GroupClusters do
groups: [group]) groups: [group])
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { delete api("/groups/#{group.id}/clusters/#{cluster.id}", current_user), params: cluster_params }
end
context 'non-authorized user' do context 'non-authorized user' do
it 'responds with 403' do it 'responds with 403' do
delete api("/groups/#{group.id}/clusters/#{cluster.id}", unauthorized_user), params: cluster_params delete api("/groups/#{group.id}/clusters/#{cluster.id}", unauthorized_user), params: cluster_params
......
...@@ -24,6 +24,10 @@ RSpec.describe API::ProjectClusters do ...@@ -24,6 +24,10 @@ RSpec.describe API::ProjectClusters do
projects: [project]) projects: [project])
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { get api("/projects/#{project.id}/clusters", developer_user) }
end
context 'non-authorized user' do context 'non-authorized user' do
it 'responds with 403' do it 'responds with 403' do
get api("/projects/#{project.id}/clusters", reporter_user) get api("/projects/#{project.id}/clusters", reporter_user)
...@@ -67,6 +71,10 @@ RSpec.describe API::ProjectClusters do ...@@ -67,6 +71,10 @@ RSpec.describe API::ProjectClusters do
projects: [project]) projects: [project])
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { get api("/projects/#{project.id}/clusters/#{cluster_id}", developer_user) }
end
context 'non-authorized user' do context 'non-authorized user' do
it 'responds with 403' do it 'responds with 403' do
get api("/projects/#{project.id}/clusters/#{cluster_id}", reporter_user) get api("/projects/#{project.id}/clusters/#{cluster_id}", reporter_user)
...@@ -182,6 +190,10 @@ RSpec.describe API::ProjectClusters do ...@@ -182,6 +190,10 @@ RSpec.describe API::ProjectClusters do
} }
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { post api("/projects/#{project.id}/clusters/user", maintainer_user), params: cluster_params }
end
context 'non-authorized user' do context 'non-authorized user' do
it 'responds with 403' do it 'responds with 403' do
post api("/projects/#{project.id}/clusters/user", developer_user), params: cluster_params post api("/projects/#{project.id}/clusters/user", developer_user), params: cluster_params
...@@ -361,6 +373,10 @@ RSpec.describe API::ProjectClusters do ...@@ -361,6 +373,10 @@ RSpec.describe API::ProjectClusters do
projects: [project]) projects: [project])
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { put api("/projects/#{project.id}/clusters/#{cluster.id}", maintainer_user), params: update_params }
end
context 'non-authorized user' do context 'non-authorized user' do
it 'responds with 403' do it 'responds with 403' do
put api("/projects/#{project.id}/clusters/#{cluster.id}", developer_user), params: update_params put api("/projects/#{project.id}/clusters/#{cluster.id}", developer_user), params: update_params
...@@ -493,6 +509,10 @@ RSpec.describe API::ProjectClusters do ...@@ -493,6 +509,10 @@ RSpec.describe API::ProjectClusters do
projects: [project]) projects: [project])
end end
include_examples ':certificate_based_clusters feature flag API responses' do
let(:subject) { delete api("/projects/#{project.id}/clusters/#{cluster.id}", maintainer_user), params: cluster_params }
end
context 'non-authorized user' do context 'non-authorized user' do
it 'responds with 403' do it 'responds with 403' do
delete api("/projects/#{project.id}/clusters/#{cluster.id}", developer_user), params: cluster_params delete api("/projects/#{project.id}/clusters/#{cluster.id}", developer_user), params: cluster_params
......
# frozen_string_literal: true
RSpec.shared_examples ':certificate_based_clusters feature flag API responses' do
context 'feature flag is disabled' do
before do
stub_feature_flags(certificate_based_clusters: false)
end
it 'responds with :not_found' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
end
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