340fd281628f1dc2498037e636f1772ec662bbd4
Marco Ricci Change the author e-mail ad...

Marco Ricci authored 2 months ago

1) # SPDX-FileCopyrightText: 2024 Marco Ricci <software@the13thletter.info>
Marco Ricci Add command-line interface...

Marco Ricci authored 2 months ago

2) #
3) # SPDX-License-Identifier: MIT
4) 
Marco Ricci Move exporter command-line...

Marco Ricci authored 2 months ago

5) """Foreign configuration exporter for derivepassphrase."""
Marco Ricci Add command-line interface...

Marco Ricci authored 2 months ago

6) 
7) from __future__ import annotations
8) 
Marco Ricci Move vault key and path det...

Marco Ricci authored 2 months ago

9) import os
Marco Ricci Add command-line interface...

Marco Ricci authored 2 months ago

10) 
11) import derivepassphrase as dpp
12) 
13) __author__ = dpp.__author__
14) __version__ = dpp.__version__
15) 
Marco Ricci Move exporter command-line...

Marco Ricci authored 2 months ago

16) __all__ = ()
Marco Ricci Move vault key and path det...

Marco Ricci authored 2 months ago

17) 
18) 
19) def get_vault_key() -> bytes:
Marco Ricci Fix miscellaneous small doc...

Marco Ricci authored 2 months ago

20)     """Automatically determine the vault(1) master key/password.
Marco Ricci Move vault key and path det...

Marco Ricci authored 2 months ago

21) 
22)     Query the `VAULT_KEY`, `LOGNAME`, `USER` and `USERNAME` environment
Marco Ricci Fix miscellaneous small doc...

Marco Ricci authored 2 months ago

23)     variables, in that order.  This is the same algorithm that vault
24)     uses.
Marco Ricci Move vault key and path det...

Marco Ricci authored 2 months ago

25) 
26)     Returns:
27)         The master key/password.  This is generally used as input to
28)         a key-derivation function to determine the *actual* encryption
29)         and signing keys for the vault configuration.
30) 
31)     Raises:
32)         KeyError:
33)             We cannot find any of the named environment variables.
34)             Please set `VAULT_KEY` manually to the desired value.
35) 
36)     """
37)     username = (
38)         os.environb.get(b'VAULT_KEY')
39)         or os.environb.get(b'LOGNAME')
40)         or os.environb.get(b'USER')
41)         or os.environb.get(b'USERNAME')
42)     )
43)     if not username:
44)         env_var = 'VAULT_KEY'
45)         raise KeyError(env_var)
46)     return username
47) 
48) 
49) def get_vault_path() -> str | bytes | os.PathLike:
Marco Ricci Fix miscellaneous small doc...

Marco Ricci authored 2 months ago

50)     """Automatically determine the vault(1) configuration path.
Marco Ricci Move vault key and path det...

Marco Ricci authored 2 months ago

51) 
52)     Query the `VAULT_PATH` environment variable, or default to
Marco Ricci Fix miscellaneous small doc...

Marco Ricci authored 2 months ago

53)     `~/.vault`.  This is the same algorithm that vault uses.  If not