Class: Gitlab::Shell
- Inherits:
-
Object
- Object
- Gitlab::Shell
- Defined in:
- lib/gitlab/shell.rb
Overview
This class is an artifact of a time when common repository operations were performed by calling out to scripts in the gitlab-shell project. Now, these operations are all performed by Gitaly, and are mostly accessible through the Repository class. Prefer using a Repository to functionality here.
Legacy code relating to namespaces still relies on Gitlab::Shell; it can be converted to a module once gitlab.com/groups/gitlab-org/-/epics/2320 is completed. gitlab.com/gitlab-org/gitlab/-/issues/25095 tracks it.
Constant Summary collapse
- Error =
Class.new(StandardError)
Class Method Summary collapse
-
.ensure_secret_token! ⇒ Object
Ensure gitlab shell has a secret token stored in the secret_file if that was never generated, generate a new one.
-
.secret_token ⇒ String
Retrieve GitLab Shell secret token.
-
.version ⇒ String
Return GitLab shell version.
-
.version_required ⇒ String
Returns required GitLab shell version.
Instance Method Summary collapse
- #add_namespace(storage, name) ⇒ Object deprecated Deprecated.
- #mv_namespace(storage, old_name, new_name) ⇒ Object deprecated Deprecated.
- #mv_repository(storage, disk_path, new_disk_path) ⇒ Boolean deprecated Deprecated.
- #remove_repository(storage, disk_path) ⇒ Object deprecated Deprecated.
- #repository_exists?(storage, dir_name) ⇒ Boolean deprecated Deprecated.
- #rm_namespace(storage, name) ⇒ Object (also: #rm_directory) deprecated Deprecated.
Class Method Details
.ensure_secret_token! ⇒ Object
Ensure gitlab shell has a secret token stored in the secret_file if that was never generated, generate a new one
29 30 31 32 33 |
# File 'lib/gitlab/shell.rb', line 29 def ensure_secret_token! return if File.exist?(File.join(Gitlab.config.gitlab_shell.path, '.gitlab_shell_secret')) generate_and_link_secret_token end |
.secret_token ⇒ String
Retrieve GitLab Shell secret token
21 22 23 24 25 |
# File 'lib/gitlab/shell.rb', line 21 def secret_token @secret_token ||= begin File.read(Gitlab.config.gitlab_shell.secret_file).chomp end end |
.version ⇒ String
Return GitLab shell version
46 47 48 |
# File 'lib/gitlab/shell.rb', line 46 def version @version ||= File.read(gitlab_shell_version_file).chomp if File.readable?(gitlab_shell_version_file) end |
Instance Method Details
#add_namespace(storage, name) ⇒ Object
Add empty directory for storing repositories
134 135 136 137 138 139 140 |
# File 'lib/gitlab/shell.rb', line 134 def add_namespace(storage, name) Gitlab::GitalyClient.allow_n_plus_1_calls do Gitlab::GitalyClient::NamespaceService.new(storage).add(name) end rescue GRPC::InvalidArgument => e raise ArgumentError, e. end |
#mv_namespace(storage, old_name, new_name) ⇒ Object
Move namespace directory inside repositories storage
169 170 171 172 173 174 175 |
# File 'lib/gitlab/shell.rb', line 169 def mv_namespace(storage, old_name, new_name) Gitlab::GitalyClient::NamespaceService.new(storage).rename(old_name, new_name) rescue GRPC::InvalidArgument => e Gitlab::ErrorTracking.track_exception(e, old_name: old_name, new_name: new_name, storage: storage) false end |
#mv_repository(storage, disk_path, new_disk_path) ⇒ Boolean
Move or rename a repository
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/gitlab/shell.rb', line 89 def mv_repository(storage, disk_path, new_disk_path) return false if disk_path.empty? || new_disk_path.empty? Gitlab::Git::Repository.new(storage, "#{disk_path}.git", nil, nil).rename("#{new_disk_path}.git") true rescue => e Gitlab::ErrorTracking.track_exception(e, path: disk_path, new_path: new_disk_path, storage: storage) false end |
#remove_repository(storage, disk_path) ⇒ Object
Removes a repository from file system, using rm_diretory which is an alias for rm_namespace. Given the underlying implementation removes the name passed as second argument on the passed storage.
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/gitlab/shell.rb', line 112 def remove_repository(storage, disk_path) return false if disk_path.empty? Gitlab::Git::Repository.new(storage, "#{disk_path}.git", nil, nil).remove true rescue => e Gitlab::AppLogger.warn("Repository does not exist: #{e} at: #{disk_path}.git") Gitlab::ErrorTracking.track_exception(e, path: disk_path, storage: storage) false end |
#repository_exists?(storage, dir_name) ⇒ Boolean
Check if repository exists on disk
187 188 189 190 191 |
# File 'lib/gitlab/shell.rb', line 187 def repository_exists?(storage, dir_name) Gitlab::Git::Repository.new(storage, dir_name, nil, nil).exists? rescue GRPC::Internal false end |
#rm_namespace(storage, name) ⇒ Object Also known as: rm_directory
Remove directory from repositories storage Every repository inside this directory will be removed too
152 153 154 155 156 |
# File 'lib/gitlab/shell.rb', line 152 def rm_namespace(storage, name) Gitlab::GitalyClient::NamespaceService.new(storage).remove(name) rescue GRPC::InvalidArgument => e raise ArgumentError, e. end |