Skip to content

Commit 1a84956

Browse files
Carl/wx integration feedback (#23)
* clean-up option code. Make all options functions for consistency. * sort option members * export built-in provider interface * clean up option defaults * unify handling of hiding options. * better handling of env vars for exported CLI options * formatting for options.py * provide some base class implementations for built-in provider to make life easier for integrators
1 parent c9334af commit 1a84956

File tree

12 files changed

+490
-361
lines changed

12 files changed

+490
-361
lines changed

docs/examples/cli/embed-plauth-click.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
@click.group(help="my cli main help message")
1515
@planet_auth_utils.opt_profile
16-
@planet_auth_utils.opt_client_id
17-
@planet_auth_utils.opt_client_secret
16+
@planet_auth_utils.opt_client_id()
17+
@planet_auth_utils.opt_client_secret()
1818
@click.pass_context
1919
def my_cli_main(ctx, auth_profile, auth_client_id, auth_client_secret):
2020
ctx.ensure_object(dict)

src/planet_auth_utils/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787
opt_password,
8888
opt_profile,
8989
opt_project,
90+
opt_qr_code,
9091
opt_refresh,
9192
opt_scope,
92-
opt_show_qr_code,
9393
opt_sops,
9494
opt_token,
9595
opt_token_file,
@@ -99,7 +99,7 @@
9999
from .commands.cli.util import recast_exceptions_to_click
100100
from planet_auth_utils.constants import EnvironmentVariables
101101
from planet_auth_utils.plauth_factory import PlanetAuthFactory
102-
from planet_auth_utils.builtins import Builtins
102+
from planet_auth_utils.builtins import Builtins, BuiltinConfigurationProviderInterface
103103
from planet_auth_utils.profile import Profile
104104
from planet_auth_utils.plauth_user_config import PlanetAuthUserConfig
105105

@@ -150,9 +150,9 @@
150150
"opt_password",
151151
"opt_profile",
152152
"opt_project",
153+
"opt_qr_code",
153154
"opt_refresh",
154155
"opt_scope",
155-
"opt_show_qr_code",
156156
"opt_sops",
157157
"opt_token",
158158
"opt_token_file",
@@ -161,6 +161,7 @@
161161
"recast_exceptions_to_click",
162162
#
163163
"Builtins",
164+
"BuiltinConfigurationProviderInterface",
164165
"EnvironmentVariables",
165166
"PlanetAuthFactory",
166167
"Profile",

src/planet_auth_utils/builtins_provider.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ def builtin_client_authclient_config_dicts(self) -> Dict[str, dict]:
5050
`planet_auth.AuthClientConfig.config_from_dict`
5151
"""
5252

53-
@abstractmethod
5453
def builtin_client_profile_aliases(self) -> Dict[str, str]:
5554
"""
5655
Return a dictionary profile aliases. Aliases allow
5756
for a single built-in configuration to be referred to
5857
by multiple names.
5958
"""
59+
return {}
6060

6161
@abstractmethod
6262
def builtin_default_profile_by_client_type(self) -> Dict[str, str]:
@@ -70,18 +70,30 @@ def builtin_default_profile(self) -> str:
7070
Return the built-in default fallback auth profile name of last resort.
7171
"""
7272

73-
@abstractmethod
7473
def builtin_trust_environment_names(self) -> List[str]:
7574
"""
7675
Return a list of the names of built-in trust environments.
7776
"""
77+
_realms = self.builtin_trust_environments()
78+
if _realms:
79+
return list(_realms.keys())
80+
return []
7881

79-
@abstractmethod
8082
def builtin_trust_environments(self) -> Dict[str, Optional[List[dict]]]:
8183
"""
8284
Return a dictionary of the trust environment configurations.
8385
Each item in the lists should be valid AuthClient config dictionary.
86+
87+
This is primarily used for cases where planet_auth is used to validate
88+
tokens on the service side. This is the flip side of most of the other
89+
BuiltinConfigurationProviderInterface methods which are geared towards
90+
helping clients obtain tokens.
8491
"""
92+
return {
93+
# "PRODUCTION": [MY_REALM_PRODUCTION],
94+
# "STAGING": [MY_REALM_STAGING],
95+
"CUSTOM": None,
96+
}
8597

8698

8799
class EmptyBuiltinProfileConstants(BuiltinConfigurationProviderInterface):
@@ -95,29 +107,15 @@ class EmptyBuiltinProfileConstants(BuiltinConfigurationProviderInterface):
95107
BUILTIN_PROFILE_NAME_NONE: NONE_AUTH_CLIENT_CONFIG,
96108
}
97109

98-
_builtin_profile_aliases: Dict[str, str] = {}
99-
100110
_builtin_profile_default_by_client_type = {
101111
"none": BUILTIN_PROFILE_NAME_NONE,
102112
}
103-
_builtin_trust_realms: Dict[str, Optional[List[dict]]] = {
104-
"CUSTOM": None,
105-
}
106113

107114
def builtin_client_authclient_config_dicts(self) -> Dict[str, dict]:
108115
return EmptyBuiltinProfileConstants._builtin_profile_auth_client_configs
109116

110-
def builtin_client_profile_aliases(self) -> Dict[str, str]:
111-
return EmptyBuiltinProfileConstants._builtin_profile_aliases
112-
113117
def builtin_default_profile_by_client_type(self) -> Dict[str, str]:
114118
return EmptyBuiltinProfileConstants._builtin_profile_default_by_client_type
115119

116120
def builtin_default_profile(self) -> str:
117121
return EmptyBuiltinProfileConstants.BUILTIN_PROFILE_NAME_NONE
118-
119-
def builtin_trust_environment_names(self) -> List[str]:
120-
return list(EmptyBuiltinProfileConstants._builtin_trust_realms.keys())
121-
122-
def builtin_trust_environments(self) -> Dict[str, Optional[List[dict]]]:
123-
return EmptyBuiltinProfileConstants._builtin_trust_realms

src/planet_auth_utils/commands/cli/jwt_cmd.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ def _get_token_or_fail(token_opt: typing.Optional[str], token_file_opt: typing.O
146146

147147
@cmd_jwt.command("decode")
148148
@click.pass_context
149-
@opt_human_readable
150-
@opt_token
151-
@opt_token_file
149+
@opt_human_readable()
150+
@opt_token()
151+
@opt_token_file()
152152
@recast_exceptions_to_click(AuthException, FileNotFoundError)
153153
def cmd_jwt_decode(ctx, token: str, token_file: pathlib.Path, human_readable):
154154
"""
@@ -160,9 +160,9 @@ def cmd_jwt_decode(ctx, token: str, token_file: pathlib.Path, human_readable):
160160

161161
@cmd_jwt.command("validate-oauth")
162162
@click.pass_context
163-
@opt_human_readable
164-
@opt_token
165-
@opt_token_file
163+
@opt_human_readable()
164+
@opt_token()
165+
@opt_token_file()
166166
@opt_audience()
167167
@opt_issuer()
168168
@recast_exceptions_to_click(AuthException, FileNotFoundError)
@@ -227,9 +227,9 @@ def cmd_jwt_validate_oauth(ctx, token, token_file, audience, issuer, human_reada
227227

228228
@cmd_jwt.command("validate-rs256", hidden=True)
229229
@click.pass_context
230-
@opt_human_readable
231-
@opt_token
232-
@opt_token_file
230+
@opt_human_readable()
231+
@opt_token()
232+
@opt_token_file()
233233
@recast_exceptions_to_click(AuthException, FileNotFoundError, NotImplementedError)
234234
def cmd_jwt_validate_rs256(ctx, token, token_file, human_readable):
235235
"""
@@ -241,9 +241,9 @@ def cmd_jwt_validate_rs256(ctx, token, token_file, human_readable):
241241

242242
@cmd_jwt.command("validate-hs512", hidden=True)
243243
@click.pass_context
244-
@opt_human_readable
245-
@opt_token
246-
@opt_token_file
244+
@opt_human_readable()
245+
@opt_token()
246+
@opt_token_file()
247247
@recast_exceptions_to_click(AuthException, FileNotFoundError, NotImplementedError)
248248
def cmd_jwt_validate_hs512(ctx, token, token_file, human_readable):
249249
"""

src/planet_auth_utils/commands/cli/main.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
opt_password,
3636
opt_loglevel,
3737
opt_open_browser,
38-
opt_show_qr_code,
38+
opt_qr_code,
3939
opt_sops,
4040
opt_audience,
4141
opt_scope,
@@ -49,8 +49,8 @@
4949

5050

5151
@click.group("plauth", invoke_without_command=True, help="Planet authentication utility")
52-
@opt_loglevel
53-
@opt_profile
52+
@opt_loglevel()
53+
@opt_profile()
5454
@click.pass_context
5555
@recast_exceptions_to_click(AuthException, FileNotFoundError, PermissionError)
5656
def cmd_plauth(ctx, loglevel, auth_profile):
@@ -146,20 +146,20 @@ def cmd_plauth_reset():
146146

147147

148148
@cmd_plauth.command("login")
149-
@opt_open_browser
150-
@opt_show_qr_code
151-
@opt_scope
149+
@opt_open_browser()
150+
@opt_qr_code()
151+
@opt_scope()
152152
@opt_audience()
153-
@opt_organization
154-
@opt_project
155-
@opt_profile
156-
@opt_client_id
157-
@opt_client_secret
158-
@opt_api_key
153+
@opt_organization()
154+
@opt_project()
155+
@opt_profile()
156+
@opt_client_id()
157+
@opt_client_secret()
158+
@opt_api_key()
159159
@opt_username()
160160
@opt_password()
161-
@opt_sops
162-
@opt_yes_no
161+
@opt_sops()
162+
@opt_yes_no()
163163
@click.pass_context
164164
@recast_exceptions_to_click(AuthException, FileNotFoundError, PermissionError)
165165
def cmd_plauth_login(

src/planet_auth_utils/commands/cli/oauth_cmd.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
opt_project,
3636
opt_refresh,
3737
opt_scope,
38-
opt_show_qr_code,
38+
opt_qr_code,
3939
opt_sops,
4040
opt_username,
4141
opt_yes_no,
@@ -66,19 +66,19 @@ def cmd_oauth(ctx):
6666

6767

6868
@cmd_oauth.command("login")
69-
@opt_open_browser
70-
@opt_show_qr_code
71-
@opt_scope
69+
@opt_open_browser()
70+
@opt_qr_code()
71+
@opt_scope()
7272
@opt_audience()
73-
@opt_organization
74-
@opt_project
73+
@opt_organization()
74+
@opt_project()
7575
@opt_username()
7676
@opt_password()
77-
@opt_client_id
78-
@opt_client_secret
79-
@opt_sops
80-
@opt_yes_no
81-
@opt_extra
77+
@opt_client_id()
78+
@opt_client_secret()
79+
@opt_sops()
80+
@opt_yes_no()
81+
@opt_extra()
8282
@click.pass_context
8383
@recast_exceptions_to_click(AuthException, ValueError)
8484
def cmd_oauth_login(
@@ -132,7 +132,7 @@ def cmd_oauth_login(
132132

133133

134134
@cmd_oauth.command("refresh")
135-
@opt_scope
135+
@opt_scope()
136136
@click.pass_context
137137
@recast_exceptions_to_click(AuthException, FileNotFoundError)
138138
def cmd_oauth_refresh(ctx, scope):
@@ -185,7 +185,7 @@ def cmd_oauth_discovery(ctx):
185185

186186
@cmd_oauth.command("validate-access-token")
187187
@click.pass_context
188-
@opt_human_readable
188+
@opt_human_readable()
189189
@recast_exceptions_to_click(AuthException, FileNotFoundError)
190190
def cmd_oauth_validate_access_token_remote(ctx, human_readable):
191191
"""
@@ -207,8 +207,8 @@ def cmd_oauth_validate_access_token_remote(ctx, human_readable):
207207
@cmd_oauth.command("validate-access-token-local")
208208
@click.pass_context
209209
@opt_audience()
210-
@opt_scope
211-
@opt_human_readable
210+
@opt_scope()
211+
@opt_human_readable()
212212
@recast_exceptions_to_click(AuthException, FileNotFoundError)
213213
def cmd_oauth_validate_access_token_local(ctx, audience, scope, human_readable):
214214
"""
@@ -239,7 +239,7 @@ def cmd_oauth_validate_access_token_local(ctx, audience, scope, human_readable):
239239

240240
@cmd_oauth.command("validate-id-token")
241241
@click.pass_context
242-
@opt_human_readable
242+
@opt_human_readable()
243243
@recast_exceptions_to_click(AuthException, FileNotFoundError)
244244
def cmd_oauth_validate_id_token_remote(ctx, human_readable):
245245
"""
@@ -260,7 +260,7 @@ def cmd_oauth_validate_id_token_remote(ctx, human_readable):
260260

261261
@cmd_oauth.command("validate-id-token-local")
262262
@click.pass_context
263-
@opt_human_readable
263+
@opt_human_readable()
264264
@recast_exceptions_to_click(AuthException, FileNotFoundError)
265265
def cmd_oauth_validate_id_token_local(ctx, human_readable):
266266
"""
@@ -280,7 +280,7 @@ def cmd_oauth_validate_id_token_local(ctx, human_readable):
280280

281281
@cmd_oauth.command("validate-refresh-token")
282282
@click.pass_context
283-
@opt_human_readable
283+
@opt_human_readable()
284284
@recast_exceptions_to_click(AuthException, FileNotFoundError)
285285
def cmd_oauth_validate_refresh_token_remote(ctx, human_readable):
286286
"""
@@ -357,7 +357,7 @@ def cmd_oauth_userinfo(ctx):
357357

358358
@cmd_oauth.command("print-access-token")
359359
@click.pass_context
360-
@opt_refresh
360+
@opt_refresh()
361361
@recast_exceptions_to_click(AuthException, FileNotFoundError)
362362
def cmd_oauth_print_access_token(ctx, refresh):
363363
"""
@@ -390,7 +390,7 @@ def cmd_oauth_print_access_token(ctx, refresh):
390390

391391
@cmd_oauth.command("decode-access-token")
392392
@click.pass_context
393-
@opt_human_readable
393+
@opt_human_readable()
394394
@recast_exceptions_to_click(AuthException, FileNotFoundError)
395395
def cmd_oauth_decode_jwt_access_token(ctx, human_readable):
396396
"""
@@ -406,7 +406,7 @@ def cmd_oauth_decode_jwt_access_token(ctx, human_readable):
406406

407407
@cmd_oauth.command("decode-id-token")
408408
@click.pass_context
409-
@opt_human_readable
409+
@opt_human_readable()
410410
@recast_exceptions_to_click(AuthException, FileNotFoundError)
411411
def cmd_oauth_decode_jwt_id_token(ctx, human_readable):
412412
"""
@@ -420,7 +420,7 @@ def cmd_oauth_decode_jwt_id_token(ctx, human_readable):
420420

421421
@cmd_oauth.command("decode-refresh-token")
422422
@click.pass_context
423-
@opt_human_readable
423+
@opt_human_readable()
424424
@recast_exceptions_to_click(AuthException, FileNotFoundError)
425425
def cmd_oauth_decode_jwt_refresh_token(ctx, human_readable):
426426
"""

0 commit comments

Comments
 (0)