From d0f5aa670becaa83b757239e05e0224c248c135b Mon Sep 17 00:00:00 2001 From: Cory Snider Date: Tue, 24 Oct 2023 13:16:58 -0400 Subject: [PATCH] Move context package internal Our context package predates the establishment of current best practices regarding context usage and it shows. It encourages bad practices such as using contexts to propagate non-request-scoped values like the application version and using string-typed keys for context values. Move the package internal to remove it from the API surface of distribution/v3@v3.0.0 so we are free to iterate on it without being constrained by compatibility. Signed-off-by: Cory Snider --- health/health.go | 8 +-- internal/client/repository_test.go | 52 +++++++++---------- {context => internal/dcontext}/context.go | 2 +- {context => internal/dcontext}/doc.go | 10 ++-- {context => internal/dcontext}/http.go | 2 +- {context => internal/dcontext}/http_test.go | 2 +- {context => internal/dcontext}/logger.go | 2 +- {context => internal/dcontext}/trace.go | 2 +- {context => internal/dcontext}/trace_test.go | 2 +- {context => internal/dcontext}/util.go | 2 +- {context => internal/dcontext}/version.go | 2 +- .../dcontext}/version_test.go | 2 +- notifications/bridge.go | 4 +- notifications/listener.go | 2 +- notifications/listener_test.go | 2 +- registry/auth/htpasswd/access.go | 2 +- registry/auth/htpasswd/access_test.go | 6 +-- registry/auth/silly/access.go | 2 +- registry/auth/silly/access_test.go | 4 +- registry/auth/token/accesscontroller.go | 2 +- registry/auth/token/token_test.go | 4 +- registry/handlers/app.go | 2 +- registry/handlers/app_test.go | 6 +-- registry/handlers/blob.go | 10 ++-- registry/handlers/blobupload.go | 2 +- registry/handlers/context.go | 2 +- registry/handlers/health_test.go | 8 +-- registry/handlers/helpers.go | 2 +- registry/handlers/manifests.go | 2 +- registry/proxy/proxyauth.go | 4 +- registry/proxy/proxyblobstore.go | 2 +- registry/proxy/proxymanifeststore.go | 2 +- registry/proxy/proxyregistry.go | 2 +- registry/proxy/scheduler/scheduler.go | 2 +- registry/proxy/scheduler/scheduler_test.go | 14 ++--- registry/registry.go | 2 +- registry/registry_test.go | 2 +- registry/root.go | 2 +- registry/storage/blobstore.go | 2 +- registry/storage/blobwriter.go | 2 +- registry/storage/blobwriter_nonresumable.go | 2 +- .../cache/cachedblobdescriptorstore.go | 2 +- registry/storage/driver/base/base.go | 2 +- registry/storage/driver/gcs/gcs_test.go | 2 +- .../middleware/cloudfront/middleware.go | 2 +- .../driver/middleware/cloudfront/s3filter.go | 2 +- .../middleware/cloudfront/s3filter_test.go | 2 +- registry/storage/driver/s3-aws/s3.go | 2 +- registry/storage/driver/s3-aws/s3_test.go | 26 +++++----- registry/storage/filereader_test.go | 8 +-- registry/storage/garbagecollect_test.go | 36 ++++++------- registry/storage/linkedblobstore.go | 2 +- registry/storage/manifestlisthandler.go | 2 +- registry/storage/manifeststore.go | 2 +- registry/storage/ociindexhandler.go | 2 +- registry/storage/ocimanifesthandler.go | 2 +- registry/storage/schema2manifesthandler.go | 2 +- .../storage/schema2manifesthandler_test.go | 6 +-- registry/storage/vacuum.go | 2 +- testutil/manifests.go | 6 +-- testutil/tarfile.go | 4 +- 61 files changed, 151 insertions(+), 151 deletions(-) rename {context => internal/dcontext}/context.go (99%) rename {context => internal/dcontext}/doc.go (93%) rename {context => internal/dcontext}/http.go (99%) rename {context => internal/dcontext}/http_test.go (99%) rename {context => internal/dcontext}/logger.go (99%) rename {context => internal/dcontext}/trace.go (99%) rename {context => internal/dcontext}/trace_test.go (99%) rename {context => internal/dcontext}/util.go (97%) rename {context => internal/dcontext}/version.go (97%) rename {context => internal/dcontext}/version_test.go (95%) diff --git a/health/health.go b/health/health.go index 06961f35..3e21f731 100644 --- a/health/health.go +++ b/health/health.go @@ -7,7 +7,7 @@ import ( "sync" "time" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/api/errcode" ) @@ -279,7 +279,7 @@ func Handler(handler http.Handler) http.Handler { func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks map[string]string) { p, err := json.Marshal(checks) if err != nil { - context.GetLogger(context.Background()).Errorf("error serializing health status: %v", err) + dcontext.GetLogger(dcontext.Background()).Errorf("error serializing health status: %v", err) p, err = json.Marshal(struct { ServerError string `json:"server_error"` }{ @@ -288,7 +288,7 @@ func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks m status = http.StatusInternalServerError if err != nil { - context.GetLogger(context.Background()).Errorf("error serializing health status failure message: %v", err) + dcontext.GetLogger(dcontext.Background()).Errorf("error serializing health status failure message: %v", err) return } } @@ -297,7 +297,7 @@ func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks m w.Header().Set("Content-Length", fmt.Sprint(len(p))) w.WriteHeader(status) if _, err := w.Write(p); err != nil { - context.GetLogger(context.Background()).Errorf("error writing health status response body: %v", err) + dcontext.GetLogger(dcontext.Background()).Errorf("error writing health status response body: %v", err) } } diff --git a/internal/client/repository_test.go b/internal/client/repository_test.go index b6f4d224..a98fe289 100644 --- a/internal/client/repository_test.go +++ b/internal/client/repository_test.go @@ -17,7 +17,7 @@ import ( "time" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/ocischema" "github.com/distribution/distribution/v3/registry/api/errcode" @@ -108,7 +108,7 @@ func TestBlobServeBlob(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() repo, _ := reference.WithName("test.example.com/repo1") r, err := NewRepository(repo, e, nil) if err != nil { @@ -157,7 +157,7 @@ func TestBlobServeBlobHEAD(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() repo, _ := reference.WithName("test.example.com/repo1") r, err := NewRepository(repo, e, nil) if err != nil { @@ -250,7 +250,7 @@ func TestBlobResume(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -307,7 +307,7 @@ func TestBlobDelete(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -327,7 +327,7 @@ func TestBlobFetch(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() repo, _ := reference.WithName("test.example.com/repo1") r, err := NewRepository(repo, e, nil) if err != nil { @@ -382,7 +382,7 @@ func TestBlobExistsNoContentLength(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -406,7 +406,7 @@ func TestBlobExists(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() repo, _ := reference.WithName("test.example.com/repo1") r, err := NewRepository(repo, e, nil) if err != nil { @@ -512,7 +512,7 @@ func TestBlobUploadChunked(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -622,7 +622,7 @@ func TestBlobUploadMonolithic(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -728,7 +728,7 @@ func TestBlobUploadMonolithicDockerUploadUUIDFromURL(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -833,7 +833,7 @@ func TestBlobUploadMonolithicNoDockerUploadUUID(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -891,7 +891,7 @@ func TestBlobMount(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -1066,7 +1066,7 @@ func checkEqualManifest(m1, m2 *ocischema.DeserializedManifest) error { } func TestOCIManifestFetch(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() repo, _ := reference.WithName("test.example.com/repo") m1, dgst, pl := newRandomOCIManifest(t, 6) var m testutil.RequestResponseMap @@ -1149,7 +1149,7 @@ func TestManifestFetchWithEtag(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -1171,7 +1171,7 @@ func TestManifestFetchWithEtag(t *testing.T) { } func TestManifestFetchWithAccept(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() repo, _ := reference.WithName("test.example.com/repo") _, dgst, _ := newRandomOCIManifest(t, 6) headers := make(chan []string, 1) @@ -1258,7 +1258,7 @@ func TestManifestDelete(t *testing.T) { if err != nil { t.Fatal(err) } - ctx := context.Background() + ctx := dcontext.Background() ms, err := r.Manifests(ctx) if err != nil { t.Fatal(err) @@ -1315,7 +1315,7 @@ func TestManifestPut(t *testing.T) { if err != nil { t.Fatal(err) } - ctx := context.Background() + ctx := dcontext.Background() ms, err := r.Manifests(ctx) if err != nil { t.Fatal(err) @@ -1372,7 +1372,7 @@ func TestManifestTags(t *testing.T) { t.Fatal(err) } - ctx := context.Background() + ctx := dcontext.Background() tagService := r.Tags(ctx) tags, err := tagService.All(ctx) @@ -1423,7 +1423,7 @@ func TestTagDelete(t *testing.T) { if err != nil { t.Fatal(err) } - ctx := context.Background() + ctx := dcontext.Background() ts := r.Tags(ctx) if err := ts.Untag(ctx, tag); err != nil { @@ -1460,7 +1460,7 @@ func TestObtainsErrorForMissingTag(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -1487,7 +1487,7 @@ func TestObtainsManifestForTagWithoutHeaders(t *testing.T) { e, c := testServer(m) defer c() - ctx := context.Background() + ctx := dcontext.Background() r, err := NewRepository(repo, e, nil) if err != nil { t.Fatal(err) @@ -1566,7 +1566,7 @@ func TestManifestTagsPaginated(t *testing.T) { t.Fatal(err) } - ctx := context.Background() + ctx := dcontext.Background() tagService := r.Tags(ctx) tags, err := tagService.All(ctx) @@ -1614,7 +1614,7 @@ func TestManifestUnauthorized(t *testing.T) { if err != nil { t.Fatal(err) } - ctx := context.Background() + ctx := dcontext.Background() ms, err := r.Manifests(ctx) if err != nil { t.Fatal(err) @@ -1652,7 +1652,7 @@ func TestCatalog(t *testing.T) { t.Fatal(err) } - ctx := context.Background() + ctx := dcontext.Background() numFilled, err := r.Repositories(ctx, entries, "") if err != io.EOF { t.Fatal(err) @@ -1684,7 +1684,7 @@ func TestCatalogInParts(t *testing.T) { t.Fatal(err) } - ctx := context.Background() + ctx := dcontext.Background() numFilled, err := r.Repositories(ctx, entries, "") if err != nil { t.Fatal(err) diff --git a/context/context.go b/internal/dcontext/context.go similarity index 99% rename from context/context.go rename to internal/dcontext/context.go index 23f93e0b..fe837980 100644 --- a/context/context.go +++ b/internal/dcontext/context.go @@ -1,4 +1,4 @@ -package context +package dcontext import ( "context" diff --git a/context/doc.go b/internal/dcontext/doc.go similarity index 93% rename from context/doc.go rename to internal/dcontext/doc.go index 51376dd6..a8d9a740 100644 --- a/context/doc.go +++ b/internal/dcontext/doc.go @@ -1,16 +1,16 @@ -// Package context provides several utilities for working with +// Package dcontext provides several utilities for working with // Go's context in http requests. Primarily, the focus is on logging relevant // request information but this package is not limited to that purpose. // // The easiest way to get started is to get the background context: // -// ctx := context.Background() +// ctx := dcontext.Background() // // The returned context should be passed around your application and be the // root of all other context instances. If the application has a version, this // line should be called before anything else: // -// ctx := context.WithVersion(context.Background(), version) +// ctx := dcontext.WithVersion(dcontext.Background(), version) // // The above will store the version in the context and will be available to // the logger. @@ -27,7 +27,7 @@ // the context and reported with the logger. The following example would // return a logger that prints the version with each log message: // -// ctx := context.Context(context.Background(), "version", version) +// ctx := context.WithValue(dcontext.Background(), "version", version) // GetLogger(ctx, "version").Infof("this log message has a version field") // // The above would print out a log message like this: @@ -85,4 +85,4 @@ // can be traced in log messages. Using the fields like "http.request.id", one // can analyze call flow for a particular request with a simple grep of the // logs. -package context +package dcontext diff --git a/context/http.go b/internal/dcontext/http.go similarity index 99% rename from context/http.go rename to internal/dcontext/http.go index bcdf2965..69c29b74 100644 --- a/context/http.go +++ b/internal/dcontext/http.go @@ -1,4 +1,4 @@ -package context +package dcontext import ( "context" diff --git a/context/http_test.go b/internal/dcontext/http_test.go similarity index 99% rename from context/http_test.go rename to internal/dcontext/http_test.go index d9e67231..9d1069d2 100644 --- a/context/http_test.go +++ b/internal/dcontext/http_test.go @@ -1,4 +1,4 @@ -package context +package dcontext import ( "net/http" diff --git a/context/logger.go b/internal/dcontext/logger.go similarity index 99% rename from context/logger.go rename to internal/dcontext/logger.go index f956a228..058fc831 100644 --- a/context/logger.go +++ b/internal/dcontext/logger.go @@ -1,4 +1,4 @@ -package context +package dcontext import ( "context" diff --git a/context/trace.go b/internal/dcontext/trace.go similarity index 99% rename from context/trace.go rename to internal/dcontext/trace.go index 2e169f0c..ba248105 100644 --- a/context/trace.go +++ b/internal/dcontext/trace.go @@ -1,4 +1,4 @@ -package context +package dcontext import ( "context" diff --git a/context/trace_test.go b/internal/dcontext/trace_test.go similarity index 99% rename from context/trace_test.go rename to internal/dcontext/trace_test.go index 4ee530bf..bb6d1779 100644 --- a/context/trace_test.go +++ b/internal/dcontext/trace_test.go @@ -1,4 +1,4 @@ -package context +package dcontext import ( "runtime" diff --git a/context/util.go b/internal/dcontext/util.go similarity index 97% rename from context/util.go rename to internal/dcontext/util.go index c462e756..5b32ba16 100644 --- a/context/util.go +++ b/internal/dcontext/util.go @@ -1,4 +1,4 @@ -package context +package dcontext import ( "context" diff --git a/context/version.go b/internal/dcontext/version.go similarity index 97% rename from context/version.go rename to internal/dcontext/version.go index 97cf9d66..0a0e9cbb 100644 --- a/context/version.go +++ b/internal/dcontext/version.go @@ -1,4 +1,4 @@ -package context +package dcontext import "context" diff --git a/context/version_test.go b/internal/dcontext/version_test.go similarity index 95% rename from context/version_test.go rename to internal/dcontext/version_test.go index b8165269..9829fe95 100644 --- a/context/version_test.go +++ b/internal/dcontext/version_test.go @@ -1,4 +1,4 @@ -package context +package dcontext import "testing" diff --git a/notifications/bridge.go b/notifications/bridge.go index e63aab65..133153de 100644 --- a/notifications/bridge.go +++ b/notifications/bridge.go @@ -5,7 +5,7 @@ import ( "time" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/reference" events "github.com/docker/go-events" "github.com/google/uuid" @@ -49,7 +49,7 @@ func NewBridge(ub URLBuilder, source SourceRecord, actor ActorRecord, request Re func NewRequestRecord(id string, r *http.Request) RequestRecord { return RequestRecord{ ID: id, - Addr: context.RemoteAddr(r), + Addr: dcontext.RemoteAddr(r), Host: r.Host, Method: r.Method, UserAgent: r.UserAgent(), diff --git a/notifications/listener.go b/notifications/listener.go index fad29341..563c1392 100644 --- a/notifications/listener.go +++ b/notifications/listener.go @@ -7,7 +7,7 @@ import ( "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/reference" "github.com/opencontainers/go-digest" ) diff --git a/notifications/listener_test.go b/notifications/listener_test.go index e33109be..5781d453 100644 --- a/notifications/listener_test.go +++ b/notifications/listener_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/manifest/schema2" "github.com/distribution/distribution/v3/registry/storage" "github.com/distribution/distribution/v3/registry/storage/cache/memory" diff --git a/registry/auth/htpasswd/access.go b/registry/auth/htpasswd/access.go index 8d8a0419..0a1d0c1c 100644 --- a/registry/auth/htpasswd/access.go +++ b/registry/auth/htpasswd/access.go @@ -18,7 +18,7 @@ import ( "golang.org/x/crypto/bcrypt" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/auth" ) diff --git a/registry/auth/htpasswd/access_test.go b/registry/auth/htpasswd/access_test.go index 25947757..0871ef41 100644 --- a/registry/auth/htpasswd/access_test.go +++ b/registry/auth/htpasswd/access_test.go @@ -8,7 +8,7 @@ import ( "os" "testing" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/auth" ) @@ -33,7 +33,7 @@ func TestBasicAccessController(t *testing.T) { "realm": testRealm, "path": tempFile.Name(), } - ctx := context.Background() + ctx := dcontext.Background() accessController, err := newAccessController(options) if err != nil { @@ -45,7 +45,7 @@ func TestBasicAccessController(t *testing.T) { userNumber := 0 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ctx := context.WithRequest(ctx, r) + ctx := dcontext.WithRequest(ctx, r) authCtx, err := accessController.Authorized(ctx) if err != nil { switch err := err.(type) { diff --git a/registry/auth/silly/access.go b/registry/auth/silly/access.go index b09373f3..685cf6a6 100644 --- a/registry/auth/silly/access.go +++ b/registry/auth/silly/access.go @@ -13,7 +13,7 @@ import ( "net/http" "strings" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/auth" ) diff --git a/registry/auth/silly/access_test.go b/registry/auth/silly/access_test.go index 482fb2f7..f463e98c 100644 --- a/registry/auth/silly/access_test.go +++ b/registry/auth/silly/access_test.go @@ -5,7 +5,7 @@ import ( "net/http/httptest" "testing" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/auth" ) @@ -16,7 +16,7 @@ func TestSillyAccessController(t *testing.T) { } server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - ctx := context.WithRequest(context.Background(), r) + ctx := dcontext.WithRequest(dcontext.Background(), r) authCtx, err := ac.Authorized(ctx) if err != nil { switch err := err.(type) { diff --git a/registry/auth/token/accesscontroller.go b/registry/auth/token/accesscontroller.go index 24902019..b2e4e4b2 100644 --- a/registry/auth/token/accesscontroller.go +++ b/registry/auth/token/accesscontroller.go @@ -13,7 +13,7 @@ import ( "os" "strings" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/auth" "github.com/go-jose/go-jose/v3" ) diff --git a/registry/auth/token/token_test.go b/registry/auth/token/token_test.go index 417d0d9b..a331a93b 100644 --- a/registry/auth/token/token_test.go +++ b/registry/auth/token/token_test.go @@ -18,7 +18,7 @@ import ( "testing" "time" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/auth" "github.com/go-jose/go-jose/v3" "github.com/go-jose/go-jose/v3/jwt" @@ -466,7 +466,7 @@ func TestAccessController(t *testing.T) { Action: "baz", } - ctx := context.WithRequest(context.Background(), req) + ctx := dcontext.WithRequest(dcontext.Background(), req) authCtx, err := accessController.Authorized(ctx, testAccess) challenge, ok := err.(auth.Challenge) if !ok { diff --git a/registry/handlers/app.go b/registry/handlers/app.go index 8efdaf85..7ce27d6d 100644 --- a/registry/handlers/app.go +++ b/registry/handlers/app.go @@ -19,9 +19,9 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/configuration" - dcontext "github.com/distribution/distribution/v3/context" "github.com/distribution/distribution/v3/health" "github.com/distribution/distribution/v3/health/checks" + "github.com/distribution/distribution/v3/internal/dcontext" prometheus "github.com/distribution/distribution/v3/metrics" "github.com/distribution/distribution/v3/notifications" "github.com/distribution/distribution/v3/registry/api/errcode" diff --git a/registry/handlers/app_test.go b/registry/handlers/app_test.go index 391deea6..d1862592 100644 --- a/registry/handlers/app_test.go +++ b/registry/handlers/app_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/distribution/distribution/v3/configuration" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/api/errcode" v2 "github.com/distribution/distribution/v3/registry/api/v2" "github.com/distribution/distribution/v3/registry/auth" @@ -25,7 +25,7 @@ import ( // tested individually. func TestAppDispatcher(t *testing.T) { driver := inmemory.New() - ctx := context.Background() + ctx := dcontext.Background() registry, err := storage.NewRegistry(ctx, driver, storage.BlobDescriptorCacheProvider(memorycache.NewInMemoryBlobDescriptorCacheProvider(0)), storage.EnableDelete, storage.EnableRedirect) if err != nil { t.Fatalf("error creating registry: %v", err) @@ -139,7 +139,7 @@ func TestAppDispatcher(t *testing.T) { // TestNewApp covers the creation of an application via NewApp with a // configuration. func TestNewApp(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() config := configuration.Configuration{ Storage: configuration.Storage{ "inmemory": nil, diff --git a/registry/handlers/blob.go b/registry/handlers/blob.go index 4d50754d..b4979782 100644 --- a/registry/handlers/blob.go +++ b/registry/handlers/blob.go @@ -4,7 +4,7 @@ import ( "net/http" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/api/errcode" "github.com/gorilla/handlers" "github.com/opencontainers/go-digest" @@ -53,7 +53,7 @@ type blobHandler struct { // GetBlob fetches the binary data from backend storage returns it in the // response. func (bh *blobHandler) GetBlob(w http.ResponseWriter, r *http.Request) { - context.GetLogger(bh).Debug("GetBlob") + dcontext.GetLogger(bh).Debug("GetBlob") blobs := bh.Repository.Blobs(bh) desc, err := blobs.Stat(bh, bh.Digest) if err != nil { @@ -66,7 +66,7 @@ func (bh *blobHandler) GetBlob(w http.ResponseWriter, r *http.Request) { } if err := blobs.ServeBlob(bh, w, r, desc.Digest); err != nil { - context.GetLogger(bh).Debugf("unexpected error getting blob HTTP handler: %v", err) + dcontext.GetLogger(bh).Debugf("unexpected error getting blob HTTP handler: %v", err) bh.Errors = append(bh.Errors, errcode.ErrorCodeUnknown.WithDetail(err)) return } @@ -74,7 +74,7 @@ func (bh *blobHandler) GetBlob(w http.ResponseWriter, r *http.Request) { // DeleteBlob deletes a layer blob func (bh *blobHandler) DeleteBlob(w http.ResponseWriter, r *http.Request) { - context.GetLogger(bh).Debug("DeleteBlob") + dcontext.GetLogger(bh).Debug("DeleteBlob") blobs := bh.Repository.Blobs(bh) err := blobs.Delete(bh, bh.Digest) @@ -88,7 +88,7 @@ func (bh *blobHandler) DeleteBlob(w http.ResponseWriter, r *http.Request) { return default: bh.Errors = append(bh.Errors, err) - context.GetLogger(bh).Errorf("Unknown error deleting blob: %s", err.Error()) + dcontext.GetLogger(bh).Errorf("Unknown error deleting blob: %s", err.Error()) return } } diff --git a/registry/handlers/blobupload.go b/registry/handlers/blobupload.go index 09c00bb8..6b6c640d 100644 --- a/registry/handlers/blobupload.go +++ b/registry/handlers/blobupload.go @@ -7,7 +7,7 @@ import ( "strconv" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/api/errcode" "github.com/distribution/distribution/v3/registry/storage" "github.com/distribution/reference" diff --git a/registry/handlers/context.go b/registry/handlers/context.go index cac97a04..cb354023 100644 --- a/registry/handlers/context.go +++ b/registry/handlers/context.go @@ -6,7 +6,7 @@ import ( "net/http" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/api/errcode" v2 "github.com/distribution/distribution/v3/registry/api/v2" "github.com/distribution/distribution/v3/registry/auth" diff --git a/registry/handlers/health_test.go b/registry/handlers/health_test.go index e0d61555..dc706b87 100644 --- a/registry/handlers/health_test.go +++ b/registry/handlers/health_test.go @@ -9,8 +9,8 @@ import ( "time" "github.com/distribution/distribution/v3/configuration" - "github.com/distribution/distribution/v3/context" "github.com/distribution/distribution/v3/health" + "github.com/distribution/distribution/v3/internal/dcontext" ) func TestFileHealthCheck(t *testing.T) { @@ -39,7 +39,7 @@ func TestFileHealthCheck(t *testing.T) { }, } - ctx := context.Background() + ctx := dcontext.Background() app := NewApp(ctx, config) healthRegistry := health.NewRegistry() @@ -103,7 +103,7 @@ func TestTCPHealthCheck(t *testing.T) { }, } - ctx := context.Background() + ctx := dcontext.Background() app := NewApp(ctx, config) healthRegistry := health.NewRegistry() @@ -165,7 +165,7 @@ func TestHTTPHealthCheck(t *testing.T) { }, } - ctx := context.Background() + ctx := dcontext.Background() app := NewApp(ctx, config) healthRegistry := health.NewRegistry() diff --git a/registry/handlers/helpers.go b/registry/handlers/helpers.go index d70306fd..3ccba555 100644 --- a/registry/handlers/helpers.go +++ b/registry/handlers/helpers.go @@ -9,7 +9,7 @@ import ( "strconv" "strings" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" ) // closeResources closes all the provided resources after running the target diff --git a/registry/handlers/manifests.go b/registry/handlers/manifests.go index d7bbab92..06b7c0c7 100644 --- a/registry/handlers/manifests.go +++ b/registry/handlers/manifests.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/manifest/manifestlist" "github.com/distribution/distribution/v3/manifest/ocischema" "github.com/distribution/distribution/v3/manifest/schema2" diff --git a/registry/proxy/proxyauth.go b/registry/proxy/proxyauth.go index ee79ed7e..8cdc3ebf 100644 --- a/registry/proxy/proxyauth.go +++ b/registry/proxy/proxyauth.go @@ -5,9 +5,9 @@ import ( "net/url" "strings" - "github.com/distribution/distribution/v3/context" "github.com/distribution/distribution/v3/internal/client/auth" "github.com/distribution/distribution/v3/internal/client/auth/challenge" + "github.com/distribution/distribution/v3/internal/dcontext" ) const challengeHeader = "Docker-Distribution-Api-Version" @@ -44,7 +44,7 @@ func configureAuth(username, password, remoteURL string) (auth.CredentialStore, } for _, url := range authURLs { - context.GetLogger(context.Background()).Infof("Discovered token authentication URL: %s", url) + dcontext.GetLogger(dcontext.Background()).Infof("Discovered token authentication URL: %s", url) creds[url] = userpass{ username: username, password: password, diff --git a/registry/proxy/proxyblobstore.go b/registry/proxy/proxyblobstore.go index f83ef329..bf8ca22f 100644 --- a/registry/proxy/proxyblobstore.go +++ b/registry/proxy/proxyblobstore.go @@ -11,7 +11,7 @@ import ( "github.com/opencontainers/go-digest" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/proxy/scheduler" "github.com/distribution/reference" ) diff --git a/registry/proxy/proxymanifeststore.go b/registry/proxy/proxymanifeststore.go index fa60a07e..1b0e5a31 100644 --- a/registry/proxy/proxymanifeststore.go +++ b/registry/proxy/proxymanifeststore.go @@ -7,7 +7,7 @@ import ( "github.com/opencontainers/go-digest" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/proxy/scheduler" "github.com/distribution/reference" ) diff --git a/registry/proxy/proxyregistry.go b/registry/proxy/proxyregistry.go index 15dc783b..33dcc4af 100644 --- a/registry/proxy/proxyregistry.go +++ b/registry/proxy/proxyregistry.go @@ -10,11 +10,11 @@ import ( "github.com/distribution/distribution/v3" "github.com/distribution/distribution/v3/configuration" - dcontext "github.com/distribution/distribution/v3/context" "github.com/distribution/distribution/v3/internal/client" "github.com/distribution/distribution/v3/internal/client/auth" "github.com/distribution/distribution/v3/internal/client/auth/challenge" "github.com/distribution/distribution/v3/internal/client/transport" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/proxy/scheduler" "github.com/distribution/distribution/v3/registry/storage" "github.com/distribution/distribution/v3/registry/storage/driver" diff --git a/registry/proxy/scheduler/scheduler.go b/registry/proxy/scheduler/scheduler.go index e492cf71..ed1d9d41 100644 --- a/registry/proxy/scheduler/scheduler.go +++ b/registry/proxy/scheduler/scheduler.go @@ -7,7 +7,7 @@ import ( "sync" "time" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/distribution/reference" ) diff --git a/registry/proxy/scheduler/scheduler_test.go b/registry/proxy/scheduler/scheduler_test.go index 1309a1b0..38fa0f58 100644 --- a/registry/proxy/scheduler/scheduler_test.go +++ b/registry/proxy/scheduler/scheduler_test.go @@ -6,7 +6,7 @@ import ( "testing" "time" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/reference" ) @@ -40,7 +40,7 @@ func TestSchedule(t *testing.T) { } var mu sync.Mutex - s := New(context.Background(), inmemory.New(), "/ttl") + s := New(dcontext.Background(), inmemory.New(), "/ttl") deleteFunc := func(repoName reference.Reference) error { if len(remainingRepos) == 0 { t.Fatalf("Incorrect expiry count") @@ -123,14 +123,14 @@ func TestRestoreOld(t *testing.T) { t.Fatalf("Error serializing test data: %s", err.Error()) } - ctx := context.Background() + ctx := dcontext.Background() pathToStatFile := "/ttl" fs := inmemory.New() err = fs.PutContent(ctx, pathToStatFile, serialized) if err != nil { t.Fatal("Unable to write serialized data to fs") } - s := New(context.Background(), fs, "/ttl") + s := New(dcontext.Background(), fs, "/ttl") s.OnBlobExpire(deleteFunc) err = s.Start() if err != nil { @@ -165,7 +165,7 @@ func TestStopRestore(t *testing.T) { fs := inmemory.New() pathToStateFile := "/ttl" - s := New(context.Background(), fs, pathToStateFile) + s := New(dcontext.Background(), fs, pathToStateFile) s.onBlobExpire = deleteFunc err := s.Start() @@ -181,7 +181,7 @@ func TestStopRestore(t *testing.T) { time.Sleep(10 * time.Millisecond) // v2 will restore state from fs - s2 := New(context.Background(), fs, pathToStateFile) + s2 := New(dcontext.Background(), fs, pathToStateFile) s2.onBlobExpire = deleteFunc err = s2.Start() if err != nil { @@ -197,7 +197,7 @@ func TestStopRestore(t *testing.T) { } func TestDoubleStart(t *testing.T) { - s := New(context.Background(), inmemory.New(), "/ttl") + s := New(dcontext.Background(), inmemory.New(), "/ttl") err := s.Start() if err != nil { t.Fatalf("Unable to start scheduler") diff --git a/registry/registry.go b/registry/registry.go index 98a29eed..933013c5 100644 --- a/registry/registry.go +++ b/registry/registry.go @@ -21,8 +21,8 @@ import ( "golang.org/x/crypto/acme/autocert" "github.com/distribution/distribution/v3/configuration" - dcontext "github.com/distribution/distribution/v3/context" "github.com/distribution/distribution/v3/health" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/handlers" "github.com/distribution/distribution/v3/registry/listener" "github.com/distribution/distribution/v3/version" diff --git a/registry/registry_test.go b/registry/registry_test.go index 3e919e31..194da97a 100644 --- a/registry/registry_test.go +++ b/registry/registry_test.go @@ -25,7 +25,7 @@ import ( "time" "github.com/distribution/distribution/v3/configuration" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" _ "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/sirupsen/logrus" "gopkg.in/yaml.v2" diff --git a/registry/root.go b/registry/root.go index 51c8c7ff..272027e6 100644 --- a/registry/root.go +++ b/registry/root.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/storage" "github.com/distribution/distribution/v3/registry/storage/driver/factory" "github.com/distribution/distribution/v3/version" diff --git a/registry/storage/blobstore.go b/registry/storage/blobstore.go index f54e901d..c03736ea 100644 --- a/registry/storage/blobstore.go +++ b/registry/storage/blobstore.go @@ -6,7 +6,7 @@ import ( "path" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/opencontainers/go-digest" ) diff --git a/registry/storage/blobwriter.go b/registry/storage/blobwriter.go index 70c8b2af..9de3b0c2 100644 --- a/registry/storage/blobwriter.go +++ b/registry/storage/blobwriter.go @@ -9,7 +9,7 @@ import ( "time" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/opencontainers/go-digest" "github.com/sirupsen/logrus" diff --git a/registry/storage/blobwriter_nonresumable.go b/registry/storage/blobwriter_nonresumable.go index a7df9a22..b3b3f6ab 100644 --- a/registry/storage/blobwriter_nonresumable.go +++ b/registry/storage/blobwriter_nonresumable.go @@ -4,7 +4,7 @@ package storage import ( - "github.com/distribution/distribution/v3/context" + "context" ) // resumeHashAt is a noop when resumable digest support is disabled. diff --git a/registry/storage/cache/cachedblobdescriptorstore.go b/registry/storage/cache/cachedblobdescriptorstore.go index b4dc828c..38dd1dcf 100644 --- a/registry/storage/cache/cachedblobdescriptorstore.go +++ b/registry/storage/cache/cachedblobdescriptorstore.go @@ -4,7 +4,7 @@ import ( "context" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" prometheus "github.com/distribution/distribution/v3/metrics" "github.com/opencontainers/go-digest" ) diff --git a/registry/storage/driver/base/base.go b/registry/storage/driver/base/base.go index 69371712..756a0d4c 100644 --- a/registry/storage/driver/base/base.go +++ b/registry/storage/driver/base/base.go @@ -42,7 +42,7 @@ import ( "io" "time" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" prometheus "github.com/distribution/distribution/v3/metrics" storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/docker/go-metrics" diff --git a/registry/storage/driver/gcs/gcs_test.go b/registry/storage/driver/gcs/gcs_test.go index 65998e7b..a76015d0 100644 --- a/registry/storage/driver/gcs/gcs_test.go +++ b/registry/storage/driver/gcs/gcs_test.go @@ -10,7 +10,7 @@ import ( "testing" "cloud.google.com/go/storage" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/distribution/distribution/v3/registry/storage/driver/testsuites" "golang.org/x/oauth2" diff --git a/registry/storage/driver/middleware/cloudfront/middleware.go b/registry/storage/driver/middleware/cloudfront/middleware.go index 5c2c0995..32474cbd 100644 --- a/registry/storage/driver/middleware/cloudfront/middleware.go +++ b/registry/storage/driver/middleware/cloudfront/middleware.go @@ -13,7 +13,7 @@ import ( "time" "github.com/aws/aws-sdk-go/service/cloudfront/sign" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" storagemiddleware "github.com/distribution/distribution/v3/registry/storage/driver/middleware" ) diff --git a/registry/storage/driver/middleware/cloudfront/s3filter.go b/registry/storage/driver/middleware/cloudfront/s3filter.go index 25aafd04..7a23bcbd 100644 --- a/registry/storage/driver/middleware/cloudfront/s3filter.go +++ b/registry/storage/driver/middleware/cloudfront/s3filter.go @@ -11,7 +11,7 @@ import ( "sync" "time" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" ) const ( diff --git a/registry/storage/driver/middleware/cloudfront/s3filter_test.go b/registry/storage/driver/middleware/cloudfront/s3filter_test.go index 81ef6aa8..0d105560 100644 --- a/registry/storage/driver/middleware/cloudfront/s3filter_test.go +++ b/registry/storage/driver/middleware/cloudfront/s3filter_test.go @@ -12,7 +12,7 @@ import ( "testing" "time" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" ) // Rather than pull in all of testify diff --git a/registry/storage/driver/s3-aws/s3.go b/registry/storage/driver/s3-aws/s3.go index a6428a91..a85624d4 100644 --- a/registry/storage/driver/s3-aws/s3.go +++ b/registry/storage/driver/s3-aws/s3.go @@ -36,7 +36,7 @@ import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/s3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/distribution/distribution/v3/registry/storage/driver/base" "github.com/distribution/distribution/v3/registry/storage/driver/factory" diff --git a/registry/storage/driver/s3-aws/s3_test.go b/registry/storage/driver/s3-aws/s3_test.go index ebd9d2a2..de6dd12b 100644 --- a/registry/storage/driver/s3-aws/s3_test.go +++ b/registry/storage/driver/s3-aws/s3_test.go @@ -16,7 +16,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/s3" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" storagedriver "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/distribution/distribution/v3/registry/storage/driver/testsuites" ) @@ -180,7 +180,7 @@ func TestEmptyRootList(t *testing.T) { filename := "/test" contents := []byte("contents") - ctx := context.Background() + ctx := dcontext.Background() err = rootedDriver.PutContent(ctx, filename, contents) if err != nil { t.Fatalf("unexpected error creating content: %v", err) @@ -209,7 +209,7 @@ func TestStorageClass(t *testing.T) { rootDir := t.TempDir() contents := []byte("contents") - ctx := context.Background() + ctx := dcontext.Background() // We don't need to test all the storage classes, just that its selectable. // The first 3 are common to AWS and MinIO, so use those. @@ -377,7 +377,7 @@ func TestDelete(t *testing.T) { // init file structure matching objs var created []string for _, p := range objs { - err := drvr.PutContent(context.Background(), p, []byte("content "+p)) + err := drvr.PutContent(dcontext.Background(), p, []byte("content "+p)) if err != nil { fmt.Printf("unable to init file %s: %s\n", p, err) continue @@ -390,7 +390,7 @@ func TestDelete(t *testing.T) { cleanup := func(objs []string) { var lastErr error for _, p := range objs { - err := drvr.Delete(context.Background(), p) + err := drvr.Delete(dcontext.Background(), p) if err != nil { switch err.(type) { case storagedriver.PathNotFoundError: @@ -409,7 +409,7 @@ func TestDelete(t *testing.T) { t.Run(tc.name, func(t *testing.T) { objs := init() - err := drvr.Delete(context.Background(), tc.delete) + err := drvr.Delete(dcontext.Background(), tc.delete) if tc.err != nil { if err == nil { @@ -437,7 +437,7 @@ func TestDelete(t *testing.T) { return false } for _, path := range objs { - stat, err := drvr.Stat(context.Background(), path) + stat, err := drvr.Stat(dcontext.Background(), path) if err != nil { switch err.(type) { case storagedriver.PathNotFoundError: @@ -491,7 +491,7 @@ func TestWalk(t *testing.T) { // create file structure matching fileset above created := make([]string, 0, len(fileset)) for _, p := range fileset { - err := drvr.PutContent(context.Background(), p, []byte("content "+p)) + err := drvr.PutContent(dcontext.Background(), p, []byte("content "+p)) if err != nil { fmt.Printf("unable to create file %s: %s\n", p, err) continue @@ -503,7 +503,7 @@ func TestWalk(t *testing.T) { defer func() { var lastErr error for _, p := range created { - err := drvr.Delete(context.Background(), p) + err := drvr.Delete(dcontext.Background(), p) if err != nil { _ = fmt.Errorf("cleanup failed for path %s: %s", p, err) lastErr = err @@ -692,7 +692,7 @@ func TestWalk(t *testing.T) { tc.from = "/" } t.Run(tc.name, func(t *testing.T) { - err := drvr.Walk(context.Background(), tc.from, func(fileInfo storagedriver.FileInfo) error { + err := drvr.Walk(dcontext.Background(), tc.from, func(fileInfo storagedriver.FileInfo) error { walked = append(walked, fileInfo.Path()) return tc.fn(fileInfo) }, tc.options...) @@ -718,7 +718,7 @@ func TestOverThousandBlobs(t *testing.T) { t.Fatalf("unexpected error creating driver with standard storage: %v", err) } - ctx := context.Background() + ctx := dcontext.Background() for i := 0; i < 1005; i++ { filename := "/thousandfiletest/file" + strconv.Itoa(i) contents := []byte("contents") @@ -746,7 +746,7 @@ func TestMoveWithMultipartCopy(t *testing.T) { t.Fatalf("unexpected error creating driver: %v", err) } - ctx := context.Background() + ctx := dcontext.Background() sourcePath := "/source" destPath := "/dest" @@ -795,7 +795,7 @@ func TestListObjectsV2(t *testing.T) { t.Fatalf("unexpected error creating driver: %v", err) } - ctx := context.Background() + ctx := dcontext.Background() n := 6 prefix := "/test-list-objects-v2" var filePaths []string diff --git a/registry/storage/filereader_test.go b/registry/storage/filereader_test.go index 3f05582e..5dfa2947 100644 --- a/registry/storage/filereader_test.go +++ b/registry/storage/filereader_test.go @@ -7,13 +7,13 @@ import ( mrand "math/rand" "testing" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/opencontainers/go-digest" ) func TestSimpleRead(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() content := make([]byte, 1<<20) n, err := crand.Read(content) if err != nil { @@ -55,7 +55,7 @@ func TestFileReaderSeek(t *testing.T) { repititions := 1024 path := "/patterned" content := bytes.Repeat([]byte(pattern), repititions) - ctx := context.Background() + ctx := dcontext.Background() if err := driver.PutContent(ctx, path, content); err != nil { t.Fatalf("error putting patterned content: %v", err) @@ -156,7 +156,7 @@ func TestFileReaderSeek(t *testing.T) { // read method, with an io.EOF error. func TestFileReaderNonExistentFile(t *testing.T) { driver := inmemory.New() - fr, err := newFileReader(context.Background(), driver, "/doesnotexist", 10) + fr, err := newFileReader(dcontext.Background(), driver, "/doesnotexist", 10) if err != nil { t.Fatalf("unexpected error initializing reader: %v", err) } diff --git a/registry/storage/garbagecollect_test.go b/registry/storage/garbagecollect_test.go index edf7f1c3..5e69a178 100644 --- a/registry/storage/garbagecollect_test.go +++ b/registry/storage/garbagecollect_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" "github.com/distribution/distribution/v3/testutil" @@ -21,7 +21,7 @@ type image struct { } func createRegistry(t *testing.T, driver driver.StorageDriver, options ...RegistryOption) distribution.Namespace { - ctx := context.Background() + ctx := dcontext.Background() options = append(options, EnableDelete) registry, err := NewRegistry(ctx, driver, options...) if err != nil { @@ -31,7 +31,7 @@ func createRegistry(t *testing.T, driver driver.StorageDriver, options ...Regist } func makeRepository(t *testing.T, registry distribution.Namespace, name string) distribution.Repository { - ctx := context.Background() + ctx := dcontext.Background() // Initialize a dummy repository named, err := reference.WithName(name) @@ -47,7 +47,7 @@ func makeRepository(t *testing.T, registry distribution.Namespace, name string) } func makeManifestService(t *testing.T, repository distribution.Repository) distribution.ManifestService { - ctx := context.Background() + ctx := dcontext.Background() manifestService, err := repository.Manifests(ctx) if err != nil { @@ -57,7 +57,7 @@ func makeManifestService(t *testing.T, repository distribution.Repository) distr } func allManifests(t *testing.T, manifestService distribution.ManifestService) map[digest.Digest]struct{} { - ctx := context.Background() + ctx := dcontext.Background() allManMap := make(map[digest.Digest]struct{}) manifestEnumerator, ok := manifestService.(distribution.ManifestEnumerator) if !ok { @@ -74,7 +74,7 @@ func allManifests(t *testing.T, manifestService distribution.ManifestService) ma } func allBlobs(t *testing.T, registry distribution.Namespace) map[digest.Digest]struct{} { - ctx := context.Background() + ctx := dcontext.Background() blobService := registry.Blobs() allBlobsMap := make(map[digest.Digest]struct{}) err := blobService.Enumerate(ctx, func(dgst digest.Digest) error { @@ -95,7 +95,7 @@ func uploadImage(t *testing.T, repository distribution.Repository, im image) dig } // upload manifest - ctx := context.Background() + ctx := dcontext.Background() manifestService := makeManifestService(t, repository) manifestDigest, err := manifestService.Put(ctx, im.manifest) if err != nil { @@ -130,7 +130,7 @@ func uploadRandomSchema2Image(t *testing.T, repository distribution.Repository) } func TestNoDeletionNoEffect(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() inmemoryDriver := inmemory.New() registry := createRegistry(t, inmemoryDriver) @@ -158,7 +158,7 @@ func TestNoDeletionNoEffect(t *testing.T) { before := allBlobs(t, registry) // Run GC - err = MarkAndSweep(context.Background(), inmemoryDriver, registry, GCOpts{ + err = MarkAndSweep(dcontext.Background(), inmemoryDriver, registry, GCOpts{ DryRun: false, RemoveUntagged: false, }) @@ -173,7 +173,7 @@ func TestNoDeletionNoEffect(t *testing.T) { } func TestDeleteManifestIfTagNotFound(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() inmemoryDriver := inmemory.New() registry := createRegistry(t, inmemoryDriver) @@ -233,7 +233,7 @@ func TestDeleteManifestIfTagNotFound(t *testing.T) { before2 := allManifests(t, manifestService) // run GC with dry-run (should not remove anything) - err = MarkAndSweep(context.Background(), inmemoryDriver, registry, GCOpts{ + err = MarkAndSweep(dcontext.Background(), inmemoryDriver, registry, GCOpts{ DryRun: true, RemoveUntagged: true, }) @@ -250,7 +250,7 @@ func TestDeleteManifestIfTagNotFound(t *testing.T) { } // Run GC (removes everything because no manifests with tags exist) - err = MarkAndSweep(context.Background(), inmemoryDriver, registry, GCOpts{ + err = MarkAndSweep(dcontext.Background(), inmemoryDriver, registry, GCOpts{ DryRun: false, RemoveUntagged: true, }) @@ -269,7 +269,7 @@ func TestDeleteManifestIfTagNotFound(t *testing.T) { } func TestGCWithMissingManifests(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() d := inmemory.New() registry := createRegistry(t, d) @@ -288,7 +288,7 @@ func TestGCWithMissingManifests(t *testing.T) { t.Fatal(err) } - err = MarkAndSweep(context.Background(), d, registry, GCOpts{ + err = MarkAndSweep(dcontext.Background(), d, registry, GCOpts{ DryRun: false, RemoveUntagged: false, }) @@ -303,7 +303,7 @@ func TestGCWithMissingManifests(t *testing.T) { } func TestDeletionHasEffect(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() inmemoryDriver := inmemory.New() registry := createRegistry(t, inmemoryDriver) @@ -318,7 +318,7 @@ func TestDeletionHasEffect(t *testing.T) { manifests.Delete(ctx, image3.manifestDigest) // Run GC - err := MarkAndSweep(context.Background(), inmemoryDriver, registry, GCOpts{ + err := MarkAndSweep(dcontext.Background(), inmemoryDriver, registry, GCOpts{ DryRun: false, RemoveUntagged: false, }) @@ -368,7 +368,7 @@ func getKeys(digests map[digest.Digest]io.ReadSeeker) (ds []digest.Digest) { } func TestDeletionWithSharedLayer(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() inmemoryDriver := inmemory.New() registry := createRegistry(t, inmemoryDriver) @@ -455,7 +455,7 @@ func TestOrphanBlobDeleted(t *testing.T) { uploadRandomSchema2Image(t, repo) // Run GC - err = MarkAndSweep(context.Background(), inmemoryDriver, registry, GCOpts{ + err = MarkAndSweep(dcontext.Background(), inmemoryDriver, registry, GCOpts{ DryRun: false, RemoveUntagged: false, }) diff --git a/registry/storage/linkedblobstore.go b/registry/storage/linkedblobstore.go index 392d39b0..18d40d27 100644 --- a/registry/storage/linkedblobstore.go +++ b/registry/storage/linkedblobstore.go @@ -9,7 +9,7 @@ import ( "time" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/distribution/reference" "github.com/google/uuid" diff --git a/registry/storage/manifestlisthandler.go b/registry/storage/manifestlisthandler.go index 1fc7aac7..caaf76bb 100644 --- a/registry/storage/manifestlisthandler.go +++ b/registry/storage/manifestlisthandler.go @@ -5,7 +5,7 @@ import ( "fmt" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/manifest/manifestlist" "github.com/distribution/distribution/v3/manifest/ocischema" "github.com/opencontainers/go-digest" diff --git a/registry/storage/manifeststore.go b/registry/storage/manifeststore.go index 37c86495..027ab65c 100644 --- a/registry/storage/manifeststore.go +++ b/registry/storage/manifeststore.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/manifestlist" "github.com/distribution/distribution/v3/manifest/ocischema" diff --git a/registry/storage/ociindexhandler.go b/registry/storage/ociindexhandler.go index 01864f06..b4d73413 100644 --- a/registry/storage/ociindexhandler.go +++ b/registry/storage/ociindexhandler.go @@ -4,7 +4,7 @@ import ( "context" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/manifest/ocischema" "github.com/opencontainers/go-digest" ) diff --git a/registry/storage/ocimanifesthandler.go b/registry/storage/ocimanifesthandler.go index 97216d2a..f69c2a2b 100644 --- a/registry/storage/ocimanifesthandler.go +++ b/registry/storage/ocimanifesthandler.go @@ -6,7 +6,7 @@ import ( "net/url" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/manifest/ocischema" "github.com/opencontainers/go-digest" v1 "github.com/opencontainers/image-spec/specs-go/v1" diff --git a/registry/storage/schema2manifesthandler.go b/registry/storage/schema2manifesthandler.go index aa8980ec..adf0677e 100644 --- a/registry/storage/schema2manifesthandler.go +++ b/registry/storage/schema2manifesthandler.go @@ -7,7 +7,7 @@ import ( "net/url" "github.com/distribution/distribution/v3" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/manifest/schema2" "github.com/opencontainers/go-digest" ) diff --git a/registry/storage/schema2manifesthandler_test.go b/registry/storage/schema2manifesthandler_test.go index 908f8c13..26c19ec1 100644 --- a/registry/storage/schema2manifesthandler_test.go +++ b/registry/storage/schema2manifesthandler_test.go @@ -6,7 +6,7 @@ import ( "testing" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/manifest" "github.com/distribution/distribution/v3/manifest/schema2" "github.com/distribution/distribution/v3/registry/storage/driver/inmemory" @@ -14,7 +14,7 @@ import ( ) func TestVerifyManifestForeignLayer(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() inmemoryDriver := inmemory.New() registry := createRegistry(t, inmemoryDriver, ManifestURLsAllowRegexp(regexp.MustCompile("^https?://foo")), @@ -152,7 +152,7 @@ func TestVerifyManifestForeignLayer(t *testing.T) { } func TestVerifyManifestBlobLayerAndConfig(t *testing.T) { - ctx := context.Background() + ctx := dcontext.Background() inmemoryDriver := inmemory.New() registry := createRegistry(t, inmemoryDriver, ManifestURLsAllowRegexp(regexp.MustCompile("^https?://foo")), diff --git a/registry/storage/vacuum.go b/registry/storage/vacuum.go index 749fb319..38ebbd67 100644 --- a/registry/storage/vacuum.go +++ b/registry/storage/vacuum.go @@ -4,7 +4,7 @@ import ( "context" "path" - dcontext "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/registry/storage/driver" "github.com/opencontainers/go-digest" ) diff --git a/testutil/manifests.go b/testutil/manifests.go index 96af5703..dd1cc3a3 100644 --- a/testutil/manifests.go +++ b/testutil/manifests.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/distribution/distribution/v3/manifest/manifestlist" "github.com/distribution/distribution/v3/manifest/schema2" "github.com/opencontainers/go-digest" @@ -12,7 +12,7 @@ import ( // MakeManifestList constructs a manifest list out of a list of manifest digests func MakeManifestList(blobstatter distribution.BlobStatter, manifestDigests []digest.Digest) (*manifestlist.DeserializedManifestList, error) { - ctx := context.Background() + ctx := dcontext.Background() manifestDescriptors := make([]manifestlist.ManifestDescriptor, 0, len(manifestDigests)) for _, manifestDigest := range manifestDigests { @@ -39,7 +39,7 @@ func MakeManifestList(blobstatter distribution.BlobStatter, manifestDigests []di // MakeSchema2Manifest constructs a schema 2 manifest from a given list of digests and returns // the digest of the manifest func MakeSchema2Manifest(repository distribution.Repository, digests []digest.Digest) (distribution.Manifest, error) { - ctx := context.Background() + ctx := dcontext.Background() blobStore := repository.Blobs(ctx) var configJSON []byte diff --git a/testutil/tarfile.go b/testutil/tarfile.go index 2b30a24d..d4bc7e2a 100644 --- a/testutil/tarfile.go +++ b/testutil/tarfile.go @@ -10,7 +10,7 @@ import ( "time" "github.com/distribution/distribution/v3" - "github.com/distribution/distribution/v3/context" + "github.com/distribution/distribution/v3/internal/dcontext" "github.com/opencontainers/go-digest" ) @@ -96,7 +96,7 @@ func CreateRandomLayers(n int) (map[digest.Digest]io.ReadSeeker, error) { // UploadBlobs lets you upload blobs to a repository func UploadBlobs(repository distribution.Repository, layers map[digest.Digest]io.ReadSeeker) error { - ctx := context.Background() + ctx := dcontext.Background() for dgst, rs := range layers { wr, err := repository.Blobs(ctx).Create(ctx) if err != nil {