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)
- PERMITTED_ACTIONS =
%w[ mv_repository remove_repository add_namespace rm_namespace mv_namespace repository_exists? ].freeze
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
32 33 34 35 36 |
# File 'lib/gitlab/shell.rb', line 32 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
26 27 28 |
# File 'lib/gitlab/shell.rb', line 26 def secret_token @secret_token ||= File.read(Gitlab.config.gitlab_shell.secret_file).chomp end |
.version ⇒ String
Return GitLab shell version
49 50 51 |
# File 'lib/gitlab/shell.rb', line 49 def version @version ||= File.read(gitlab_shell_version_file).chomp if File.readable?(gitlab_shell_version_file) end |
.version_required ⇒ String
Returns required GitLab shell version
41 42 43 44 |
# File 'lib/gitlab/shell.rb', line 41 def version_required @version_required ||= File.read(Rails.root .join('GITLAB_SHELL_VERSION')).strip end |
Instance Method Details
#add_namespace(storage, name) ⇒ Object
Add empty directory for storing repositories
139 140 141 142 143 144 145 |
# File 'lib/gitlab/shell.rb', line 139 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
174 175 176 177 178 179 180 |
# File 'lib/gitlab/shell.rb', line 174 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
94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/gitlab/shell.rb', line 94 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 StandardError => 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.
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/gitlab/shell.rb', line 117 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 StandardError => 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
192 193 194 195 196 |
# File 'lib/gitlab/shell.rb', line 192 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
157 158 159 160 161 |
# File 'lib/gitlab/shell.rb', line 157 def rm_namespace(storage, name) Gitlab::GitalyClient::NamespaceService.new(storage).remove(name) rescue GRPC::InvalidArgument => e raise ArgumentError, e. end |