Commit d94d185c authored by orozot's avatar orozot Committed by Michael Kozono

Add harbor_registry_integration feature flag

Issue: https://gitlab.com/gitlab-org/gitlab/-/issues/353595
parent 6fd529f6
# frozen_string_literal: true
module Groups
module Harbor
class RepositoriesController < Groups::ApplicationController
feature_category :integrations
before_action :harbor_registry_enabled!
before_action do
push_frontend_feature_flag(:harbor_registry_integration)
end
def show
render :index
end
private
def harbor_registry_enabled!
render_404 unless Feature.enabled?(:harbor_registry_integration)
end
end
end
end
# frozen_string_literal: true
module Projects
module Harbor
class ApplicationController < Projects::ApplicationController
layout 'project'
before_action :harbor_registry_enabled!
before_action do
push_frontend_feature_flag(:harbor_registry_integration)
end
feature_category :integrations
private
def harbor_registry_enabled!
render_404 unless Feature.enabled?(:harbor_registry_integration)
end
end
end
end
# frozen_string_literal: true
module Projects
module Harbor
class RepositoriesController < ::Projects::Harbor::ApplicationController
def show
render :index
end
end
end
end
- page_title _("Harbor Registry")
- @content_class = "limit-container-width" unless fluid_layout
#js-harbor-registry-list-group{ data: { endpoint: group_harbor_registries_path(@group),
"no_containers_image" => image_path('illustrations/docker-empty-state.svg'),
"containers_error_image" => image_path('illustrations/docker-error-state.svg'),
"help_page_path" => help_page_path('user/packages/container_registry/index'),
connection_error: (!!@connection_error).to_s,
invalid_path_error: (!!@invalid_path_error).to_s, } }
- page_title _("Harbor Registry")
- @content_class = "limit-container-width" unless fluid_layout
#js-harbor-registry-list-project{ data: { endpoint: project_harbor_registry_index_path(@project),
"no_containers_image" => image_path('illustrations/docker-empty-state.svg'),
"containers_error_image" => image_path('illustrations/docker-error-state.svg'),
"help_page_path" => help_page_path('user/packages/container_registry/index'),
connection_error: (!!@connection_error).to_s,
invalid_path_error: (!!@invalid_path_error).to_s, } }
---
name: harbor_registry_integration
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/81593
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/353595
milestone: '14.9'
type: development
group: group::package
default_enabled: false
......@@ -118,6 +118,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
end
resources :container_registries, only: [:index, :show], controller: 'registry/repositories'
resources :harbor_registries, only: [:index, :show], controller: 'harbor/repositories'
resource :dependency_proxy, only: [:show, :update]
resources :email_campaigns, only: :index
......
......@@ -545,6 +545,9 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
resources :container_registry, only: [:index, :destroy, :show], # rubocop: disable Cop/PutProjectRoutesUnderScope
controller: 'registry/repositories'
resources :harbor_registry, only: [:index, :show], # rubocop: disable Cop/PutProjectRoutesUnderScope
controller: 'harbor/repositories'
namespace :registry do
resources :repository, only: [] do # rubocop: disable Cop/PutProjectRoutesUnderScope
# We default to JSON format in the controller to avoid ambiguity.
......
......@@ -16,6 +16,7 @@ RSpec.describe 'Group navbar' do
group.add_maintainer(user)
stub_feature_flags(customer_relations: false)
stub_group_wikis(false)
stub_feature_flags(harbor_registry_integration: false)
sign_in(user)
insert_package_nav(_('Kubernetes'))
......@@ -231,4 +232,16 @@ RSpec.describe 'Group navbar' do
it_behaves_like 'verified navigation bar'
end
context 'when harbor registry is available' do
before do
stub_feature_flags(harbor_registry_integration: true)
insert_harbor_registry_nav(_('Package Registry'))
visit group_path(group)
end
it_behaves_like 'verified navigation bar'
end
end
......@@ -14,6 +14,7 @@ RSpec.describe 'Project navbar' do
before do
sign_in(user)
stub_feature_flags(harbor_registry_integration: false)
insert_package_nav(_('Infrastructure'))
insert_infrastructure_registry_nav
insert_infrastructure_google_cloud_nav
......@@ -81,4 +82,16 @@ RSpec.describe 'Project navbar' do
it_behaves_like 'verified navigation bar'
end
end
context 'when harbor registry is available' do
before do
stub_feature_flags(harbor_registry_integration: true)
insert_harbor_registry_nav(_('Infrastructure Registry'))
visit project_path(project)
end
it_behaves_like 'verified navigation bar'
end
end
......@@ -8,8 +8,8 @@ module Sidebars
def configure_menu_items
add_item(packages_registry_menu_item)
add_item(container_registry_menu_item)
add_item(harbor_registry__menu_item)
add_item(dependency_proxy_menu_item)
true
end
......@@ -49,6 +49,17 @@ module Sidebars
)
end
def harbor_registry__menu_item
return nil_menu_item(:harbor_registry) if Feature.disabled?(:harbor_registry_integration)
::Sidebars::MenuItem.new(
title: _('Harbor Registry'),
link: group_harbor_registries_path(context.group),
active_routes: { controller: 'groups/harbor/repositories' },
item_id: :harbor_registry
)
end
def dependency_proxy_menu_item
setting_does_not_exist_or_is_enabled = !context.group.dependency_proxy_setting ||
context.group.dependency_proxy_setting.enabled
......
......@@ -9,7 +9,7 @@ module Sidebars
add_item(packages_registry_menu_item)
add_item(container_registry_menu_item)
add_item(infrastructure_registry_menu_item)
add_item(harbor_registry__menu_item)
true
end
......@@ -65,6 +65,17 @@ module Sidebars
)
end
def harbor_registry__menu_item
return ::Sidebars::NilMenuItem.new(item_id: :harbor_registry) if Feature.disabled?(:harbor_registry_integration)
::Sidebars::MenuItem.new(
title: _('Harbor Registry'),
link: project_harbor_registry_index_path(context.project),
active_routes: { controller: :harbor_registry },
item_id: :harbor_registry
)
end
def packages_registry_disabled?
!::Gitlab.config.packages.enabled || !can?(context.current_user, :read_package, context.project)
end
......
......@@ -17932,6 +17932,9 @@ msgstr ""
msgid "HTTP Basic: Access denied\\nYou must use a personal access token with 'api' scope for Git over HTTP.\\nYou can generate one at %{profile_personal_access_tokens_url}"
msgstr ""
msgid "Harbor Registry"
msgstr ""
msgid "Hashed Storage must be enabled to use Geo"
msgstr ""
......
......@@ -18,6 +18,7 @@ RSpec.describe 'Group navbar' do
stub_feature_flags(customer_relations: false)
stub_config(dependency_proxy: { enabled: false })
stub_config(registry: { enabled: false })
stub_feature_flags(harbor_registry_integration: false)
stub_group_wikis(false)
group.add_maintainer(user)
sign_in(user)
......@@ -70,4 +71,16 @@ RSpec.describe 'Group navbar' do
it_behaves_like 'verified navigation bar'
end
context 'when harbor registry is available' do
before do
stub_feature_flags(harbor_registry_integration: true)
insert_harbor_registry_nav(_('Package Registry'))
visit group_path(group)
end
it_behaves_like 'verified navigation bar'
end
end
......@@ -16,6 +16,7 @@ RSpec.describe 'Project navbar' do
sign_in(user)
stub_config(registry: { enabled: false })
stub_feature_flags(harbor_registry_integration: false)
insert_package_nav(_('Infrastructure'))
insert_infrastructure_registry_nav
insert_infrastructure_google_cloud_nav
......@@ -76,4 +77,16 @@ RSpec.describe 'Project navbar' do
it_behaves_like 'verified navigation bar'
end
context 'when harbor registry is available' do
before do
stub_feature_flags(harbor_registry_integration: true)
insert_harbor_registry_nav(_('Infrastructure Registry'))
visit project_path(project)
end
it_behaves_like 'verified navigation bar'
end
end
......@@ -23,6 +23,7 @@ RSpec.describe Sidebars::Groups::Menus::PackagesRegistriesMenu do
context 'when menu does not have any menu item to show' do
it 'returns false' do
stub_feature_flags(harbor_registry_integration: false)
stub_container_registry_config(enabled: false)
stub_config(packages: { enabled: false })
stub_config(dependency_proxy: { enabled: false })
......@@ -35,11 +36,13 @@ RSpec.describe Sidebars::Groups::Menus::PackagesRegistriesMenu do
describe '#link' do
let(:registry_enabled) { true }
let(:packages_enabled) { true }
let(:harbor_registry_integration) { true }
before do
stub_container_registry_config(enabled: registry_enabled)
stub_config(packages: { enabled: packages_enabled })
stub_config(dependency_proxy: { enabled: true })
stub_feature_flags(harbor_registry_integration: harbor_registry_integration)
end
subject { menu.link }
......@@ -60,8 +63,16 @@ RSpec.describe Sidebars::Groups::Menus::PackagesRegistriesMenu do
context 'when Container Registry is not visible' do
let(:registry_enabled) { false }
it 'menu link points to Dependency Proxy page' do
expect(subject).to eq find_menu(menu, :dependency_proxy).link
it 'menu link points to Harbor Registry page' do
expect(subject).to eq find_menu(menu, :harbor_registry).link
end
context 'when Harbor Registry is not visible' do
let(:harbor_registry_integration) { false }
it 'menu link points to Dependency Proxy page' do
expect(subject).to eq find_menu(menu, :dependency_proxy).link
end
end
end
end
......@@ -175,6 +186,26 @@ RSpec.describe Sidebars::Groups::Menus::PackagesRegistriesMenu do
it_behaves_like 'the menu entry is not available'
end
end
describe 'Harbor Registry' do
let(:item_id) { :harbor_registry }
before do
stub_feature_flags(harbor_registry_integration: harbor_registry_enabled)
end
context 'when config harbor registry setting is disabled' do
let(:harbor_registry_enabled) { false }
it_behaves_like 'the menu entry is not available'
end
context 'when config harbor registry setting is enabled' do
let(:harbor_registry_enabled) { true }
it_behaves_like 'the menu entry is available'
end
end
end
private
......
......@@ -33,6 +33,7 @@ RSpec.describe Sidebars::Projects::Menus::PackagesRegistriesMenu do
before do
stub_container_registry_config(enabled: registry_enabled)
stub_config(packages: { enabled: packages_enabled })
stub_feature_flags(harbor_registry_integration: false)
end
context 'when Packages Registry is visible' do
......@@ -144,5 +145,25 @@ RSpec.describe Sidebars::Projects::Menus::PackagesRegistriesMenu do
end
end
end
describe 'Harbor Registry' do
let(:item_id) { :harbor_registry }
context 'when config harbor registry setting is disabled' do
it 'does not add the menu item to the list' do
stub_feature_flags(harbor_registry_integration: false)
is_expected.to be_nil
end
end
context 'when config harbor registry setting is enabled' do
it 'the menu item is added to list of menu items' do
stub_feature_flags(harbor_registry_integration: true)
is_expected.not_to be_nil
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::Harbor::RepositoriesController do
let_it_be(:group, reload: true) { create(:group) }
let_it_be(:user) { create(:user) }
shared_examples 'responds with 404 status' do
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
shared_examples 'responds with 200 status' do
it 'renders the index template' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
end
end
before do
stub_feature_flags(harbor_registry_integration: true)
group.add_reporter(user)
login_as(user)
end
describe 'GET #index' do
subject do
get group_harbor_registries_path(group)
response
end
context 'with harbor registry feature flag enabled' do
it_behaves_like 'responds with 200 status'
end
context 'with harbor registry feature flag disabled' do
before do
stub_feature_flags(harbor_registry_integration: false)
end
it_behaves_like 'responds with 404 status'
end
end
describe 'GET #show' do
subject do
get group_harbor_registry_path(group, 1)
response
end
context 'with harbor registry feature flag enabled' do
it_behaves_like 'responds with 200 status'
end
context 'with harbor registry feature flag disabled' do
before do
stub_feature_flags(harbor_registry_integration: false)
end
it_behaves_like 'responds with 404 status'
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Projects::Harbor::RepositoriesController do
let_it_be(:project, reload: true) { create(:project) }
let_it_be(:user) { create(:user) }
shared_examples 'responds with 404 status' do
it 'returns 404' do
subject
expect(response).to have_gitlab_http_status(:not_found)
end
end
shared_examples 'responds with 200 status' do
it 'renders the index template' do
subject
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:index)
end
end
before do
stub_feature_flags(harbor_registry_integration: true)
project.add_developer(user)
sign_in(user)
end
describe 'GET #index' do
subject do
get project_harbor_registry_index_path(project)
response
end
context 'with harbor registry feature flag enabled' do
it_behaves_like 'responds with 200 status'
end
context 'with harbor registry feature flag disabled' do
before do
stub_feature_flags(harbor_registry_integration: false)
end
it_behaves_like 'responds with 404 status'
end
end
describe 'GET #show' do
subject do
get project_harbor_registry_path(project, 1)
response
end
context 'with harbor registry feature flag enabled' do
it_behaves_like 'responds with 200 status'
end
context 'with harbor registry feature flag disabled' do
before do
stub_feature_flags(harbor_registry_integration: false)
end
it_behaves_like 'responds with 404 status'
end
end
end
......@@ -77,6 +77,14 @@ module NavbarStructureHelper
)
end
def insert_harbor_registry_nav(within)
insert_after_sub_nav_item(
within,
within: _('Packages & Registries'),
new_sub_nav_item_name: _('Harbor Registry')
)
end
def insert_infrastructure_google_cloud_nav
insert_after_sub_nav_item(
_('Terraform'),
......
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