Skip to content

Commit a90be3c

Browse files
authored
Merge pull request #165 from EmmEff/improved-oci-redirect-support
Improved OCI redirect handling
2 parents f063ec9 + 1cbe1ea commit a90be3c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

client/oci.go

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ func (c *Client) ociRegistryAuth(ctx context.Context, name string, accessTypes [
4040
v := url.Values{}
4141
v.Set("namespace", name)
4242

43+
// Setting 'mapped' to '1' (true) enables support for mapping short library refs to
44+
// fully-qualified name
45+
v.Set("mapped", strconv.Itoa(1))
46+
4347
ats := make([]string, 0, len(accessTypes))
4448
for _, at := range accessTypes {
4549
ats = append(ats, string(at))
@@ -630,6 +634,7 @@ func (r *ociRegistry) getImageConfig(ctx context.Context, creds credentials, nam
630634

631635
var errOCIDownloadNotSupported = errors.New("not supported")
632636

637+
// newOCIRegistry returns *ociRegistry, credentials for that registry, and the (optionally) remapped image name
633638
func (c *Client) newOCIRegistry(ctx context.Context, name string, accessTypes []accessType) (*ociRegistry, *bearerTokenCredentials, string, error) {
634639
// Attempt to obtain (direct) OCI registry auth token
635640
originalName := name

client/pull.go

+9-8
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,17 @@ func (c *Client) ConcurrentDownloadImage(ctx context.Context, dst *os.File, arch
158158
}
159159

160160
// Check for direct OCI registry access
161-
if err := c.ociDownloadImage(ctx, arch, name, tag, dst, spec, pb); err == nil {
162-
return err
163-
} else if !errors.Is(err, errOCIDownloadNotSupported) {
164-
// Return OCI download error or fallback to legacy download
165-
return err
166-
}
161+
if err := c.ociDownloadImage(ctx, arch, name, tag, dst, spec, pb); err != nil {
162+
if !errors.Is(err, errOCIDownloadNotSupported) {
163+
// Return OCI download error or fallback to legacy download
164+
return err
165+
}
167166

168-
c.Logger.Log("Fallback to (legacy) library download")
167+
c.Logger.Log("Fallback to (legacy) library download")
169168

170-
return c.legacyDownloadImage(ctx, arch, name, tag, dst, spec, pb)
169+
return c.legacyDownloadImage(ctx, arch, name, tag, dst, spec, pb)
170+
}
171+
return nil
171172
}
172173

173174
func (c *Client) legacyDownloadImage(ctx context.Context, arch, name, tag string, dst io.WriterAt, spec *Downloader, pb ProgressBar) error {

client/pull_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ func seedRandomNumberGenerator(t *testing.T) {
212212
if _, err := crypto_rand.Read(b[:]); err != nil {
213213
t.Fatalf("error seeding random number generator: %v", err)
214214
}
215-
math_rand.Seed(int64(binary.LittleEndian.Uint64(b[:])))
215+
math_rand.New(math_rand.NewSource(int64(binary.LittleEndian.Uint64(b[:]))))
216216
}
217217

218218
// mockLibraryServer returns *httptest.Server that mocks Cloud Library server; in particular,

0 commit comments

Comments
 (0)