Skip to content

Commit

Permalink
Remove scheme from OCI URL before parsing it
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 <[email protected]>
  • Loading branch information
lcarva committed Mar 20, 2023
1 parent 496585f commit fb1fa3e
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(u *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 fb1fa3e

Please sign in to comment.