-
Notifications
You must be signed in to change notification settings - Fork 98
Get auth info as early as possible, store in context, use that #699
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| import click | ||
|
|
||
| import planet | ||
| from planet.auth import Auth | ||
| from planet.exceptions import PlanetError | ||
|
|
||
| from . import auth, collect, data, orders, subscriptions | ||
|
|
||
|
|
@@ -45,6 +47,20 @@ def main(ctx, verbosity, quiet): | |
| ctx.ensure_object(dict) | ||
| ctx.obj['QUIET'] = quiet | ||
|
|
||
| # Check authentication sources and store the highest priority in ctx. | ||
| # 1. Environment. | ||
| try: | ||
| auth_env = Auth.from_env() | ||
| except PlanetError: | ||
| auth_env = None | ||
| # 2. Secret file. | ||
| try: | ||
| auth_file = Auth.from_file() | ||
| except PlanetError: | ||
| auth_file = None | ||
|
|
||
| ctx.obj['AUTH'] = auth_env or auth_file | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now the root "planet" command takes charge of auth. Previously, we deferred until calling the Session constructor.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warnings might be added here, but I think that could also be done in another PR.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having |
||
|
|
||
|
|
||
| def _configure_logging(verbosity): | ||
| """configure logging via verbosity level, corresponding | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,7 +48,6 @@ async def data_client(ctx): | |
| help='Assign custom base Orders API URL.') | ||
| def data(ctx, base_url): | ||
| '''Commands for interacting with the Data API''' | ||
| ctx.obj['AUTH'] = None | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is what deferral to the Session constructor looked like. |
||
| ctx.obj['BASE_URL'] = base_url | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,7 +46,6 @@ async def orders_client(ctx): | |
| help='Assign custom base Orders API URL.') | ||
| def orders(ctx, base_url): | ||
| '''Commands for interacting with the Orders API''' | ||
| ctx.obj['AUTH'] = None | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice to be getting rid of these per-client calls to auth. I seem to remember those going in to resolve #463 so I am surprised they are no longer needed |
||
| ctx.obj['BASE_URL'] = base_url | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now reports on the active auth object.