Marco Ricci commited on 2024-12-25 17:15:23
Zeige 4 geänderte Dateien mit 56 Einfügungen und 51 Löschungen.
| ... | ... |
@@ -8,14 +8,18 @@ |
| 8 | 8 |
|
| 9 | 9 |
### Changed |
| 10 | 10 |
|
| 11 |
- - Calling [`derivepassphrase.cli.derivepassphrase_export`][], |
|
| 12 |
- [`derivepassphrase.cli.derivepassphrase_export_vault`][] or |
|
| 13 |
- [`derivepassphrase.cli.derivepassphrase_vault`][], or calling |
|
| 14 |
- [`derivepassphrase.cli.derivepassphrase`][] via its |
|
| 11 |
+ - Calling [`derivepassphrase_export`] |
|
| 12 |
+ [derivepassphrase.cli.derivepassphrase_export], |
|
| 13 |
+ [`derivepassphrase_export_vault`] |
|
| 14 |
+ [derivepassphrase.cli.derivepassphrase_export_vault] or |
|
| 15 |
+ [`derivepassphrase_vault`] |
|
| 16 |
+ [derivepassphrase.cli.derivepassphrase_vault], or calling |
|
| 17 |
+ [`derivepassphrase`] [derivepassphrase.cli.derivepassphrase] via its |
|
| 15 | 18 |
[`.main`][click.BaseCommand.main] method, causes those functions to use |
| 16 | 19 |
the standard Python [logging][] and [warnings][] facilities to issue |
| 17 | 20 |
diagnostic messages, without output to standard error. (This includes |
| 18 | 21 |
using [`click.testing.CliRunner`][], which uses `.main` calls under the |
| 19 |
- hood.) Calling [`derivepassphrase.cli.derivepassphrase`][] directly as |
|
| 20 |
- a function diverts diagnostic messages to standard error. |
|
| 22 |
+ hood.) Calling [`derivepassphrase`] |
|
| 23 |
+ [derivepassphrase.cli.derivepassphrase] directly as a function diverts |
|
| 24 |
+ diagnostic messages to standard error. |
|
| 21 | 25 |
|
| ... | ... |
@@ -6,8 +6,8 @@ |
| 6 | 6 |
files are user-editable, the data files are `derivepassphrase`-editable. |
| 7 | 7 |
|
| 8 | 8 |
The configuration files are in TOML format, so installing |
| 9 |
- `derivepassphrase` on Python 3.10 and older requires the [`tomli`][] |
|
| 10 |
- package. |
|
| 9 |
+ `derivepassphrase` on Python 3.10 and older requires the |
|
| 10 |
+ [`tomli`][tomli] package. |
|
| 11 | 11 |
|
| 12 | 12 |
[tomli]: https://pypi.org/project/tomli/ |
| 13 | 13 |
|
| ... | ... |
@@ -5,9 +5,9 @@ title: Reference overview |
| 5 | 5 |
## Man pages |
| 6 | 6 |
|
| 7 | 7 |
* [`derivepassphrase(1)`][top_man]: Derive a strong passphrase, deterministically, from a master secret. |
| 8 |
- * [`derivepassphrase-vault(1)`][top_man]: Derive a passphrase using the vault(1) derivation scheme. |
|
| 8 |
+ * [`derivepassphrase-vault(1)`][vault_man]: Derive a passphrase using the vault(1) derivation scheme. |
|
| 9 | 9 |
* [`derivepassphrase-export(1)`][export_man]: Export a foreign configuration to standard output. |
| 10 |
- * [`derivepassphrase-export-vault(1)`][export_man]: Export a vault-native configuration to standard output. |
|
| 10 |
+ * [`derivepassphrase-export-vault(1)`][export_vault_man]: Export a vault-native configuration to standard output. |
|
| 11 | 11 |
|
| 12 | 12 |
## Modules and packages (API docs) |
| 13 | 13 |
|
| ... | ... |
@@ -146,7 +146,8 @@ class CLIofPackageFormatter(logging.Formatter): |
| 146 | 146 |
`PKG.deprecation` (where `PKG` is the package name), else |
| 147 | 147 |
`"Warning: "`. |
| 148 | 148 |
* For records at level [`logging.ERROR`][] and |
| 149 |
- [`logging.CRITICAL`][] `"Error: "`, `LABEL` is `"ERROR: "`. |
|
| 149 |
+ [`logging.CRITICAL`][] `"Error: "`, `LABEL` is the empty |
|
| 150 |
+ string. |
|
| 150 | 151 |
|
| 151 | 152 |
The level indication strings at level `WARNING` or above are |
| 152 | 153 |
highlighted. Use [`click.echo`][] to output them and remove |
| ... | ... |
@@ -516,8 +517,8 @@ def standard_logging_options(f: Callable[P, R]) -> Callable[P, R]: |
| 516 | 517 |
"""Decorate the function with standard logging click options. |
| 517 | 518 |
|
| 518 | 519 |
Adds the three click options `-v`/`--verbose`, `-q`/`--quiet` and |
| 519 |
- `--debug`, which issue callbacks to the [`log_info`][], |
|
| 520 |
- [`silence_warnings`][] and [`log_debug`][] functions, respectively. |
|
| 520 |
+ `--debug`, which calls back into the [`adjust_logging_level`][] |
|
| 521 |
+ function (with different argument values). |
|
| 521 | 522 |
|
| 522 | 523 |
Args: |
| 523 | 524 |
f: A callable to decorate. |
| ... | ... |
@@ -1084,8 +1085,8 @@ def _get_suitable_ssh_keys( |
| 1084 | 1085 |
with ssh_agent.SSHAgentClient.ensure_agent_subcontext(conn) as client: |
| 1085 | 1086 |
try: |
| 1086 | 1087 |
all_key_comment_pairs = list(client.list_keys()) |
| 1087 |
- except EOFError as e: # pragma: no cover |
|
| 1088 |
- raise RuntimeError(_AGENT_COMMUNICATION_ERROR) from e |
|
| 1088 |
+ except EOFError as exc: # pragma: no cover |
|
| 1089 |
+ raise RuntimeError(_AGENT_COMMUNICATION_ERROR) from exc |
|
| 1089 | 1090 |
suitable_keys = copy.copy(all_key_comment_pairs) |
| 1090 | 1091 |
for pair in all_key_comment_pairs: |
| 1091 | 1092 |
key, _comment = pair |
| ... | ... |
@@ -1337,13 +1338,13 @@ def _key_to_phrase( |
| 1337 | 1338 |
with ssh_agent.SSHAgentClient.ensure_agent_subcontext() as client: |
| 1338 | 1339 |
try: |
| 1339 | 1340 |
return vault.Vault.phrase_from_key(key, conn=client) |
| 1340 |
- except ssh_agent.SSHAgentFailedError as e: |
|
| 1341 |
+ except ssh_agent.SSHAgentFailedError as exc: |
|
| 1341 | 1342 |
try: |
| 1342 | 1343 |
keylist = client.list_keys() |
| 1343 | 1344 |
except ssh_agent.SSHAgentFailedError: |
| 1344 | 1345 |
pass |
| 1345 |
- except Exception as e2: # noqa: BLE001 |
|
| 1346 |
- e.__context__ = e2 |
|
| 1346 |
+ except Exception as exc2: # noqa: BLE001 |
|
| 1347 |
+ exc.__context__ = exc2 |
|
| 1347 | 1348 |
else: |
| 1348 | 1349 |
if not any( # pragma: no branch |
| 1349 | 1350 |
k == key for k, _ in keylist |
| ... | ... |
@@ -1352,7 +1353,7 @@ def _key_to_phrase( |
| 1352 | 1353 |
'The requested SSH key is not loaded ' |
| 1353 | 1354 |
'into the agent.' |
| 1354 | 1355 |
) |
| 1355 |
- error_callback(e) |
|
| 1356 |
+ error_callback(exc) |
|
| 1356 | 1357 |
except KeyError: |
| 1357 | 1358 |
error_callback('Cannot find running SSH agent; check SSH_AUTH_SOCK')
|
| 1358 | 1359 |
except NotImplementedError: |
| ... | ... |
@@ -1360,8 +1361,8 @@ def _key_to_phrase( |
| 1360 | 1361 |
'Cannot connect to SSH agent because ' |
| 1361 | 1362 |
'this Python version does not support UNIX domain sockets' |
| 1362 | 1363 |
) |
| 1363 |
- except OSError as e: |
|
| 1364 |
- error_callback('Cannot connect to SSH agent: %s', e.strerror)
|
|
| 1364 |
+ except OSError as exc: |
|
| 1365 |
+ error_callback('Cannot connect to SSH agent: %s', exc.strerror)
|
|
| 1365 | 1366 |
|
| 1366 | 1367 |
|
| 1367 | 1368 |
def _print_config_as_sh_script( |
| ... | ... |
@@ -1500,9 +1501,9 @@ def _validate_occurrence_constraint( |
| 1500 | 1501 |
else: |
| 1501 | 1502 |
try: |
| 1502 | 1503 |
int_value = int(value, 10) |
| 1503 |
- except ValueError as e: |
|
| 1504 |
+ except ValueError as exc: |
|
| 1504 | 1505 |
msg = 'not an integer' |
| 1505 |
- raise click.BadParameter(msg) from e |
|
| 1506 |
+ raise click.BadParameter(msg) from exc |
|
| 1506 | 1507 |
if int_value < 0: |
| 1507 | 1508 |
msg = 'not a non-negative integer' |
| 1508 | 1509 |
raise click.BadParameter(msg) |
| ... | ... |
@@ -1537,9 +1538,9 @@ def _validate_length( |
| 1537 | 1538 |
else: |
| 1538 | 1539 |
try: |
| 1539 | 1540 |
int_value = int(value, 10) |
| 1540 |
- except ValueError as e: |
|
| 1541 |
+ except ValueError as exc: |
|
| 1541 | 1542 |
msg = 'not an integer' |
| 1542 |
- raise click.BadParameter(msg) from e |
|
| 1543 |
+ raise click.BadParameter(msg) from exc |
|
| 1543 | 1544 |
if int_value < 1: |
| 1544 | 1545 |
msg = 'not a positive integer' |
| 1545 | 1546 |
raise click.BadParameter(msg) |
| ... | ... |
@@ -1734,8 +1735,8 @@ DEFAULT_NOTES_MARKER = '# - - - - - >8 - - - - -' |
| 1734 | 1735 |
) |
| 1735 | 1736 |
@click.option( |
| 1736 | 1737 |
'--export-as', |
| 1737 |
- type=click.Choice(['JSON', 'sh']), |
|
| 1738 |
- default='JSON', |
|
| 1738 |
+ type=click.Choice(['json', 'sh']), |
|
| 1739 |
+ default='json', |
|
| 1739 | 1740 |
help='when exporting, export as JSON (default) or POSIX sh', |
| 1740 | 1741 |
cls=CompatibilityOption, |
| 1741 | 1742 |
) |
| ... | ... |
@@ -1963,10 +1964,10 @@ def derivepassphrase_vault( # noqa: C901,PLR0912,PLR0913,PLR0914,PLR0915 |
| 1963 | 1964 |
else: |
| 1964 | 1965 |
deprecation.info('Successfully migrated to %r.', new_name)
|
| 1965 | 1966 |
return backup_config |
| 1966 |
- except OSError as e: |
|
| 1967 |
- err('Cannot load config: %s: %r', e.strerror, e.filename)
|
|
| 1968 |
- except Exception as e: # noqa: BLE001 |
|
| 1969 |
- err('Cannot load config: %s', str(e), exc_info=e)
|
|
| 1967 |
+ except OSError as exc: |
|
| 1968 |
+ err('Cannot load config: %s: %r', exc.strerror, exc.filename)
|
|
| 1969 |
+ except Exception as exc: # noqa: BLE001 |
|
| 1970 |
+ err('Cannot load config: %s', str(exc), exc_info=exc)
|
|
| 1970 | 1971 |
|
| 1971 | 1972 |
def put_config(config: _types.VaultConfig, /) -> None: |
| 1972 | 1973 |
try: |
| ... | ... |
@@ -1981,10 +1982,10 @@ def derivepassphrase_vault( # noqa: C901,PLR0912,PLR0913,PLR0914,PLR0915 |
| 1981 | 1982 |
return _load_user_config() |
| 1982 | 1983 |
except FileNotFoundError: |
| 1983 | 1984 |
return {}
|
| 1984 |
- except OSError as e: |
|
| 1985 |
- err('Cannot load user config: %s: %r', e.strerror, e.filename)
|
|
| 1986 |
- except Exception as e: # noqa: BLE001 |
|
| 1987 |
- err('Cannot load user config: %s', str(e), exc_info=e)
|
|
| 1985 |
+ except OSError as exc: |
|
| 1986 |
+ err('Cannot load user config: %s: %r', exc.strerror, exc.filename)
|
|
| 1987 |
+ except Exception as exc: # noqa: BLE001 |
|
| 1988 |
+ err('Cannot load user config: %s', str(exc), exc_info=exc)
|
|
| 1988 | 1989 |
|
| 1989 | 1990 |
configuration: _types.VaultConfig |
| 1990 | 1991 |
|
| ... | ... |
@@ -2089,10 +2090,10 @@ def derivepassphrase_vault( # noqa: C901,PLR0912,PLR0913,PLR0914,PLR0915 |
| 2089 | 2090 |
# error information. |
| 2090 | 2091 |
with infile: |
| 2091 | 2092 |
maybe_config = json.load(infile) |
| 2092 |
- except json.JSONDecodeError as e: |
|
| 2093 |
- err('Cannot load config: cannot decode JSON: %s', e)
|
|
| 2094 |
- except OSError as e: |
|
| 2095 |
- err('Cannot load config: %s: %r', e.strerror, e.filename)
|
|
| 2093 |
+ except json.JSONDecodeError as exc: |
|
| 2094 |
+ err('Cannot load config: cannot decode JSON: %s', exc)
|
|
| 2095 |
+ except OSError as exc: |
|
| 2096 |
+ err('Cannot load config: %s: %r', exc.strerror, exc.filename)
|
|
| 2096 | 2097 |
cleaned = _types.clean_up_falsy_vault_config_values(maybe_config) |
| 2097 | 2098 |
if not _types.is_vault_config(maybe_config): |
| 2098 | 2099 |
err('Cannot load config: %s', _INVALID_VAULT_CONFIG)
|
| ... | ... |
@@ -2137,8 +2138,8 @@ def derivepassphrase_vault( # noqa: C901,PLR0912,PLR0913,PLR0914,PLR0915 |
| 2137 | 2138 |
cast(dict[str, Any], value), |
| 2138 | 2139 |
main_config=user_config, |
| 2139 | 2140 |
) |
| 2140 |
- except AssertionError as e: |
|
| 2141 |
- err('The configuration file is invalid. ' + str(e))
|
|
| 2141 |
+ except AssertionError as exc: |
|
| 2142 |
+ err('The configuration file is invalid. ' + str(exc))
|
|
| 2142 | 2143 |
global_obj = maybe_config.get('global', {})
|
| 2143 | 2144 |
has_key = _types.js_truthiness(global_obj.get('key'))
|
| 2144 | 2145 |
has_phrase = _types.js_truthiness(global_obj.get('phrase'))
|
| ... | ... |
@@ -2225,8 +2226,8 @@ def derivepassphrase_vault( # noqa: C901,PLR0912,PLR0913,PLR0914,PLR0915 |
| 2225 | 2226 |
) |
| 2226 | 2227 |
else: |
| 2227 | 2228 |
json.dump(configuration, outfile) |
| 2228 |
- except OSError as e: |
|
| 2229 |
- err('Cannot store config: %s: %r', e.strerror, e.filename)
|
|
| 2229 |
+ except OSError as exc: |
|
| 2230 |
+ err('Cannot store config: %s: %r', exc.strerror, exc.filename)
|
|
| 2230 | 2231 |
else: |
| 2231 | 2232 |
configuration = get_config() |
| 2232 | 2233 |
# This block could be type checked more stringently, but this |
| ... | ... |
@@ -2272,14 +2273,14 @@ def derivepassphrase_vault( # noqa: C901,PLR0912,PLR0913,PLR0914,PLR0915 |
| 2272 | 2273 |
'Cannot connect to SSH agent because ' |
| 2273 | 2274 |
'this Python version does not support UNIX domain sockets' |
| 2274 | 2275 |
) |
| 2275 |
- except OSError as e: |
|
| 2276 |
- err('Cannot connect to SSH agent: %s', e.strerror)
|
|
| 2276 |
+ except OSError as exc: |
|
| 2277 |
+ err('Cannot connect to SSH agent: %s', exc.strerror)
|
|
| 2277 | 2278 |
except ( |
| 2278 | 2279 |
LookupError, |
| 2279 | 2280 |
RuntimeError, |
| 2280 | 2281 |
ssh_agent.SSHAgentFailedError, |
| 2281 |
- ) as e: |
|
| 2282 |
- err(str(e)) |
|
| 2282 |
+ ) as exc: |
|
| 2283 |
+ err(str(exc)) |
|
| 2283 | 2284 |
elif use_phrase: |
| 2284 | 2285 |
maybe_phrase = _prompt_for_passphrase() |
| 2285 | 2286 |
if not maybe_phrase: |
| ... | ... |
@@ -2304,8 +2305,8 @@ def derivepassphrase_vault( # noqa: C901,PLR0912,PLR0913,PLR0914,PLR0915 |
| 2304 | 2305 |
{'phrase': phrase},
|
| 2305 | 2306 |
main_config=user_config, |
| 2306 | 2307 |
) |
| 2307 |
- except AssertionError as e: |
|
| 2308 |
- err('The configuration file is invalid. ' + str(e))
|
|
| 2308 |
+ except AssertionError as exc: |
|
| 2309 |
+ err('The configuration file is invalid. ' + str(exc))
|
|
| 2309 | 2310 |
if 'key' in settings: |
| 2310 | 2311 |
if service: |
| 2311 | 2312 |
logger.warning( |
| ... | ... |
@@ -2366,8 +2367,8 @@ def derivepassphrase_vault( # noqa: C901,PLR0912,PLR0913,PLR0914,PLR0915 |
| 2366 | 2367 |
{'phrase': phrase},
|
| 2367 | 2368 |
main_config=user_config, |
| 2368 | 2369 |
) |
| 2369 |
- except AssertionError as e: |
|
| 2370 |
- err('The configuration file is invalid. ' + str(e))
|
|
| 2370 |
+ except AssertionError as exc: |
|
| 2371 |
+ err('The configuration file is invalid. ' + str(exc))
|
|
| 2371 | 2372 |
|
| 2372 | 2373 |
# If either --key or --phrase are given, use that setting. |
| 2373 | 2374 |
# Otherwise, if both key and phrase are set in the config, |
| 2374 | 2375 |