encrypt-email: make globals a little more obvious
Jeremy Fleischman committed
Mar 28, 2025 at 18:15 UTC
5e1844f6b667485d5ec16014c87b54e9a1f55d63
1 file changed
+11
-10
non-critical-infra/packages/encrypt-email/encrypt-email.py
+11
-10
@@ -22,6 +22,12 @@ def find_relative_project_root() -> Path:
22
return find_project_root(Path.cwd()).relative_to(Path.cwd(), walk_up=True)
23
24
25
+PROJECT_ROOT = find_relative_project_root()
26
+NON_CRITICAL_INFRA_DIR = PROJECT_ROOT / "non-critical-infra"
27
+MAILING_LISTS_NIX = NON_CRITICAL_INFRA_DIR / "modules/mailserver/mailing-lists.nix"
28
+assert MAILING_LISTS_NIX.exists()
29
+
30
+
31
def encrypt_to_file(plaintext: str, secret_path: Path, force: bool) -> None:
32
if secret_path.exists():
33
if not force:
@@ -94,18 +100,18 @@ def address(address_id: str, email: str, force: bool) -> None:
100
click.secho("Removed whitespace surrounding given email address", fg="yellow")
101
email = clean_email
102
97
- secret_path = non_critical_infra_dir / f"secrets/{address_id}-email-address.umbriel"
103
+ secret_path = NON_CRITICAL_INFRA_DIR / f"secrets/{address_id}-email-address.umbriel"
104
encrypt_to_file(email, secret_path, force)
105
106
click.secho()
107
click.secho("Now add `", nl=False)
108
click.secho(
103
- secret_path.relative_to(mailing_lists_nix.parent, walk_up=True),
109
+ secret_path.relative_to(MAILING_LISTS_NIX.parent, walk_up=True),
110
fg="blue",
111
nl=False,
112
)
113
click.secho("` to the relevant mailing list in '", nl=False)
108
- click.secho(mailing_lists_nix, fg="blue")
114
+ click.secho(MAILING_LISTS_NIX, fg="blue")
115
116
117
@main.command()
@@ -130,7 +136,7 @@ def login(address_id: str, force: bool) -> None:
136
137
hashed_password = hash_password(password)
138
133
- secret_path = non_critical_infra_dir / f"secrets/{address_id}-email-login.umbriel"
139
+ secret_path = NON_CRITICAL_INFRA_DIR / f"secrets/{address_id}-email-login.umbriel"
140
encrypt_to_file(hashed_password, secret_path, force)
141
142
nix_code = dedent(
@@ -145,16 +151,11 @@ def login(address_id: str, force: bool) -> None:
151
)
152
click.secho()
153
click.secho("Now add this login account to ", nl=False)
148
- click.secho(mailing_lists_nix, fg="blue", nl=False)
154
+ click.secho(MAILING_LISTS_NIX, fg="blue", nl=False)
155
click.secho("'. Add or edit an entry that looks like this:")
156
click.secho()
157
click.secho(indent(nix_code, prefix=" " * 4), fg="blue")
158
159
160
if __name__ == "__main__":
155
- project_root = find_relative_project_root()
156
- non_critical_infra_dir = project_root / "non-critical-infra"
157
- mailing_lists_nix = non_critical_infra_dir / "modules/mailserver/mailing-lists.nix"
158
- assert mailing_lists_nix.exists()
159
-
161
main()