2018-11-09 18:39:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-09-12 10:26:59 +00:00
|
|
|
module Gitlab
|
|
|
|
module GitalyClient
|
|
|
|
class NamespaceService
|
2019-11-18 18:06:53 +00:00
|
|
|
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
|
|
|
|
|
2017-09-12 10:26:59 +00:00
|
|
|
def initialize(storage)
|
2019-11-18 18:06:53 +00:00
|
|
|
raise NamespaceServiceAccessError if self.class.denied?
|
|
|
|
|
2017-09-12 10:26:59 +00:00
|
|
|
@storage = storage
|
|
|
|
end
|
|
|
|
|
|
|
|
def add(name)
|
|
|
|
request = Gitaly::AddNamespaceRequest.new(storage_name: @storage, name: name)
|
|
|
|
|
2018-07-05 16:05:24 +00:00
|
|
|
gitaly_client_call(:add_namespace, request, timeout: GitalyClient.fast_timeout)
|
2017-09-12 10:26:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove(name)
|
|
|
|
request = Gitaly::RemoveNamespaceRequest.new(storage_name: @storage, name: name)
|
|
|
|
|
2019-09-19 18:06:18 +00:00
|
|
|
gitaly_client_call(:remove_namespace, request, timeout: GitalyClient.long_timeout)
|
2017-09-12 10:26:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def rename(from, to)
|
|
|
|
request = Gitaly::RenameNamespaceRequest.new(storage_name: @storage, from: from, to: to)
|
|
|
|
|
2018-07-05 16:05:24 +00:00
|
|
|
gitaly_client_call(:rename_namespace, request, timeout: GitalyClient.fast_timeout)
|
2017-09-12 10:26:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-07-05 16:05:24 +00:00
|
|
|
def gitaly_client_call(type, request, timeout: nil)
|
|
|
|
GitalyClient.call(@storage, :namespace_service, type, request, timeout: timeout)
|
2017-09-12 10:26:59 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|