summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsh McKenzie <amckenzie@gitlab.com>2018-07-25 12:51:32 +1000
committerAsh McKenzie <amckenzie@gitlab.com>2018-07-25 13:42:54 +1000
commit2b3c4292719a7d3b33d59e8b46c9caf38271dada (patch)
tree45521ebb56ee390e6438bde2589fccc11bed1359
parent17ddc241b16a2d010f8f4b84aee0a732b94b1429 (diff)
downloadgitlab-shell-2b3c4292719a7d3b33d59e8b46c9caf38271dada.tar.gz
Move 2FA related logic into APICommandHelper
-rw-r--r--lib/api_command_helper.rb34
-rw-r--r--lib/gitlab_shell.rb36
2 files changed, 37 insertions, 33 deletions
diff --git a/lib/api_command_helper.rb b/lib/api_command_helper.rb
new file mode 100644
index 0000000..3dd1229
--- /dev/null
+++ b/lib/api_command_helper.rb
@@ -0,0 +1,34 @@
+module APICommandHelper
+ def continue?(question)
+ puts "#{question} (yes/no)"
+ STDOUT.flush # Make sure the question gets output before we wait for input
+ continue = STDIN.gets.chomp
+ puts '' # Add a buffer in the output
+ continue == 'yes'
+ end
+
+ def api_2fa_recovery_codes
+ 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(key_id)
+ if resp['success']
+ codes = resp['recovery_codes'].join("\n")
+ 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."
+ else
+ puts "An error occurred while trying to generate new recovery codes.\n" \
+ "#{resp['message']}"
+ end
+ end
+end
diff --git a/lib/gitlab_shell.rb b/lib/gitlab_shell.rb
index 9644cf4..e30e5e1 100644
--- a/lib/gitlab_shell.rb
+++ b/lib/gitlab_shell.rb
@@ -3,8 +3,11 @@ require 'pathname'
require_relative 'gitlab_net'
require_relative 'gitlab_metrics'
+require_relative 'api_command_helper'
class GitlabShell # rubocop:disable Metrics/ClassLength
+ include APICommandHelper
+
class AccessDeniedError < StandardError; end
class DisallowedCommandError < StandardError; end
class InvalidRepositoryPathError < StandardError; end
@@ -221,39 +224,6 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
private
- def continue?(question)
- puts "#{question} (yes/no)"
- STDOUT.flush # Make sure the question gets output before we wait for input
- continue = STDIN.gets.chomp
- puts '' # Add a buffer in the output
- continue == 'yes'
- end
-
- def api_2fa_recovery_codes
- 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(key_id)
- if resp['success']
- codes = resp['recovery_codes'].join("\n")
- 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."
- else
- puts "An error occurred while trying to generate new recovery codes.\n" \
- "#{resp['message']}"
- end
- end
-
def git_trace_available?
return false unless @config.git_trace_log_file