19
19
20
20
from matter_server .server .const import PAA_ROOT_CERTS_DIR
21
21
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
-
27
22
# Git repo details
28
23
OWNER = "project-chip"
29
24
REPO = "connectedhomeip"
30
25
PATH = "credentials/development/paa-root-certs"
31
26
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
+
32
35
33
36
async def get_directory_contents (owner : str , repo : str , path : str ) -> List [str ]:
34
37
"""
@@ -55,28 +58,6 @@ async def get_directory_contents(owner: str, repo: str, path: str) -> List[str]:
55
58
return []
56
59
57
60
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
-
80
61
async def write_paa_root_cert (certificate : str , subject : str ) -> None :
81
62
"""Write certificate from string to file."""
82
63
@@ -170,12 +151,14 @@ async def fetch_git_certificates() -> int:
170
151
"""Fetch Git PAA Certificates."""
171
152
fetch_count = 0
172
153
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 })
173
157
try :
174
158
async with ClientSession (raise_for_status = True ) as http_session :
175
- for cert in GIT_CERTS :
159
+ for cert in git_certs :
176
160
if cert in LAST_CERT_IDS :
177
161
continue
178
-
179
162
async with http_session .get (f"{ GIT_URL } /{ cert } .pem" ) as response :
180
163
certificate = await response .text ()
181
164
await write_paa_root_cert (certificate , cert )
0 commit comments