Verified Commit e05004bd authored by David Runge's avatar David Runge
Browse files

config: Make PRIVATE_TOKEN optional

arch_release_promotion/config.py:
Change `Settings.PRIVATE_TOKEN` to become an optional attribute, as it
is not required for readonly scenarios.
Order all `Settings` attributes alphabetically and add documentation for
them and their respective default values.
Change `Settings.validate_private_token()` to reflect the change in type
for `Settings.PRIVATE_TOKEN`.

tests/test_config.py:
Extend tests to also check for cases where `Settings.PRIVATE_TOKEN` is
None.
parent 598f81b5
......@@ -283,17 +283,24 @@ class Settings(BaseSettings):
Attributes
----------
gpgkey: str
GITLAB_URL: str
A URL for a GitLab upstream (defaults to "https://gitlab.archlinux.org")
GPGKEY: str
The PGP key id to use for artifact signatures
packager: str
The packager name and mail address to use for artifact signatures
MIRRORLIST_URL: str
A URL to derive a mirrorlist from (defaults to
"https://archlinux.org/mirrorlist/?country=all&protocol=http&protocol=https")
PACKAGER: str
The packager name and mail address (UID) to use for artifact signatures
PRIVATE_TOKEN: Optional[str]
An optional private token to use for authenticating against an upstream
"""
MIRRORLIST_URL: str = "https://archlinux.org/mirrorlist/?country=all&protocol=http&protocol=https"
GITLAB_URL: str = "https://gitlab.archlinux.org"
GPGKEY: str
MIRRORLIST_URL: str = "https://archlinux.org/mirrorlist/?country=all&protocol=http&protocol=https"
PACKAGER: str
PRIVATE_TOKEN: str
PRIVATE_TOKEN: Optional[str]
class Config:
......@@ -371,7 +378,7 @@ class Settings(BaseSettings):
return gpgkey
@validator("PRIVATE_TOKEN")
def validate_private_token(cls, private_token: str) -> str:
def validate_private_token(cls, private_token: Optional[str]) -> Optional[str]:
"""A validator for the PRIVATE_TOKEN attribute
Parameters
......@@ -390,6 +397,9 @@ class Settings(BaseSettings):
A gpgkey string in long-format
"""
if private_token is None:
return None
if len(private_token) < 20:
raise ValueError("The PRIVATE_TOKEN string has to represent a valid private token (20 chars).")
......
......@@ -3,7 +3,7 @@ import tempfile
from contextlib import nullcontext as does_not_raise
from pathlib import Path
from string import ascii_letters, ascii_uppercase
from typing import ContextManager, List
from typing import ContextManager, List, Optional
from unittest.mock import patch
from pydantic import ValidationError
......@@ -21,6 +21,12 @@ from arch_release_promotion import config
"".join(random.choice(ascii_letters) for x in range(20)),
does_not_raise(),
),
(
"".join(random.choice(ascii_uppercase) for x in range(40)),
"Foobar McFoo <foobar@archlinux.org>",
None,
does_not_raise(),
),
(
"".join(random.choice(ascii_uppercase) for x in range(40)),
"",
......@@ -62,13 +68,14 @@ from arch_release_promotion import config
def test_settings(
gpgkey: str,
packager: str,
private_token: str,
private_token: Optional[str],
expectation: ContextManager[str],
) -> None:
conf = tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", suffix=".conf", delete=False)
conf.write(f"GPGKEY='{gpgkey}'\n")
conf.write(f"PACKAGER='{packager}'\n")
conf.write(f"PRIVATE_TOKEN={private_token}\n")
if private_token:
conf.write(f"PRIVATE_TOKEN={private_token}\n")
conf.close()
with patch("arch_release_promotion.config.MAKEPKG_CONFIGS", [Path(conf.name)]):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment