@@ -163,8 +163,12 @@ def sign_in(sign_in_host = nil, scope: nil)
163163
164164 key_name = get_key_name ( scope )
165165 scope_params = get_scope_params ( scope )
166- mfa_params = get_mfa_params ( email , password )
166+ profile = get_user_profile ( email , password )
167+ mfa_params = get_mfa_params ( profile )
167168 all_params = scope_params . merge ( mfa_params )
169+ warning = profile [ "warning" ]
170+
171+ say "#{ warning } \n " if warning
168172
169173 response = rubygems_api_request ( :post , "api/v1/api_key" ,
170174 sign_in_host , scope : scope ) do |request |
@@ -273,29 +277,28 @@ def default_host?
273277 self . host == Gem ::DEFAULT_HOST
274278 end
275279
276- def get_mfa_params ( email , password )
280+ def get_user_profile ( email , password )
277281 return { } unless default_host?
278282
279- mfa_level = get_user_mfa_level ( email , password )
280- params = { }
281- if mfa_level == "ui_only" || mfa_level == "ui_and_gem_signin"
282- selected = ask_yes_no ( "Would you like to enable MFA for this key? (strongly recommended)" )
283- params [ "mfa" ] = true if selected
284- end
285- params
286- end
287-
288- def get_user_mfa_level ( email , password )
289283 response = rubygems_api_request ( :get , "api/v1/profile/me.yaml" ) do |request |
290284 request . basic_auth email , password
291285 end
292286
293287 with_response response do |resp |
294- body = Gem ::SafeYAML . load clean_text ( resp . body )
295- body [ "mfa" ]
288+ Gem ::SafeYAML . load clean_text ( resp . body )
296289 end
297290 end
298291
292+ def get_mfa_params ( profile )
293+ mfa_level = profile [ "mfa" ]
294+ params = { }
295+ if mfa_level == "ui_only" || mfa_level == "ui_and_gem_signin"
296+ selected = ask_yes_no ( "Would you like to enable MFA for this key? (strongly recommended)" )
297+ params [ "mfa" ] = true if selected
298+ end
299+ params
300+ end
301+
299302 def get_key_name ( scope )
300303 hostname = Socket . gethostname || "unknown-host"
301304 user = ENV [ "USER" ] || ENV [ "USERNAME" ] || "unknown-user"
0 commit comments