diff options
author | Ashley Ellis Pierce <anellis12@gmail.com> | 2022-07-22 13:11:52 -0400 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-07-23 03:42:59 +0900 |
commit | 244bda7efd507657ada6f18e800d852d1a1569f4 (patch) | |
tree | c4f6a2ac0ad9906b180665b6bda72acb7f223e3b /lib/rubygems | |
parent | e199ae3edcead0271c6da3410eb02acd927739b7 (diff) | |
download | ruby-244bda7efd507657ada6f18e800d852d1a1569f4.tar.gz |
[rubygems/rubygems] Display mfa warnings on gem signin
https://github.com/rubygems/rubygems/commit/4dc77b7099
Co-authored-by: Jenny Shen <jenny.shen@shopify.com>
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/gemcutter_utilities.rb | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb index 1eeb341bb8..c46650afb1 100644 --- a/lib/rubygems/gemcutter_utilities.rb +++ b/lib/rubygems/gemcutter_utilities.rb @@ -163,8 +163,12 @@ module Gem::GemcutterUtilities key_name = get_key_name(scope) scope_params = get_scope_params(scope) - mfa_params = get_mfa_params(email, password) + profile = get_user_profile(email, password) + mfa_params = get_mfa_params(profile) all_params = scope_params.merge(mfa_params) + warning = profile["warning"] + + say "#{warning}\n" if warning response = rubygems_api_request(:post, "api/v1/api_key", sign_in_host, scope: scope) do |request| @@ -273,29 +277,28 @@ module Gem::GemcutterUtilities self.host == Gem::DEFAULT_HOST end - def get_mfa_params(email, password) + def get_user_profile(email, password) return {} unless default_host? - mfa_level = get_user_mfa_level(email, password) - params = {} - if mfa_level == "ui_only" || mfa_level == "ui_and_gem_signin" - selected = ask_yes_no("Would you like to enable MFA for this key? (strongly recommended)") - params["mfa"] = true if selected - end - params - end - - def get_user_mfa_level(email, password) response = rubygems_api_request(:get, "api/v1/profile/me.yaml") do |request| request.basic_auth email, password end with_response response do |resp| - body = Gem::SafeYAML.load clean_text(resp.body) - body["mfa"] + Gem::SafeYAML.load clean_text(resp.body) end end + def get_mfa_params(profile) + mfa_level = profile["mfa"] + params = {} + if mfa_level == "ui_only" || mfa_level == "ui_and_gem_signin" + selected = ask_yes_no("Would you like to enable MFA for this key? (strongly recommended)") + params["mfa"] = true if selected + end + params + end + def get_key_name(scope) hostname = Socket.gethostname || "unknown-host" user = ENV["USER"] || ENV["USERNAME"] || "unknown-user" |