Commit 04eefcda authored by John Cai's avatar John Cai Committed by Douglas Barbosa Alexandre

Add deprecation guard to prevent further usage of NamespaceService

Namespace service is in process of being deprecated since it is not
compatible with Gitaly HA. Hence, we want to prevent future usage of it
by forcing callers to wrap Namespace Service calls in an allow block
parent 4fd474d2
......@@ -57,6 +57,7 @@ module Storage
# Move the namespace directory in all storages used by member projects
repository_storages(legacy_only: true).each do |repository_storage|
# Ensure old directory exists before moving it
Gitlab::GitalyClient::NamespaceService.allow do
gitlab_shell.add_namespace(repository_storage, full_path_before_last_save)
# Ensure new directory exists before moving it (if there's a parent)
......@@ -72,6 +73,7 @@ module Storage
end
end
end
end
def old_repository_storages
@old_repository_storage_paths ||= repository_storages
......@@ -95,6 +97,7 @@ module Storage
# We will remove it later async
new_path = "#{full_path}+#{id}+deleted"
Gitlab::GitalyClient::NamespaceService.allow do
if gitlab_shell.mv_namespace(repository_storage, full_path, new_path)
Gitlab::AppLogger.info %Q(Namespace directory "#{full_path}" moved to "#{new_path}")
......@@ -107,4 +110,5 @@ module Storage
end
end
end
end
end
......@@ -8,6 +8,8 @@ class GitlabShellWorker
latency_sensitive_worker!
def perform(action, *arg)
Gitlab::GitalyClient::NamespaceService.allow do
gitlab_shell.__send__(action, *arg) # rubocop:disable GitlabSecurity/PublicSend
end
end
end
......@@ -66,6 +66,7 @@ module Gitlab
def move_repositories(namespace, old_full_path, new_full_path)
repo_shards_for_namespace(namespace).each do |repository_storage|
# Ensure old directory exists before moving it
Gitlab::GitalyClient::NamespaceService.allow do
gitlab_shell.add_namespace(repository_storage, old_full_path)
unless gitlab_shell.mv_namespace(repository_storage, old_full_path, new_full_path)
......@@ -74,6 +75,7 @@ module Gitlab
end
end
end
end
def repo_shards_for_namespace(namespace)
projects_for_namespace(namespace).distinct.select(:repository_storage)
......
......@@ -3,7 +3,22 @@
module Gitlab
module GitalyClient
class NamespaceService
extend Gitlab::TemporarilyAllow
NamespaceServiceAccessError = Class.new(StandardError)
ALLOW_KEY = :allow_namespace
def self.allow
temporarily_allow(ALLOW_KEY) { yield }
end
def self.denied?
!temporarily_allowed?(ALLOW_KEY)
end
def initialize(storage)
raise NamespaceServiceAccessError if self.class.denied?
@storage = storage
end
......
......@@ -401,7 +401,7 @@ describe Gitlab::Shell do
describe '#add_namespace' do
it 'creates a namespace' do
subject.add_namespace(storage, "mepmep")
Gitlab::GitalyClient::NamespaceService.allow { subject.add_namespace(storage, "mepmep") }
expect(TestEnv.storage_dir_exists?(storage, "mepmep")).to be(true)
end
......@@ -425,8 +425,10 @@ describe Gitlab::Shell do
describe '#remove' do
it 'removes the namespace' do
Gitlab::GitalyClient::NamespaceService.allow do
subject.add_namespace(storage, "mepmep")
subject.rm_namespace(storage, "mepmep")
end
expect(TestEnv.storage_dir_exists?(storage, "mepmep")).to be(false)
end
......@@ -434,8 +436,10 @@ describe Gitlab::Shell do
describe '#mv_namespace' do
it 'renames the namespace' do
Gitlab::GitalyClient::NamespaceService.allow do
subject.add_namespace(storage, "mepmep")
subject.mv_namespace(storage, "mepmep", "2mep")
end
expect(TestEnv.storage_dir_exists?(storage, "mepmep")).to be(false)
expect(TestEnv.storage_dir_exists?(storage, "2mep")).to be(true)
......
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