Skip to content

Commit e111fe7

Browse files
Merge branch 'main' into carl/feedback-2--login-profile-ignored
2 parents 45d3433 + 9b9c4bb commit e111fe7

File tree

4 files changed

+51
-43
lines changed

4 files changed

+51
-43
lines changed

src/planet_auth_utils/commands/cli/main.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,12 @@ def cmd_plauth_login(
185185
yes,
186186
):
187187
"""
188-
Perform an initial login, obtain user authorization, and save access
189-
tokens for the selected authentication profile. The specific process
190-
used depends on the selected options and authentication profile.
188+
Perform an initial login.
189+
190+
This command performs an initial login, obtains user authorization,
191+
and saves access tokens for the selected authentication profile.
192+
The specific process used depends on the selected options and
193+
authentication profile.
191194
"""
192195
extra = {}
193196
if project:

src/planet_auth_utils/commands/cli/oauth_cmd.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ def cmd_oauth_refresh(ctx, scope):
164164
It is possible to request a refresh token with scopes that are different
165165
from what is currently possessed, but you will never be granted
166166
more scopes than what the user has authorized.
167+
168+
This command only applies to auth profiles that use OAuth access tokens.
167169
"""
168170
_check_auth_client_type_for_click_ctx(ctx)
169171
saved_token = FileBackedOidcCredential(None, ctx.obj["AUTH"].token_file_path())
@@ -376,7 +378,8 @@ def cmd_oauth_revoke_refresh_token(ctx):
376378
@recast_exceptions_to_click(AuthException, FileNotFoundError)
377379
def cmd_oauth_userinfo(ctx):
378380
"""
379-
Look up user information from the auth server using the access token.
381+
Look up user information for the current user. Look up is performed by
382+
querying the authorization server using the current access token.
380383
"""
381384
_check_auth_client_type_for_click_ctx(ctx)
382385
saved_token = FileBackedOidcCredential(None, ctx.obj["AUTH"].token_file_path())
@@ -395,6 +398,7 @@ def cmd_oauth_userinfo(ctx):
395398
def cmd_oauth_print_access_token(ctx, refresh):
396399
"""
397400
Show the current OAuth access token. Stale tokens will be automatically refreshed.
401+
This command only applies to auth profiles that use OAuth access tokens.
398402
"""
399403
_check_auth_client_type_for_click_ctx(ctx)
400404
saved_token = FileBackedOidcCredential(None, ctx.obj["AUTH"].token_file_path())
@@ -428,8 +432,8 @@ def cmd_oauth_print_access_token(ctx, refresh):
428432
@recast_exceptions_to_click(AuthException, FileNotFoundError)
429433
def cmd_oauth_decode_jwt_access_token(ctx, human_readable):
430434
"""
431-
Decode a JWT access token locally and display its contents. NO
432-
VALIDATION IS PERFORMED. This function is intended for local
435+
Decode a JWT access token locally.
436+
NO VALIDATION IS PERFORMED. This function is intended for local
433437
debugging purposes. Note: Access tokens need not be JWTs.
434438
This function will not work for authorization servers that issue
435439
access tokens in other formats.
@@ -445,8 +449,8 @@ def cmd_oauth_decode_jwt_access_token(ctx, human_readable):
445449
@recast_exceptions_to_click(AuthException, FileNotFoundError)
446450
def cmd_oauth_decode_jwt_id_token(ctx, human_readable):
447451
"""
448-
Decode a JWT ID token locally and display its contents. NO
449-
VALIDATION IS PERFORMED. This function is intended for local
452+
Decode a JWT ID token locally.
453+
NO VALIDATION IS PERFORMED. This function is intended for local
450454
debugging purposes.
451455
"""
452456
_check_auth_client_type_for_click_ctx(ctx)
@@ -460,8 +464,8 @@ def cmd_oauth_decode_jwt_id_token(ctx, human_readable):
460464
@recast_exceptions_to_click(AuthException, FileNotFoundError)
461465
def cmd_oauth_decode_jwt_refresh_token(ctx, human_readable):
462466
"""
463-
Decode a JWT refresh token locally and display its contents. NO
464-
VALIDATION IS PERFORMED. This function is intended for local
467+
Decode a JWT refresh token locally.
468+
NO VALIDATION IS PERFORMED. This function is intended for local
465469
debugging purposes. Note: Refresh tokens need not be JWTs.
466470
This function will not work for authorization servers that issue
467471
refresh tokens in other formats.

src/planet_auth_utils/commands/cli/planet_legacy_auth_cmd.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ def cmd_pllegacy_login(ctx, auth_profile, username, password, sops, yes):
121121
@recast_exceptions_to_click(AuthException, FileNotFoundError)
122122
def cmd_pllegacy_print_api_key(ctx):
123123
"""
124-
Show the API Key used by the currently selected authentication profile.
124+
Show the current API Key. This command only applies to auth profiles
125+
that use simple API keys.
125126
"""
126127
# We also support StaticApiKeyAuthClient in some cases where the user
127128
# directly provides an API key. Such clients can use the legacy API
@@ -151,7 +152,7 @@ def cmd_pllegacy_print_api_key(ctx):
151152
@recast_exceptions_to_click(AuthException, FileNotFoundError)
152153
def cmd_pllegacy_print_access_token(ctx):
153154
"""
154-
Show the legacy JWT currently held by the selected authentication profile.
155+
Show the current legacy JWT access token.
155156
"""
156157
_check_client_type_pllegacy_for_click_ctx(ctx)
157158
saved_token = FileBackedPlanetLegacyApiKey(api_key_file=ctx.obj["AUTH"].token_file_path())

src/planet_auth_utils/commands/cli/profile_cmd.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def _dialogue_choose_auth_profile():
7070
filtered_builtin_profile_names.append(profile_name)
7171

7272
filtered_builtin_profile_names.sort()
73-
sorted_on_disk_profile_names = Profile.list_on_disk_profiles().copy()
73+
74+
# Loading filters out invalid profile configurations that may be on disk
75+
sorted_on_disk_profile_names = list(_load_all_on_disk_profiles().keys())
7476
sorted_on_disk_profile_names.sort()
7577
all_profile_names = filtered_builtin_profile_names + sorted_on_disk_profile_names
7678
choices = []
@@ -133,38 +135,30 @@ def cmd_profile_list(long):
133135
"""
134136
List auth profiles.
135137
"""
138+
click.echo("Built-in profiles:")
139+
profile_names = Builtins.builtin_profile_names().copy()
140+
profile_names.sort()
141+
display_dicts = OrderedDict()
142+
display_names = []
143+
for profile_name in profile_names:
144+
config_dict = Builtins.builtin_profile_auth_client_config_dict(profile_name)
145+
# The idea of a "hidden" profile currently only applies to built-in profiles.
146+
# This is largely so we can have partial SKEL profiles.
147+
if not config_dict.get("_hidden", False):
148+
display_dicts[profile_name] = config_dict
149+
display_names.append(profile_name)
136150
if long:
137-
click.echo("Built-in profiles:")
138-
profile_names = Builtins.builtin_profile_names().copy()
139-
profile_names.sort()
140-
display_object = OrderedDict()
141-
for profile_name in profile_names:
142-
config_dict = Builtins.builtin_profile_auth_client_config_dict(profile_name)
143-
# The idea of a "hidden" profile currently only applies to built-in profiles.
144-
# This is largely so we can have partial SKEL profiles.
145-
if not config_dict.get("_hidden", False):
146-
display_object[profile_name] = config_dict
147-
print_obj(display_object)
148-
149-
click.echo("\nLocally defined profiles:")
150-
print_obj(_load_all_on_disk_profiles())
151+
print_obj(display_dicts)
152+
else:
153+
print_obj(display_names)
151154

155+
click.echo("\nLocally defined profiles:")
156+
profile_dicts = _load_all_on_disk_profiles()
157+
profile_names = list(profile_dicts.keys())
158+
if long:
159+
print_obj(profile_dicts)
152160
else:
153-
click.echo("Built-in profiles:")
154-
display_profile_names = []
155-
for profile_name in Builtins.builtin_profile_names():
156-
config_dict = Builtins.builtin_profile_auth_client_config_dict(profile_name)
157-
# The idea of a "hidden" profile currently only applies to built-in profiles.
158-
# This is largely so we can have partial SKEL profiles.
159-
if not config_dict.get("_hidden", False):
160-
display_profile_names.append(profile_name)
161-
display_profile_names.sort()
162-
print_obj(display_profile_names)
163-
164-
click.echo("\nLocally defined profiles:")
165-
display_profile_names = Profile.list_on_disk_profiles()
166-
display_profile_names.sort()
167-
print_obj(display_profile_names)
161+
print_obj(profile_names)
168162

169163

170164
@cmd_profile.command("create")
@@ -271,10 +265,16 @@ def cmd_profile_copy(sops, src, dst):
271265
@recast_exceptions_to_click(AuthException, FileNotFoundError, PermissionError)
272266
def cmd_profile_set(selected_profile):
273267
"""
274-
Configure the default authentication profile to use when one is not otherwise specified.
268+
Configure the default authentication profile. Preference will be saved to disk
269+
and will be used when one is not otherwise specified. Command line options
270+
and environment variables override on-disk preferences.
275271
"""
276272
if not selected_profile:
277273
selected_profile = _dialogue_choose_auth_profile()
274+
else:
275+
# Validate user input. Dialogue selected profiles should be pre-vetted.
276+
normalized_profile_name, _ = PlanetAuthFactory.load_auth_client_config_from_profile(selected_profile)
277+
selected_profile = normalized_profile_name
278278

279279
try:
280280
user_profile_config_file = PlanetAuthUserConfig()

0 commit comments

Comments
 (0)