Skip to content

Commit baf08fc

Browse files
committed
1. Fetch GIT_CERTS from within main function
2. Fix Git URL 3. Git URL uses variables for repo, directory, project data
1 parent ed41e29 commit baf08fc

File tree

1 file changed

+12
-29
lines changed

1 file changed

+12
-29
lines changed

matter_server/server/helpers/paa_certificates.py

+12-29
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@
1919

2020
from matter_server.server.const import PAA_ROOT_CERTS_DIR
2121

22-
LOGGER = logging.getLogger(__name__)
23-
PRODUCTION_URL = "https://on.dcl.csa-iot.org"
24-
TEST_URL = "https://on.test-net.dcl.csa-iot.org"
25-
GIT_URL = "https://github.com/project-chip/connectedhomeip/raw/master/credentials/development/paa-root-certs" # pylint: disable=line-too-long
26-
2722
# Git repo details
2823
OWNER = "project-chip"
2924
REPO = "connectedhomeip"
3025
PATH = "credentials/development/paa-root-certs"
3126

27+
LOGGER = logging.getLogger(__name__)
28+
PRODUCTION_URL = "https://on.dcl.csa-iot.org"
29+
TEST_URL = "https://on.test-net.dcl.csa-iot.org"
30+
GIT_URL = f"https://raw.githubusercontent.com/{OWNER}/{REPO}/master/{PATH}"
31+
32+
33+
LAST_CERT_IDS: set[str] = set()
34+
3235

3336
async def get_directory_contents(owner: str, repo: str, path: str) -> List[str]:
3437
"""
@@ -55,28 +58,6 @@ async def get_directory_contents(owner: str, repo: str, path: str) -> List[str]:
5558
return []
5659

5760

58-
async def get_git_file_list() -> List[str]:
59-
"""
60-
Retrieve a list of unique file names from a Git repository.
61-
62-
This function fetches the list of file names from a specified path in a Git repository,
63-
filters out the file extensions, and returns a list of unique file names.
64-
65-
Returns:
66-
List[str]: A list of unique file names.
67-
"""
68-
file_list = await get_directory_contents(OWNER, REPO, PATH)
69-
# Filter out extension and remove duplicates
70-
unique_file_names = list({file.split(".")[0] for file in file_list})
71-
return unique_file_names
72-
73-
74-
GIT_CERTS = asyncio.run(get_git_file_list())
75-
76-
77-
LAST_CERT_IDS: set[str] = set()
78-
79-
8061
async def write_paa_root_cert(certificate: str, subject: str) -> None:
8162
"""Write certificate from string to file."""
8263

@@ -170,12 +151,14 @@ async def fetch_git_certificates() -> int:
170151
"""Fetch Git PAA Certificates."""
171152
fetch_count = 0
172153
LOGGER.info("Fetching the latest PAA root certificates from Git.")
154+
file_list = await get_directory_contents(OWNER, REPO, PATH)
155+
# Filter out extension and remove duplicates
156+
git_certs = list({file.split(".")[0] for file in file_list})
173157
try:
174158
async with ClientSession(raise_for_status=True) as http_session:
175-
for cert in GIT_CERTS:
159+
for cert in git_certs:
176160
if cert in LAST_CERT_IDS:
177161
continue
178-
179162
async with http_session.get(f"{GIT_URL}/{cert}.pem") as response:
180163
certificate = await response.text()
181164
await write_paa_root_cert(certificate, cert)

0 commit comments

Comments
 (0)