summaryrefslogtreecommitdiff
path: root/lib/action
diff options
context:
space:
mode:
Diffstat (limited to 'lib/action')
-rw-r--r--lib/action/api_2fa_recovery.rb54
-rw-r--r--lib/action/base.rb27
-rw-r--r--lib/action/git_lfs_authenticate.rb26
-rw-r--r--lib/action/gitaly.rb126
4 files changed, 0 insertions, 233 deletions
diff --git a/lib/action/api_2fa_recovery.rb b/lib/action/api_2fa_recovery.rb
deleted file mode 100644
index 06f8057..0000000
--- a/lib/action/api_2fa_recovery.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-require_relative '../action'
-require_relative '../gitlab_logger'
-
-module Action
- class API2FARecovery < Base
- def initialize(actor)
- @actor = actor
- end
-
- def execute(_, _)
- recover
- end
-
- private
-
- attr_reader :actor
-
- def continue?(question)
- puts "#{question} (yes/no)"
- STDOUT.flush # Make sure the question gets output before we wait for input
- response = STDIN.gets.chomp
- puts '' # Add a buffer in the output
- response == 'yes'
- end
-
- def recover
- continue = continue?(
- "Are you sure you want to generate new two-factor recovery codes?\n" \
- "Any existing recovery codes you saved will be invalidated."
- )
-
- unless continue
- puts 'New recovery codes have *not* been generated. Existing codes will remain valid.'
- return
- end
-
- resp = api.two_factor_recovery_codes(actor)
- if resp['success']
- codes = resp['recovery_codes'].join("\n")
- $logger.info('API 2FA recovery success', user: actor.log_username)
- puts "Your two-factor authentication recovery codes are:\n\n" \
- "#{codes}\n\n" \
- "During sign in, use one of the codes above when prompted for\n" \
- "your two-factor code. Then, visit your Profile Settings and add\n" \
- "a new device so you do not lose access to your account again."
- true
- else
- $logger.info('API 2FA recovery error', user: actor.log_username)
- puts "An error occurred while trying to generate new recovery codes.\n" \
- "#{resp['message']}"
- end
- end
- end
-end
diff --git a/lib/action/base.rb b/lib/action/base.rb
deleted file mode 100644
index fe8c836..0000000
--- a/lib/action/base.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-require 'json'
-
-require_relative '../gitlab_config'
-require_relative '../gitlab_net'
-require_relative '../gitlab_metrics'
-
-module Action
- class Base
- def initialize
- raise NotImplementedError
- end
-
- def self.create_from_json(_)
- raise NotImplementedError
- end
-
- private
-
- def config
- @config ||= GitlabConfig.new
- end
-
- def api
- @api ||= GitlabNet.new
- end
- end
-end
diff --git a/lib/action/git_lfs_authenticate.rb b/lib/action/git_lfs_authenticate.rb
deleted file mode 100644
index 8c5294d..0000000
--- a/lib/action/git_lfs_authenticate.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-require_relative '../action'
-require_relative '../gitlab_logger'
-
-module Action
- class GitLFSAuthenticate < Base
- def initialize(actor, repo_name)
- @actor = actor
- @repo_name = repo_name
- end
-
- def execute(_, _)
- GitlabMetrics.measure('lfs-authenticate') do
- $logger.info('Processing LFS authentication', user: actor.log_username)
- lfs_access = api.lfs_authenticate(actor, repo_name)
- return unless lfs_access
-
- puts lfs_access.authentication_payload
- end
- true
- end
-
- private
-
- attr_reader :actor, :repo_name
- end
-end
diff --git a/lib/action/gitaly.rb b/lib/action/gitaly.rb
deleted file mode 100644
index b95ff17..0000000
--- a/lib/action/gitaly.rb
+++ /dev/null
@@ -1,126 +0,0 @@
-require_relative '../action'
-require_relative '../gitlab_logger'
-require_relative '../gitlab_net'
-
-module Action
- class Gitaly < Base
- REPOSITORY_PATH_NOT_PROVIDED = "Repository path not provided. Please make sure you're using GitLab v8.10 or later.".freeze
- MIGRATED_COMMANDS = {
- 'git-upload-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-pack'),
- 'git-upload-archive' => File.join(ROOT_PATH, 'bin', 'gitaly-upload-archive'),
- 'git-receive-pack' => File.join(ROOT_PATH, 'bin', 'gitaly-receive-pack')
- }.freeze
-
- def initialize(actor, gl_repository, gl_username, git_protocol, repository_path, gitaly)
- @actor = actor
- @gl_repository = gl_repository
- @gl_username = gl_username
- @git_protocol = git_protocol
- @repository_path = repository_path
- @gitaly = gitaly
- end
-
- def self.create_from_json(actor, json)
- new(actor,
- json['gl_repository'],
- json['gl_username'],
- json['git_protocol'],
- json['repository_path'],
- json['gitaly'])
- end
-
- def execute(command, args)
- raise ArgumentError, REPOSITORY_PATH_NOT_PROVIDED unless repository_path
- raise InvalidRepositoryPathError unless valid_repository?
-
- $logger.info('Performing Gitaly command', user: actor.log_username)
- process(command, args)
- end
-
- private
-
- attr_reader :actor, :gl_repository, :gl_username, :repository_path, :gitaly
-
- def git_protocol
- @git_protocol || ENV['GIT_PROTOCOL'] # TODO: tidy this up
- end
-
- def process(command, args)
- executable = command
- args = [repository_path]
-
- if MIGRATED_COMMANDS.key?(executable) && gitaly
- executable = MIGRATED_COMMANDS[executable]
- gitaly_address = gitaly['address']
- args = [gitaly_address, JSON.dump(gitaly_request)]
- end
-
- args_string = [File.basename(executable), *args].join(' ')
- $logger.info('executing git command', command: args_string, user: actor.log_username)
-
- exec_cmd(executable, *args)
- end
-
- def exec_cmd(*args)
- env = exec_env
- env['GITALY_TOKEN'] = gitaly['token'] if gitaly && gitaly.include?('token')
-
- if git_trace_available?
- env.merge!(
- 'GIT_TRACE' => config.git_trace_log_file,
- 'GIT_TRACE_PACKET' => config.git_trace_log_file,
- 'GIT_TRACE_PERFORMANCE' => config.git_trace_log_file
- )
- end
-
- # We use 'chdir: ROOT_PATH' to let the next executable know where config.yml is.
- Kernel.exec(env, *args, unsetenv_others: true, chdir: ROOT_PATH)
- end
-
- def exec_env
- {
- 'HOME' => ENV['HOME'],
- 'PATH' => ENV['PATH'],
- 'LD_LIBRARY_PATH' => ENV['LD_LIBRARY_PATH'],
- 'LANG' => ENV['LANG'],
- 'GL_ID' => actor.identifier,
- 'GL_PROTOCOL' => GitlabNet::GL_PROTOCOL,
- 'GL_REPOSITORY' => gl_repository,
- 'GL_USERNAME' => gl_username
- }
- end
-
- def gitaly_request
- # The entire gitaly_request hash should be built in gitlab-ce and passed
- # on as-is. For now we build a fake one on the spot.
- {
- 'repository' => gitaly['repository'],
- 'gl_repository' => gl_repository,
- 'gl_id' => actor.identifier,
- 'gl_username' => gl_username,
- 'git_protocol' => git_protocol
- }
- end
-
- def valid_repository?
- File.absolute_path(repository_path) == repository_path
- end
-
- def git_trace_available?
- return false unless config.git_trace_log_file
-
- if Pathname(config.git_trace_log_file).relative?
- $logger.warn('git trace log path must be absolute, ignoring', git_trace_log_file: config.git_trace_log_file)
- return false
- end
-
- begin
- File.open(config.git_trace_log_file, 'a') { nil }
- return true
- rescue => ex
- $logger.warn('Failed to open git trace log file', git_trace_log_file: config.git_trace_log_file, error: ex.to_s)
- return false
- end
- end
- end
-end