Skip to content

Commit

Permalink
fix: Remove scheme from OCI URL before parsing it (#796)
Browse files Browse the repository at this point in the history
Without this change, registry.ParseReference throws an error if the URL
contains a scheme, e.g. https://.

Signed-off-by: Luiz Carvalho <lucarval@redhat.com>
  • Loading branch information
lcarva committed Mar 24, 2023
1 parent 3de2c90 commit 13c4bed
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion downloader/oci_getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (g *OCIGetter) ClientMode(_ *url.URL) (getter.ClientMode, error) {
func (g *OCIGetter) Get(path string, u *url.URL) error {
ctx := g.Context()

repository := strings.TrimPrefix(u.String(), "oci://")
repository := ociURL(u)
ref, err := registry.ParseReference(repository)
if err != nil {
return fmt.Errorf("reference: %w", err)
Expand Down Expand Up @@ -84,3 +84,13 @@ func (g *OCIGetter) Context() context.Context {
}
return g.client.Ctx
}

// ociURL returns the string representation of the url that is an acceptable
// OCI URL. In short, it strips off the scheme, e.g. "https://", from the URL.
func ociURL(u *url.URL) string {
scheme, url, found := strings.Cut(u.String(), "://")
if !found {
url = scheme
}
return url
}

0 comments on commit 13c4bed

Please sign in to comment.