Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Allow Auth Plugins to use netrc #718

Closed
labeneator opened this issue Oct 2, 2018 · 5 comments
Closed

Proposal: Allow Auth Plugins to use netrc #718

labeneator opened this issue Oct 2, 2018 · 5 comments

Comments

@labeneator
Copy link

Based on a previous issue #162 and my use case, I'd like to propose a small extension to auth plugins to allow netrc credentials.

Use Case

We have a plugin that provides http-signatures support to httpie. However, providing an access/secret key pair becomes cumbersome, especially once one has multiple environments to work with (local dev/integ/prod....).
It would be great if we could leverage .netrc as a store for credentials (instead of creating yet another config file).

Proposal

  1. Add a class variable netrc_parse with a default of False to class AuthPlugin. Default of False to support the principle of least astonishment (Existing plugins will not be impacted).
  2. If netrc_parse is True, source credentials from .netrc and call get_auth with them.
@labeneator labeneator changed the title Proposal: Allow Plugins to use netrc Proposal: Allow Auth Plugins to use netrc Oct 2, 2018
@labeneator
Copy link
Author

Sample run

❯ tail -1 ~/.netrc
machine api.integ.xxxx.co.ke login akxxxxxxxx password skxxxxxxxxx

# netrc credentials used
 ❯ http   --auth-type=httpsig  "https://api.integ.xxxx.co.ke/api/v1/user/reports" 
HTTP/1.1 200 OK
....
.....


# Credentials from --auth
 ❯ http   --auth-type=httpsig --auth="akxxxxxxxx:skxxxxxxxxx"  "https://api.integ.xxxx.co.ke/api/v1/user/reports"
HTTP/1.1 200 OK
......
......


# Site that doesn't exist in .netrc (no deviation from current httpie behaviour)
 ❯ http   --auth-type=httpsig  "https://api.xxxx.co.ke/api/v1/user/reports" 
usage: http [--json] [--form] [--pretty {all,colors,format,none}]
            [--style STYLE] [--print WHAT] [--headers] [--body] [--verbose]
            [--all] [--history-print WHAT] [--stream] [--output FILE]
            [--download] [--continue]
            [--session SESSION_NAME_OR_PATH | --session-read-only SESSION_NAME_OR_PATH]
            [--auth USER[:PASS]] [--auth-type {basic,digest,httpsig}]
            [--proxy PROTOCOL:PROXY_URL] [--follow]
            [--max-redirects MAX_REDIRECTS] [--timeout SECONDS]
            [--check-status] [--verify VERIFY]
            [--ssl {ssl2.3,tls1,tls1.1,tls1.2}] [--cert CERT]
            [--cert-key CERT_KEY] [--ignore-stdin] [--help] [--version]
            [--traceback] [--default-scheme DEFAULT_SCHEME] [--debug]
            [METHOD] URL [REQUEST_ITEM [REQUEST_ITEM ...]]
http: error: --auth required

@jkbrzt
Copy link
Member

jkbrzt commented Nov 19, 2018

Good idea 👍 See my comments on your PR.

@labeneator
Copy link
Author

@jakubroztocil PR updated.

@emagutu
Copy link

emagutu commented Jan 7, 2019

@jakubroztocil can this be merged please?

@jkbrzt jkbrzt closed this as completed in b865988 Jun 16, 2020
@jkbrzt
Copy link
Member

jkbrzt commented Jun 16, 2020

Just pushed support for this to master in b865988. Feedback appreciated!

@labeneator: I based it on your PR #719, so please feel free to add yourself to AUTHORS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants