|
16 | 16 | import logging
|
17 | 17 | import importlib.metadata
|
18 | 18 | import sys
|
| 19 | +import time |
19 | 20 |
|
20 |
| -from planet_auth import Auth, AuthException, setStructuredLogging |
| 21 | +from planet_auth import Auth, AuthException, setStructuredLogging, ObjectStorageProvider, ObjectStorageProvider_KeyType |
| 22 | +from planet_auth.constants import USER_CONFIG_FILE |
21 | 23 |
|
22 | 24 | from planet_auth_utils.plauth_factory import PlanetAuthFactory
|
| 25 | +from planet_auth_utils.profile import Profile |
23 | 26 |
|
24 | 27 | from .options import (
|
25 | 28 | opt_organization,
|
@@ -119,6 +122,29 @@ def _pkg_display_version(pkg_name):
|
119 | 122 | print(f"planet : {_pkg_display_version('planet')}")
|
120 | 123 |
|
121 | 124 |
|
| 125 | +@cmd_plauth.command("reset") |
| 126 | +def cmd_plauth_reset(): |
| 127 | + """ |
| 128 | + Reset saved auth state. |
| 129 | +
|
| 130 | + Old auth state is not deleted. It is moved aside and preserved. |
| 131 | + """ |
| 132 | + save_tag = time.strftime("%Y-%m-%d-%H%M%S") |
| 133 | + |
| 134 | + # The CLI only supports the default storage provider right now. |
| 135 | + storage_provider = ObjectStorageProvider._default_storage_provider() |
| 136 | + |
| 137 | + user_conf_objkey = ObjectStorageProvider_KeyType(USER_CONFIG_FILE) |
| 138 | + if storage_provider.obj_exists(user_conf_objkey): |
| 139 | + user_conf_objkey_offname = ObjectStorageProvider_KeyType(USER_CONFIG_FILE + f"-{save_tag}") |
| 140 | + storage_provider.obj_rename(user_conf_objkey, user_conf_objkey_offname) |
| 141 | + |
| 142 | + profile_dir_objkey = ObjectStorageProvider_KeyType(Profile.profile_root()) |
| 143 | + if storage_provider.obj_exists(profile_dir_objkey): |
| 144 | + profile_dir_objkey_offname = ObjectStorageProvider_KeyType(Profile.profile_root().name + f"-{save_tag}") |
| 145 | + storage_provider.obj_rename(profile_dir_objkey, profile_dir_objkey_offname) |
| 146 | + |
| 147 | + |
122 | 148 | @cmd_plauth.command("login")
|
123 | 149 | @opt_open_browser
|
124 | 150 | @opt_show_qr_code
|
|
0 commit comments