Skip to content

Commit 29dd249

Browse files
committed
#13 Clean up configuration yaml and environment variables
1 parent 65f2a82 commit 29dd249

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

check_done/authentication.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
import requests
55

66
from check_done.common import (
7-
CHECK_DONE_GITHUB_APP_ID,
8-
CHECK_DONE_GITHUB_APP_PRIVATE_KEY,
97
AuthenticationError,
108
HttpBearerAuth,
9+
config_info,
1110
)
1211

12+
_CHECK_DONE_GITHUB_APP_ID = config_info().check_done_github_app_id
13+
_CHECK_DONE_GITHUB_APP_PRIVATE_KEY = config_info().check_done_github_app_private_key
1314
_GRANT_TYPE = "urn:ietf:params:oauth:grant-type:device_code"
1415
_SECONDS_PER_MINUTE = 60
1516
_ISSUED_AT = int(time.time())
@@ -50,9 +51,9 @@ def _generated_jwt_token() -> str:
5051
payload = {
5152
"exp": _EXPIRES_AT,
5253
"iat": _ISSUED_AT,
53-
"iss": CHECK_DONE_GITHUB_APP_ID,
54+
"iss": _CHECK_DONE_GITHUB_APP_ID,
5455
}
55-
return jwt.encode(payload, CHECK_DONE_GITHUB_APP_PRIVATE_KEY, algorithm="RS256")
56+
return jwt.encode(payload, _CHECK_DONE_GITHUB_APP_PRIVATE_KEY, algorithm="RS256")
5657
except Exception as error:
5758
raise AuthenticationError(f"Cannot generate JWT token: {error}") from error
5859

check_done/common.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
from requests.auth import AuthBase
1111

1212
load_dotenv()
13-
_ENVVAR_CHECK_DONE_GITHUB_APP_ID = "CHECK_DONE_GITHUB_APP_ID"
14-
_ENVVAR_CHECK_DONE_GITHUB_APP_PRIVATE_KEY = "CHECK_DONE_GITHUB_APP_PRIVATE_KEY"
15-
CHECK_DONE_GITHUB_APP_ID = os.environ.get(_ENVVAR_CHECK_DONE_GITHUB_APP_ID)
16-
CHECK_DONE_GITHUB_APP_PRIVATE_KEY = os.environ.get(_ENVVAR_CHECK_DONE_GITHUB_APP_PRIVATE_KEY)
1713

1814
_GITHUB_ORGANIZATION_NAME_AND_PROJECT_NUMBER_URL_REGEX = re.compile(
1915
r"https://github\.com/orgs/(?P<organization_name>[a-zA-Z0-9\-]+)/projects/(?P<project_number>[0-9]+).*"
@@ -22,20 +18,21 @@
2218

2319

2420
class _ConfigInfo(BaseModel):
25-
board_url: str
26-
api_key: str
27-
28-
@field_validator("api_key", mode="before")
29-
def api_key_from_env(cls, api_key: Any | None):
30-
if isinstance(api_key, str):
31-
stripped_api_key = api_key.strip()
21+
project_board_url: str
22+
check_done_github_app_id: str
23+
check_done_github_app_private_key: str
24+
25+
@field_validator("check_done_github_app_id", "check_done_github_app_private_key", mode="before")
26+
def value_from_env(cls, value: Any | None):
27+
if isinstance(value, str):
28+
stripped_value = value.strip()
3229
result = (
33-
resolved_environment_variables(api_key)
34-
if stripped_api_key.startswith("${") and stripped_api_key.endswith("}")
35-
else stripped_api_key
30+
resolved_environment_variables(value)
31+
if stripped_value.startswith("${") and stripped_value.endswith("}")
32+
else stripped_value
3633
)
3734
else:
38-
result = api_key
35+
result = value
3936
return result
4037

4138

check_done/done_project_items_info/done_project_items_info.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
)
2828

2929
_GRAPHQL_ENDPOINT = "https://api.github.com/graphql"
30-
_BOARD_URL = config_info().board_url
31-
ORGANIZATION_NAME, PROJECT_NUMBER = github_organization_name_and_project_number_from_url_if_matches(_BOARD_URL)
30+
_PROJECT_BOARD_URL = config_info().project_board_url
31+
ORGANIZATION_NAME, PROJECT_NUMBER = github_organization_name_and_project_number_from_url_if_matches(_PROJECT_BOARD_URL)
3232
_ACCESS_TOKEN = github_app_access_token(ORGANIZATION_NAME)
3333
_PATH_TO_QUERIES = Path(__file__).parent.parent / "done_project_items_info" / "queries"
3434
_MAX_ENTRIES_PER_PAGE = 100

data/.check_done.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
board_url: "https://github.com/orgs/siisurit/projects/2"
2-
api_key: ${GITHUB_API_KEY}
1+
project_board_url: "https://github.com/orgs/siisurit/projects/2"
2+
check_done_github_app_id: ${CHECK_DONE_GITHUB_APP_ID}
3+
check_done_github_app_private_key: ${CHECK_DONE_GITHUB_APP_PRIVATE_KEY}

0 commit comments

Comments
 (0)