credentials¶
lab.connectome.credentials
¶
Saving a secret where the project reads it.
The CAVE token is saved by lab.connectome.fetch.save_cave_token;
the other secrets are variables in the gitignored config.ENV.
check_env_value(key, value)
¶
Raise unless a variable can be written as one plain line.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Variable name in capitals, digits, and underscores. |
required |
value
|
str
|
Letters, digits, and |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
For a |
Examples:
Source code in lab/connectome/credentials.py
set_env_value(path, key, value)
¶
Set one variable of a .env file and keep every other line.
An existing line for key is replaced and any later one for it is
dropped; otherwise the line is added at the end.
The file is created readable by its owner only, and a file that
exists keeps its mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
The file; it is created when missing. |
required |
key
|
str
|
Variable name in capitals, digits, and underscores. |
required |
value
|
str
|
Letters, digits, and |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
For a |
Examples:
>>> import tempfile
>>> path = Path(tempfile.mkdtemp()) / ".env"
>>> _ = path.write_text("A=1\nTOKEN=old\n# kept\n")
>>> set_env_value(path, "TOKEN", "new")
>>> print(path.read_text(), end="")
A=1
TOKEN=new
# kept
>>> set_env_value(path, "OTHER", "x")
>>> path.read_text().splitlines()[-1]
'OTHER=x'