-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from pmuller/feature/AGE_IDENTITY_FILE-environm…
…ent-variable feat: add support for the $AGE_IDENTITY_FILE environment variable
- Loading branch information
Showing
14 changed files
with
250 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,34 @@ | ||
import os | ||
import re | ||
from pathlib import Path | ||
|
||
import pyrage | ||
|
||
|
||
def read_identity_file(path: Path) -> pyrage.x25519.Identity: | ||
def read_identity_file(path: Path | str) -> pyrage.x25519.Identity: | ||
if isinstance(path, str): | ||
path = Path(path) | ||
|
||
# Remove comments | ||
identity_string = re.sub( | ||
r"^#.*\n?", | ||
"", | ||
path.read_text(), | ||
flags=re.MULTILINE, | ||
).rstrip("\n") | ||
|
||
return pyrage.x25519.Identity.from_str(identity_string) | ||
|
||
|
||
def get_identity_from_environment() -> pyrage.x25519.Identity | None: | ||
path_string = os.environ.get("AGE_IDENTITY_FILE") | ||
|
||
if path_string is None: | ||
return None | ||
|
||
path = Path(path_string) | ||
|
||
if not path.is_file(): | ||
raise FileNotFoundError(f"AGE_IDENTITY_FILE does not exist: {path}") | ||
|
||
return read_identity_file(path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
ROOT = Path(__file__).parent.parent | ||
EXAMPLE_PATH = ROOT / "example" | ||
|
||
|
||
@pytest.fixture() | ||
def example_age_key() -> str: | ||
return str(EXAMPLE_PATH / "config" / "age.key") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
from saltfactories.cli.call import SaltCall | ||
from saltfactories.daemons.minion import SaltMinion | ||
from saltfactories.manager import FactoriesManager | ||
from saltfactories.utils import random_string | ||
|
||
from tests.integration.conftest import MINION_CONFIG | ||
|
||
|
||
@pytest.fixture() | ||
def minion(salt_factories: FactoriesManager, example_age_key: str) -> SaltMinion: | ||
overrides = MINION_CONFIG.copy() | ||
overrides["age_identity_file"] = example_age_key | ||
return salt_factories.salt_minion_daemon( | ||
random_string("minion-"), | ||
overrides=overrides, | ||
) | ||
|
||
|
||
def test(salt_call_cli: SaltCall, tmp_path: Path) -> None: | ||
_ = salt_call_cli.run("state.apply", pillar=f'{{"prefix": "{tmp_path}"}}') | ||
assert (tmp_path / "test-public").read_text() == "that's not a secret\n" | ||
assert (tmp_path / "test-private").read_text() == "test-secret-value\n" |
Oops, something went wrong.