MCPcopy
hub / github.com/httpie/cli / _process_auth

Method _process_auth

httpie/cli/argparser.py:282–355  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

280 self.args.cert_key_pass.prompt_password(self.args.cert_key)
281
282 def _process_auth(self):
283 # TODO: refactor & simplify this method.
284 self.args.auth_plugin = None
285 default_auth_plugin = plugin_manager.get_auth_plugins()[0]
286 auth_type_set = self.args.auth_type is not None
287 url = urlsplit(self.args.url)
288
289 if self.args.auth is None and not auth_type_set:
290 if url.username is not None:
291 # Handle http://username:password@hostname/
292 username = url.username
293 password = url.password or ''
294 self.args.auth = AuthCredentials(
295 key=username,
296 value=password,
297 sep=SEPARATOR_CREDENTIALS,
298 orig=SEPARATOR_CREDENTIALS.join([username, password])
299 )
300
301 if self.args.auth is not None or auth_type_set:
302 if not self.args.auth_type:
303 self.args.auth_type = default_auth_plugin.auth_type
304 plugin = plugin_manager.get_auth_plugin(self.args.auth_type)()
305
306 if (not self.args.ignore_netrc
307 and self.args.auth is None
308 and plugin.netrc_parse):
309 # Only host needed, so it’s OK URL not finalized.
310 netrc_credentials = get_netrc_auth(self.args.url)
311 if netrc_credentials:
312 self.args.auth = AuthCredentials(
313 key=netrc_credentials[0],
314 value=netrc_credentials[1],
315 sep=SEPARATOR_CREDENTIALS,
316 orig=SEPARATOR_CREDENTIALS.join(netrc_credentials)
317 )
318
319 if plugin.auth_require and self.args.auth is None:
320 self.error('--auth required')
321
322 plugin.raw_auth = self.args.auth
323 self.args.auth_plugin = plugin
324 already_parsed = isinstance(self.args.auth, AuthCredentials)
325
326 if self.args.auth is None or not plugin.auth_parse:
327 self.args.auth = plugin.get_auth()
328 else:
329 if already_parsed:
330 # from the URL
331 credentials = self.args.auth
332 else:
333 credentials = parse_auth(self.args.auth)
334
335 if (not credentials.has_password()
336 and plugin.prompt_password):
337 if self.args.ignore_stdin:
338 # Non-tty stdin read by now
339 self.error(

Callers 1

parse_argsMethod · 0.95

Calls 8

errorMethod · 0.95
AuthCredentialsClass · 0.85
ExplicitNullAuthClass · 0.85
get_auth_pluginsMethod · 0.80
get_auth_pluginMethod · 0.80
has_passwordMethod · 0.80
get_authMethod · 0.45
prompt_passwordMethod · 0.45

Tested by

no test coverage detected