debian-mirror-gitlab/lib/gitlab/gitaly_client/namespace_service.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.3 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Gitlab
module GitalyClient
class NamespaceService
2019-12-26 22:10:19 +05:30
extend Gitlab::TemporarilyAllow
NamespaceServiceAccessError = Class.new(StandardError)
ALLOW_KEY = :allow_namespace
def self.allow
temporarily_allow(ALLOW_KEY) { yield }
2018-03-17 18:26:18 +05:30
end
2019-12-26 22:10:19 +05:30
def self.denied?
!temporarily_allowed?(ALLOW_KEY)
end
def initialize(storage)
raise NamespaceServiceAccessError if self.class.denied?
2018-03-17 18:26:18 +05:30
2019-12-26 22:10:19 +05:30
@storage = storage
2018-03-17 18:26:18 +05:30
end
def add(name)
request = Gitaly::AddNamespaceRequest.new(storage_name: @storage, name: name)
2018-11-08 19:23:39 +05:30
gitaly_client_call(:add_namespace, request, timeout: GitalyClient.fast_timeout)
2018-03-17 18:26:18 +05:30
end
def remove(name)
request = Gitaly::RemoveNamespaceRequest.new(storage_name: @storage, name: name)
2019-12-21 20:55:43 +05:30
gitaly_client_call(:remove_namespace, request, timeout: GitalyClient.long_timeout)
2018-03-17 18:26:18 +05:30
end
def rename(from, to)
request = Gitaly::RenameNamespaceRequest.new(storage_name: @storage, from: from, to: to)
2018-11-08 19:23:39 +05:30
gitaly_client_call(:rename_namespace, request, timeout: GitalyClient.fast_timeout)
2018-03-17 18:26:18 +05:30
end
private
2018-11-08 19:23:39 +05:30
def gitaly_client_call(type, request, timeout: nil)
GitalyClient.call(@storage, :namespace_service, type, request, timeout: timeout)
2018-03-17 18:26:18 +05:30
end
end
end
end