From 99918e07476ab0a3c92b772af7f6cadc13f8268c Mon Sep 17 00:00:00 2001 From: Alexander Jung Date: Wed, 21 Feb 2024 11:34:34 +0100 Subject: [PATCH] feat(oci): Introduce lightweight name check For offline checks, a simple check of the naming format can help determine whether the provided input source is valid. Signed-off-by: Alexander Jung --- oci/manager.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/oci/manager.go b/oci/manager.go index 6913c6fcd..f9ca65aff 100644 --- a/oci/manager.go +++ b/oci/manager.go @@ -682,6 +682,15 @@ func (manager *ociManager) IsCompatible(ctx context.Context, source string, qopt return nil, false, err } + isFullyQualifiedNameReference := func(source string) bool { + _, err := name.ParseReference(source) + if err != nil && errors.Is(err, &name.ErrBadName{}) { + return false + } + + return true + } + query := packmanager.NewQuery(qopts...) // Check if the provided source is a fully qualified OCI reference @@ -788,6 +797,7 @@ func (manager *ociManager) IsCompatible(ctx context.Context, source string, qopt checks := []func(string) bool{ isLocalImage, + isFullyQualifiedNameReference, } if query.Remote() {