-
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
Conversation
A possible solution for one of the issues reported in #643
| try: | ||
| click.echo(ctx.obj['AUTH'].value) | ||
| except (AttributeError, KeyError): | ||
| raise AuthException('Command context lacks auth information.') |
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.
| except PlanetError: | ||
| auth_file = None | ||
|
|
||
| ctx.obj['AUTH'] = auth_env or auth_file |
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.
Now the root "planet" command takes charge of auth. Previously, we deferred until calling the Session constructor.
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.
Warnings might be added here, but I think that could also be done in another PR.
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.
Having planet take charge of auth is a great idea! To minimize code in the CLI wrapper and make it easier to maintain and understand default auth behavior, what about adding the logic for getting auth to the auth module, as something like Auth.default() -> AuthType then using that function here and also in the Session class.
| help='Assign custom base Orders API URL.') | ||
| def data(ctx, base_url): | ||
| '''Commands for interacting with the Data API''' | ||
| ctx.obj['AUTH'] = None |
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 is what deferral to the Session constructor looked like.
|
Just a drive-by question: will this change affect CLI help at all? that is, |
|
@jreiberkyle oh yeah, that needs to be checked. Here's what I see after moving my secret file and making sure I don't have PL_API_KEY set. |
| help='Assign custom base Orders API URL.') | ||
| def orders(ctx, base_url): | ||
| '''Commands for interacting with the Orders API''' | ||
| ctx.obj['AUTH'] = None |
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.
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
|
In mulling over this, I can't recall why we need to manage auth information in the CLI. The priority of auth sources is the same for the CLI and API. Why not have the |
|
@jreiberkyle I like to think of software as an onion (this is not my original analogy). On the outside is the filesystem and the environment, which is where our auth sources are (a secret file or an environment variable). The CLI is the outermost layer of our onion and necessarily has to interact with the filesystem and environment. This package's http module is a few layers down in our onion and shouldn't (in my ideal onion world) be interacting with the filesystem and environment. It should be getting auth information from the next layer out (a service client), which in turn gets it from the next layer out (the CLI). I've worked on projects with no such boundaries and they always suffer for the lack of them. That's why I changed the code to have the outermost layer of our software be responsible for getting the secret and passing it further down. |
|
@sgillies That logic makes sense. In keeping with this approach, then, would we want to remove the logic for obtaining auth information (from env and file) from within |
|
@jreiberkyle no, I think we should keep it. In some applications (like a lot of our usage examples and notebooks), a Session can be the outermost layer, yes? Like It's pragmatic to have it. But let's not use it like that in our CLI, that's all I'm saying. |
|
Ahh okay I understand. It's context-dependent. That makes sense. I'm on board with this approach. |
|
@sgillies for the benefit of my understanding: here, in "a few layers down in our onion", our onion == CLI, right?
but for the API, the http module is the outermost layer of the onion. So, for the CLI application, the CLI should be obtaining the auth info, but for the python application, it is ok for the http module to obtain the auth information - because each is the outermost layer of the onion for it's own application. I can follow this conceptually, though it does seem confusing since the http module is the same in both applications, so we pay for this 'auth obtained at outer layer of the onion' with 'logic for obtaining auth in two places in the logic chain'. So, your experience with how this tradeoff has come out in favor of the 'outer layer' approach is helpful. Would you be willing to elaborate a little on your experience alluded to in the quote below?
|
|
this has been used as input to #809, see that PR for implementation |
A possible solution for one of the issues reported in #643.
In a nutshell, the root planet command is now responsible for finding auth info and
planet auth valuereports on the active auth, whatever the source.