2019-07-25 01:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-09 01:55:24 -04:00
|
|
|
require_relative 'workhorse_helpers'
|
|
|
|
|
2016-08-15 06:33:46 -04:00
|
|
|
module GitHttpHelpers
|
2019-07-09 01:55:24 -04:00
|
|
|
include WorkhorseHelpers
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
def clone_get(repository_path, **options)
|
|
|
|
get "/#{repository_path}/info/refs", params: { service: 'git-upload-pack' }, headers: auth_env(*options.values_at(:user, :password, :spnego_request_token))
|
2016-08-15 06:33:46 -04:00
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
def clone_post(repository_path, **options)
|
|
|
|
post "/#{repository_path}/git-upload-pack", headers: auth_env(*options.values_at(:user, :password, :spnego_request_token))
|
2016-08-15 06:33:46 -04:00
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
def push_get(repository_path, **options)
|
|
|
|
get "/#{repository_path}/info/refs", params: { service: 'git-receive-pack' }, headers: auth_env(*options.values_at(:user, :password, :spnego_request_token))
|
2016-08-15 06:33:46 -04:00
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
def push_post(repository_path, **options)
|
|
|
|
post "/#{repository_path}/git-receive-pack", headers: auth_env(*options.values_at(:user, :password, :spnego_request_token))
|
2016-08-15 06:33:46 -04:00
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
def download(repository_path, user: nil, password: nil, spnego_request_token: nil)
|
2020-09-30 02:09:47 -04:00
|
|
|
args = { user: user, password: password, spnego_request_token: spnego_request_token }
|
2016-08-15 06:33:46 -04:00
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
clone_get(repository_path, **args)
|
2016-08-15 06:33:46 -04:00
|
|
|
yield response
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
clone_post(repository_path, **args)
|
2016-08-15 06:33:46 -04:00
|
|
|
yield response
|
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
def upload(repository_path, user: nil, password: nil, spnego_request_token: nil)
|
2020-09-30 02:09:47 -04:00
|
|
|
args = { user: user, password: password, spnego_request_token: spnego_request_token }
|
2016-08-15 06:33:46 -04:00
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
push_get(repository_path, **args)
|
2016-08-15 06:33:46 -04:00
|
|
|
yield response
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
push_post(repository_path, **args)
|
2016-08-15 06:33:46 -04:00
|
|
|
yield response
|
|
|
|
end
|
|
|
|
|
2020-12-01 07:09:17 -05:00
|
|
|
def download_or_upload(repository_path, **args, &block)
|
|
|
|
download(repository_path, **args, &block)
|
|
|
|
upload(repository_path, **args, &block)
|
2017-05-15 19:13:36 -04:00
|
|
|
end
|
|
|
|
|
2016-08-15 06:33:46 -04:00
|
|
|
def auth_env(user, password, spnego_request_token)
|
|
|
|
env = workhorse_internal_api_request_header
|
2017-05-15 19:13:36 -04:00
|
|
|
if user
|
2016-08-15 06:33:46 -04:00
|
|
|
env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user, password)
|
|
|
|
elsif spnego_request_token
|
|
|
|
env['HTTP_AUTHORIZATION'] = "Negotiate #{::Base64.strict_encode64('opaque_request_token')}"
|
|
|
|
end
|
|
|
|
|
|
|
|
env
|
|
|
|
end
|
2017-05-15 19:13:36 -04:00
|
|
|
|
|
|
|
def git_access_error(error_key)
|
2017-05-16 15:58:46 -04:00
|
|
|
message = Gitlab::GitAccess::ERROR_MESSAGES[error_key]
|
|
|
|
message || raise("GitAccess error message key '#{error_key}' not found")
|
2017-05-15 19:13:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def git_access_wiki_error(error_key)
|
2017-05-16 15:58:46 -04:00
|
|
|
message = Gitlab::GitAccessWiki::ERROR_MESSAGES[error_key]
|
|
|
|
message || raise("GitAccessWiki error message key '#{error_key}' not found")
|
2017-05-15 19:13:36 -04:00
|
|
|
end
|
2016-08-15 06:33:46 -04:00
|
|
|
end
|