Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions planet/cli/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import click

import planet
from planet.exceptions import AuthException
from .cmds import translate_exceptions

LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -53,7 +54,11 @@ def init(ctx, email, password):


@auth.command()
@click.pass_context
@translate_exceptions
def value():
def value(ctx):
'''Print the stored authentication information'''
click.echo(planet.Auth.from_file().value)
try:
click.echo(ctx.obj['AUTH'].value)
except (AttributeError, KeyError):
raise AuthException('Command context lacks auth information.')
Copy link
Contributor Author

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.

16 changes: 16 additions & 0 deletions planet/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.



def _configure_logging(verbosity):
"""configure logging via verbosity level, corresponding
Expand Down
1 change: 0 additions & 1 deletion planet/cli/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

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.

ctx.obj['BASE_URL'] = base_url


Expand Down
1 change: 0 additions & 1 deletion planet/cli/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

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

ctx.obj['BASE_URL'] = base_url


Expand Down
3 changes: 0 additions & 3 deletions planet/cli/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
@click.pass_context
def subscriptions(ctx):
'''Commands for interacting with the Subscriptions API'''
# None means that order of precedence is 1) environment variable,
# 2) secret file.
ctx.obj['AUTH'] = None


# We want our command to be known as "list" on the command line but
Expand Down