Skip to content

Commit f8fbbef

Browse files
authored
Add flag for test-net DCL (#786)
1 parent 938ae9f commit f8fbbef

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

matter_server/server/__main__.py

+7
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@
9898
default=None,
9999
help="Directory where PAA root certificates are stored.",
100100
)
101+
parser.add_argument(
102+
"--enable-test-net-dcl",
103+
type=bool,
104+
default=False,
105+
help="Enable PAA root certificates and other device information from test-net DCL.",
106+
)
101107

102108
args = parser.parse_args()
103109

@@ -181,6 +187,7 @@ def main() -> None:
181187
args.listen_address,
182188
args.primary_interface,
183189
args.paa_root_cert_dir,
190+
args.enable_test_net_dcl,
184191
)
185192

186193
async def handle_stop(loop: asyncio.AbstractEventLoop) -> None:

matter_server/server/helpers/paa_certificates.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ async def fetch_dcl_certificates(
149149
# are correctly captured
150150

151151

152-
async def fetch_git_certificates(paa_root_cert_dir: Path) -> int:
152+
async def fetch_git_certificates(
153+
paa_root_cert_dir: Path, prefix: str | None = None
154+
) -> int:
153155
"""Fetch Git PAA Certificates."""
154156
fetch_count = 0
155157
LOGGER.info("Fetching the latest PAA root certificates from Git.")
@@ -163,6 +165,8 @@ async def fetch_git_certificates(paa_root_cert_dir: Path) -> int:
163165
git_certs = {item["name"].split(".")[0] for item in contents}
164166
# Fetch certificates
165167
for cert in git_certs:
168+
if prefix and not cert.startswith(prefix):
169+
continue
166170
async with http_session.get(f"{GIT_URL}/{cert}.pem") as response:
167171
certificate = await response.text()
168172
if await write_paa_root_cert(
@@ -238,6 +242,11 @@ def _check_paa_root_dir(
238242

239243
if fetch_test_certificates:
240244
total_fetch_count += await fetch_git_certificates(paa_root_cert_dir)
245+
else:
246+
# Treat the Chip-Test certificates as production, we use them in our examples
247+
total_fetch_count += await fetch_git_certificates(
248+
paa_root_cert_dir, "Chip-Test"
249+
)
241250

242251
await loop.run_in_executor(None, paa_root_cert_dir_version.write_text, "1")
243252

matter_server/server/server.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ def __init__(
108108
listen_addresses: list[str] | None = None,
109109
primary_interface: str | None = None,
110110
paa_root_cert_dir: Path | None = None,
111+
enable_test_net_dcl: bool = False,
111112
) -> None:
112113
"""Initialize the Matter Server."""
113114
self.storage_path = storage_path
@@ -120,6 +121,7 @@ def __init__(
120121
self.paa_root_cert_dir = DEFAULT_PAA_ROOT_CERTS_DIR
121122
else:
122123
self.paa_root_cert_dir = Path(paa_root_cert_dir).absolute()
124+
self.enable_test_net_dcl = enable_test_net_dcl
123125
self.logger = logging.getLogger(__name__)
124126
self.app = web.Application()
125127
self.loop: asyncio.AbstractEventLoop | None = None
@@ -156,7 +158,11 @@ async def start(self) -> None:
156158

157159
# (re)fetch all PAA certificates once at startup
158160
# NOTE: this must be done before initializing the controller
159-
await fetch_certificates(self.paa_root_cert_dir)
161+
await fetch_certificates(
162+
self.paa_root_cert_dir,
163+
fetch_test_certificates=self.enable_test_net_dcl,
164+
fetch_production_certificates=True,
165+
)
160166

161167
# Initialize our (intermediate) device controller which keeps track
162168
# of Matter devices and their subscriptions.

0 commit comments

Comments
 (0)