Skip to content

Commit 3efb9cc

Browse files
Zaperexnickboldt
andauthored
chore: update dynamic plugins install script to handle registries with custom ports (#4476)
* chore: update dynamic plugins install script to handle registries with custom ports Signed-off-by: Frank Kong <frkong@redhat.com> rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED * chore: suppress sonar warning for hardcoded ip in test case Signed-off-by: Frank Kong <frkong@redhat.com> rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED * chore: refactor regex for better legibility Signed-off-by: Frank Kong <frkong@redhat.com> rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED * chore: update regex to reject no tag/digest case and add more test cases Signed-off-by: Frank Kong <frkong@redhat.com> rh-pre-commit.version: 2.3.2 rh-pre-commit.check-secrets: ENABLED --------- Co-authored-by: Nick Boldt <nboldt@redhat.com>
1 parent ae1f401 commit 3efb9cc

2 files changed

Lines changed: 54 additions & 2 deletions

File tree

scripts/install-dynamic-plugins/install-dynamic-plugins.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,11 @@ def install(self, plugin: dict, plugin_path_by_hash: dict) -> str:
475475

476476
class OciPackageMerger(PackageMerger):
477477
EXPECTED_OCI_PATTERN = (
478-
r'^(' + OCI_PROTOCOL_PREFIX + r'[^\s:@]+)'
478+
r'^(' + OCI_PROTOCOL_PREFIX +
479+
r'[^\s/:@]+' # hostname (e.g. registry.localhost)
480+
r'(?::\d+)?' # optional port (e.g. :5000)
481+
r'(?:/[^\s:@]+)+' # path segments (e.g. /org/plugin), at least one required
482+
r')'
479483
r'(?:'
480484
r':([^\s!@:]+)' # tag only
481485
r'|'
@@ -501,7 +505,7 @@ def parse_plugin_key(self, package: str) -> tuple[str, str, bool, str]:
501505
"""
502506
match = re.match(self.EXPECTED_OCI_PATTERN, package)
503507
if not match:
504-
raise InstallException(f"oci package \'{package}\' is not in the expected format \'{OCI_PROTOCOL_PREFIX}<registry>:<tag>\' or \'{OCI_PROTOCOL_PREFIX}<registry>@sha<algo>:<digest>\' (optionally followed by \'!<path>\') in {self.dynamic_plugins_file} where <algo> is one of {RECOGNIZED_ALGORITHMS}")
508+
raise InstallException(f"oci package \'{package}\' is not in the expected format \'{OCI_PROTOCOL_PREFIX}<registry>:<tag>\' or \'{OCI_PROTOCOL_PREFIX}<registry>@<algo>:<digest>\' (optionally followed by \'!<path>\') in {self.dynamic_plugins_file} where <registry> may include a port (e.g. host:5000/path) and <algo> is one of {RECOGNIZED_ALGORITHMS}")
505509

506510
# Strip away the version (tag or digest) from the package string, resulting in oci://<registry>:!<path>
507511
# This helps ensure keys used to identify OCI plugins are independent of the version of the plugin

scripts/install-dynamic-plugins/test_install-dynamic-plugins.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,38 @@ def oci_merger(self):
222222
'{{inherit}}',
223223
True
224224
),
225+
226+
# Host:port registry format
227+
(
228+
'oci://registry.localhost:5000/rhdh-plugins/plugin:v1.0!plugin-name',
229+
'oci://registry.localhost:5000/rhdh-plugins/plugin:!plugin-name',
230+
'v1.0',
231+
False
232+
),
233+
(
234+
'oci://registry.localhost:5000/rhdh-plugins/rhdh-plugin-export-overlays/backstage-community-plugin-scaffolder-backend-module-quay:bs_1.45.3__2.14.0!my-plugin',
235+
'oci://registry.localhost:5000/rhdh-plugins/rhdh-plugin-export-overlays/backstage-community-plugin-scaffolder-backend-module-quay:!my-plugin',
236+
'bs_1.45.3__2.14.0',
237+
False
238+
),
239+
(
240+
'oci://registry.localhost:5000/path@sha256:abc123!plugin',
241+
'oci://registry.localhost:5000/path:!plugin',
242+
'sha256:abc123',
243+
False
244+
),
245+
(
246+
'oci://registry.localhost:5000/path:{{inherit}}!plugin',
247+
'oci://registry.localhost:5000/path:!plugin',
248+
'{{inherit}}',
249+
True
250+
),
251+
(
252+
'oci://10.0.0.1:5000/repo/plugin:tag!plugin', # NOSONAR
253+
'oci://10.0.0.1:5000/repo/plugin:!plugin', # NOSONAR
254+
'tag',
255+
False
256+
),
225257
])
226258
def test_parse_plugin_key_success_cases(
227259
self, oci_merger, input_package, expected_key, expected_version, expected_inherit
@@ -237,29 +269,45 @@ def test_parse_plugin_key_success_cases(
237269
# Missing tag/digest
238270
('oci://registry.io/plugin!path', 'not in the expected format'),
239271
('oci://registry.io/plugin', 'not in the expected format'),
272+
('oci://host:1000/path', 'not in the expected format'),
240273
241274
# Invalid format - no tag or digest before !
242275
('oci://registry.io!path', 'not in the expected format'),
276+
('oci://host:1000!path', 'not in the expected format'),
243277
244278
# Invalid digest algorithm (md5 not in RECOGNIZED_ALGORITHMS)
245279
('oci://registry.io/plugin@md5:abc123!plugin', 'not in the expected format'),
280+
('oci://host:1000/path@md5:abc123!plugin', 'not in the expected format'),
246281
247282
# Invalid format - multiple @ symbols
248283
('oci://registry.io/plugin@@sha256:abc!plugin', 'not in the expected format'),
284+
('oci://host:1000/path@@sha256:abc!plugin', 'not in the expected format'),
249285
250286
# Invalid format - multiple : symbols in tag
251287
('oci://registry.io/plugin:v1:v2!plugin', 'not in the expected format'),
288+
('oci://host:1000/path:v1:v2!plugin', 'not in the expected format'),
252289
253290
# Empty tag
254291
('oci://registry.io/plugin:!plugin', 'not in the expected format'),
255292
('oci://registry.io/plugin:', 'not in the expected format'),
293+
('oci://host:1000/path:!plugin', 'not in the expected format'),
294+
('oci://host:1000/path:', 'not in the expected format'),
256295
257296
# Empty path after !
258297
('oci://registry.io/plugin:v1.0!', 'not in the expected format'),
298+
('oci://host:1000/path:v1.0!', 'not in the expected format'),
259299
260300
# No oci:// prefix (but this should fail the regex)
261301
('registry.io/plugin:v1.0!plugin', 'not in the expected format'),
262302
('registry.io/plugin:v1.0', 'not in the expected format'),
303+
('host:1000/path:v1.0!plugin', 'not in the expected format'),
304+
('host:1000/path:v1.0', 'not in the expected format'),
305+
306+
# Non-numeric port
307+
('oci://host:abc/path:tag!plugin', 'not in the expected format'),
308+
('oci://host:abc/path', 'not in the expected format'),
309+
('oci://10.0.0.1:abc/path', 'not in the expected format'), # NOSONAR
310+
('oci://10.0.0.1:abc/path:tag!plugin', 'not in the expected format'), # NOSONAR
263311
])
264312
def test_parse_plugin_key_error_cases(self, oci_merger, invalid_package, error_substring):
265313
"""Test that parse_plugin_key raises InstallException for invalid OCI package formats."""

0 commit comments

Comments
 (0)