forked from TrueCloudLab/distribution
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 <csnider@mirantis.com>
This commit is contained in:
parent
6c694cbcf6
commit
d0f5aa670b
61 changed files with 151 additions and 151 deletions
|
@ -7,7 +7,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"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/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) {
|
func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks map[string]string) {
|
||||||
p, err := json.Marshal(checks)
|
p, err := json.Marshal(checks)
|
||||||
if err != nil {
|
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 {
|
p, err = json.Marshal(struct {
|
||||||
ServerError string `json:"server_error"`
|
ServerError string `json:"server_error"`
|
||||||
}{
|
}{
|
||||||
|
@ -288,7 +288,7 @@ func statusResponse(w http.ResponseWriter, r *http.Request, status int, checks m
|
||||||
status = http.StatusInternalServerError
|
status = http.StatusInternalServerError
|
||||||
|
|
||||||
if err != nil {
|
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
|
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.Header().Set("Content-Length", fmt.Sprint(len(p)))
|
||||||
w.WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
if _, err := w.Write(p); err != nil {
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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"
|
||||||
"github.com/distribution/distribution/v3/manifest/ocischema"
|
"github.com/distribution/distribution/v3/manifest/ocischema"
|
||||||
"github.com/distribution/distribution/v3/registry/api/errcode"
|
"github.com/distribution/distribution/v3/registry/api/errcode"
|
||||||
|
@ -108,7 +108,7 @@ func TestBlobServeBlob(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
repo, _ := reference.WithName("test.example.com/repo1")
|
repo, _ := reference.WithName("test.example.com/repo1")
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -157,7 +157,7 @@ func TestBlobServeBlobHEAD(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
repo, _ := reference.WithName("test.example.com/repo1")
|
repo, _ := reference.WithName("test.example.com/repo1")
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -250,7 +250,7 @@ func TestBlobResume(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -307,7 +307,7 @@ func TestBlobDelete(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -327,7 +327,7 @@ func TestBlobFetch(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
repo, _ := reference.WithName("test.example.com/repo1")
|
repo, _ := reference.WithName("test.example.com/repo1")
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -382,7 +382,7 @@ func TestBlobExistsNoContentLength(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -406,7 +406,7 @@ func TestBlobExists(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
repo, _ := reference.WithName("test.example.com/repo1")
|
repo, _ := reference.WithName("test.example.com/repo1")
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -512,7 +512,7 @@ func TestBlobUploadChunked(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -622,7 +622,7 @@ func TestBlobUploadMonolithic(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -728,7 +728,7 @@ func TestBlobUploadMonolithicDockerUploadUUIDFromURL(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -833,7 +833,7 @@ func TestBlobUploadMonolithicNoDockerUploadUUID(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -891,7 +891,7 @@ func TestBlobMount(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1066,7 +1066,7 @@ func checkEqualManifest(m1, m2 *ocischema.DeserializedManifest) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOCIManifestFetch(t *testing.T) {
|
func TestOCIManifestFetch(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
repo, _ := reference.WithName("test.example.com/repo")
|
repo, _ := reference.WithName("test.example.com/repo")
|
||||||
m1, dgst, pl := newRandomOCIManifest(t, 6)
|
m1, dgst, pl := newRandomOCIManifest(t, 6)
|
||||||
var m testutil.RequestResponseMap
|
var m testutil.RequestResponseMap
|
||||||
|
@ -1149,7 +1149,7 @@ func TestManifestFetchWithEtag(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1171,7 +1171,7 @@ func TestManifestFetchWithEtag(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestManifestFetchWithAccept(t *testing.T) {
|
func TestManifestFetchWithAccept(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
repo, _ := reference.WithName("test.example.com/repo")
|
repo, _ := reference.WithName("test.example.com/repo")
|
||||||
_, dgst, _ := newRandomOCIManifest(t, 6)
|
_, dgst, _ := newRandomOCIManifest(t, 6)
|
||||||
headers := make(chan []string, 1)
|
headers := make(chan []string, 1)
|
||||||
|
@ -1258,7 +1258,7 @@ func TestManifestDelete(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
ms, err := r.Manifests(ctx)
|
ms, err := r.Manifests(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1315,7 +1315,7 @@ func TestManifestPut(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
ms, err := r.Manifests(ctx)
|
ms, err := r.Manifests(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1372,7 +1372,7 @@ func TestManifestTags(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
tagService := r.Tags(ctx)
|
tagService := r.Tags(ctx)
|
||||||
|
|
||||||
tags, err := tagService.All(ctx)
|
tags, err := tagService.All(ctx)
|
||||||
|
@ -1423,7 +1423,7 @@ func TestTagDelete(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
ts := r.Tags(ctx)
|
ts := r.Tags(ctx)
|
||||||
|
|
||||||
if err := ts.Untag(ctx, tag); err != nil {
|
if err := ts.Untag(ctx, tag); err != nil {
|
||||||
|
@ -1460,7 +1460,7 @@ func TestObtainsErrorForMissingTag(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1487,7 +1487,7 @@ func TestObtainsManifestForTagWithoutHeaders(t *testing.T) {
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
r, err := NewRepository(repo, e, nil)
|
r, err := NewRepository(repo, e, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1566,7 +1566,7 @@ func TestManifestTagsPaginated(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
tagService := r.Tags(ctx)
|
tagService := r.Tags(ctx)
|
||||||
|
|
||||||
tags, err := tagService.All(ctx)
|
tags, err := tagService.All(ctx)
|
||||||
|
@ -1614,7 +1614,7 @@ func TestManifestUnauthorized(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
ms, err := r.Manifests(ctx)
|
ms, err := r.Manifests(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1652,7 +1652,7 @@ func TestCatalog(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
numFilled, err := r.Repositories(ctx, entries, "")
|
numFilled, err := r.Repositories(ctx, entries, "")
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1684,7 +1684,7 @@ func TestCatalogInParts(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
numFilled, err := r.Repositories(ctx, entries, "")
|
numFilled, err := r.Repositories(ctx, entries, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package context
|
package dcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -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
|
// Go's context in http requests. Primarily, the focus is on logging relevant
|
||||||
// request information but this package is not limited to that purpose.
|
// request information but this package is not limited to that purpose.
|
||||||
//
|
//
|
||||||
// The easiest way to get started is to get the background context:
|
// 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
|
// 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
|
// root of all other context instances. If the application has a version, this
|
||||||
// line should be called before anything else:
|
// 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 above will store the version in the context and will be available to
|
||||||
// the logger.
|
// the logger.
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
// the context and reported with the logger. The following example would
|
// the context and reported with the logger. The following example would
|
||||||
// return a logger that prints the version with each log message:
|
// 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")
|
// GetLogger(ctx, "version").Infof("this log message has a version field")
|
||||||
//
|
//
|
||||||
// The above would print out a log message like this:
|
// 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 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
|
// can analyze call flow for a particular request with a simple grep of the
|
||||||
// logs.
|
// logs.
|
||||||
package context
|
package dcontext
|
|
@ -1,4 +1,4 @@
|
||||||
package context
|
package dcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package context
|
package dcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
|
@ -1,4 +1,4 @@
|
||||||
package context
|
package dcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package context
|
package dcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package context
|
package dcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
"runtime"
|
|
@ -1,4 +1,4 @@
|
||||||
package context
|
package dcontext
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
|
@ -1,4 +1,4 @@
|
||||||
package context
|
package dcontext
|
||||||
|
|
||||||
import "context"
|
import "context"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package context
|
package dcontext
|
||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"github.com/distribution/distribution/v3"
|
||||||
"github.com/distribution/distribution/v3/context"
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
events "github.com/docker/go-events"
|
events "github.com/docker/go-events"
|
||||||
"github.com/google/uuid"
|
"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 {
|
func NewRequestRecord(id string, r *http.Request) RequestRecord {
|
||||||
return RequestRecord{
|
return RequestRecord{
|
||||||
ID: id,
|
ID: id,
|
||||||
Addr: context.RemoteAddr(r),
|
Addr: dcontext.RemoteAddr(r),
|
||||||
Host: r.Host,
|
Host: r.Host,
|
||||||
Method: r.Method,
|
Method: r.Method,
|
||||||
UserAgent: r.UserAgent(),
|
UserAgent: r.UserAgent(),
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/distribution/reference"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/manifest/schema2"
|
||||||
"github.com/distribution/distribution/v3/registry/storage"
|
"github.com/distribution/distribution/v3/registry/storage"
|
||||||
"github.com/distribution/distribution/v3/registry/storage/cache/memory"
|
"github.com/distribution/distribution/v3/registry/storage/cache/memory"
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
"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"
|
"github.com/distribution/distribution/v3/registry/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/context"
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
"github.com/distribution/distribution/v3/registry/auth"
|
"github.com/distribution/distribution/v3/registry/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func TestBasicAccessController(t *testing.T) {
|
||||||
"realm": testRealm,
|
"realm": testRealm,
|
||||||
"path": tempFile.Name(),
|
"path": tempFile.Name(),
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
|
|
||||||
accessController, err := newAccessController(options)
|
accessController, err := newAccessController(options)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -45,7 +45,7 @@ func TestBasicAccessController(t *testing.T) {
|
||||||
userNumber := 0
|
userNumber := 0
|
||||||
|
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
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)
|
authCtx, err := accessController.Authorized(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err := err.(type) {
|
switch err := err.(type) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
dcontext "github.com/distribution/distribution/v3/context"
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
"github.com/distribution/distribution/v3/registry/auth"
|
"github.com/distribution/distribution/v3/registry/auth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/context"
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
"github.com/distribution/distribution/v3/registry/auth"
|
"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) {
|
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)
|
authCtx, err := ac.Authorized(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err := err.(type) {
|
switch err := err.(type) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
dcontext "github.com/distribution/distribution/v3/context"
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
"github.com/distribution/distribution/v3/registry/auth"
|
"github.com/distribution/distribution/v3/registry/auth"
|
||||||
"github.com/go-jose/go-jose/v3"
|
"github.com/go-jose/go-jose/v3"
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,7 +18,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/context"
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
"github.com/distribution/distribution/v3/registry/auth"
|
"github.com/distribution/distribution/v3/registry/auth"
|
||||||
"github.com/go-jose/go-jose/v3"
|
"github.com/go-jose/go-jose/v3"
|
||||||
"github.com/go-jose/go-jose/v3/jwt"
|
"github.com/go-jose/go-jose/v3/jwt"
|
||||||
|
@ -466,7 +466,7 @@ func TestAccessController(t *testing.T) {
|
||||||
Action: "baz",
|
Action: "baz",
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.WithRequest(context.Background(), req)
|
ctx := dcontext.WithRequest(dcontext.Background(), req)
|
||||||
authCtx, err := accessController.Authorized(ctx, testAccess)
|
authCtx, err := accessController.Authorized(ctx, testAccess)
|
||||||
challenge, ok := err.(auth.Challenge)
|
challenge, ok := err.(auth.Challenge)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -19,9 +19,9 @@ import (
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"github.com/distribution/distribution/v3"
|
||||||
"github.com/distribution/distribution/v3/configuration"
|
"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"
|
||||||
"github.com/distribution/distribution/v3/health/checks"
|
"github.com/distribution/distribution/v3/health/checks"
|
||||||
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
prometheus "github.com/distribution/distribution/v3/metrics"
|
prometheus "github.com/distribution/distribution/v3/metrics"
|
||||||
"github.com/distribution/distribution/v3/notifications"
|
"github.com/distribution/distribution/v3/notifications"
|
||||||
"github.com/distribution/distribution/v3/registry/api/errcode"
|
"github.com/distribution/distribution/v3/registry/api/errcode"
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/configuration"
|
"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"
|
"github.com/distribution/distribution/v3/registry/api/errcode"
|
||||||
v2 "github.com/distribution/distribution/v3/registry/api/v2"
|
v2 "github.com/distribution/distribution/v3/registry/api/v2"
|
||||||
"github.com/distribution/distribution/v3/registry/auth"
|
"github.com/distribution/distribution/v3/registry/auth"
|
||||||
|
@ -25,7 +25,7 @@ import (
|
||||||
// tested individually.
|
// tested individually.
|
||||||
func TestAppDispatcher(t *testing.T) {
|
func TestAppDispatcher(t *testing.T) {
|
||||||
driver := inmemory.New()
|
driver := inmemory.New()
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
registry, err := storage.NewRegistry(ctx, driver, storage.BlobDescriptorCacheProvider(memorycache.NewInMemoryBlobDescriptorCacheProvider(0)), storage.EnableDelete, storage.EnableRedirect)
|
registry, err := storage.NewRegistry(ctx, driver, storage.BlobDescriptorCacheProvider(memorycache.NewInMemoryBlobDescriptorCacheProvider(0)), storage.EnableDelete, storage.EnableRedirect)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating registry: %v", err)
|
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
|
// TestNewApp covers the creation of an application via NewApp with a
|
||||||
// configuration.
|
// configuration.
|
||||||
func TestNewApp(t *testing.T) {
|
func TestNewApp(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
config := configuration.Configuration{
|
config := configuration.Configuration{
|
||||||
Storage: configuration.Storage{
|
Storage: configuration.Storage{
|
||||||
"inmemory": nil,
|
"inmemory": nil,
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/distribution/distribution/v3/registry/api/errcode"
|
||||||
"github.com/gorilla/handlers"
|
"github.com/gorilla/handlers"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
|
@ -53,7 +53,7 @@ type blobHandler struct {
|
||||||
// GetBlob fetches the binary data from backend storage returns it in the
|
// GetBlob fetches the binary data from backend storage returns it in the
|
||||||
// response.
|
// response.
|
||||||
func (bh *blobHandler) GetBlob(w http.ResponseWriter, r *http.Request) {
|
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)
|
blobs := bh.Repository.Blobs(bh)
|
||||||
desc, err := blobs.Stat(bh, bh.Digest)
|
desc, err := blobs.Stat(bh, bh.Digest)
|
||||||
if err != nil {
|
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 {
|
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))
|
bh.Errors = append(bh.Errors, errcode.ErrorCodeUnknown.WithDetail(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ func (bh *blobHandler) GetBlob(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// DeleteBlob deletes a layer blob
|
// DeleteBlob deletes a layer blob
|
||||||
func (bh *blobHandler) DeleteBlob(w http.ResponseWriter, r *http.Request) {
|
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)
|
blobs := bh.Repository.Blobs(bh)
|
||||||
err := blobs.Delete(bh, bh.Digest)
|
err := blobs.Delete(bh, bh.Digest)
|
||||||
|
@ -88,7 +88,7 @@ func (bh *blobHandler) DeleteBlob(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
bh.Errors = append(bh.Errors, err)
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/api/errcode"
|
||||||
"github.com/distribution/distribution/v3/registry/storage"
|
"github.com/distribution/distribution/v3/registry/storage"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/api/errcode"
|
||||||
v2 "github.com/distribution/distribution/v3/registry/api/v2"
|
v2 "github.com/distribution/distribution/v3/registry/api/v2"
|
||||||
"github.com/distribution/distribution/v3/registry/auth"
|
"github.com/distribution/distribution/v3/registry/auth"
|
||||||
|
|
|
@ -9,8 +9,8 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/configuration"
|
"github.com/distribution/distribution/v3/configuration"
|
||||||
"github.com/distribution/distribution/v3/context"
|
|
||||||
"github.com/distribution/distribution/v3/health"
|
"github.com/distribution/distribution/v3/health"
|
||||||
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFileHealthCheck(t *testing.T) {
|
func TestFileHealthCheck(t *testing.T) {
|
||||||
|
@ -39,7 +39,7 @@ func TestFileHealthCheck(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
|
|
||||||
app := NewApp(ctx, config)
|
app := NewApp(ctx, config)
|
||||||
healthRegistry := health.NewRegistry()
|
healthRegistry := health.NewRegistry()
|
||||||
|
@ -103,7 +103,7 @@ func TestTCPHealthCheck(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
|
|
||||||
app := NewApp(ctx, config)
|
app := NewApp(ctx, config)
|
||||||
healthRegistry := health.NewRegistry()
|
healthRegistry := health.NewRegistry()
|
||||||
|
@ -165,7 +165,7 @@ func TestHTTPHealthCheck(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
|
|
||||||
app := NewApp(ctx, config)
|
app := NewApp(ctx, config)
|
||||||
healthRegistry := health.NewRegistry()
|
healthRegistry := health.NewRegistry()
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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
|
// closeResources closes all the provided resources after running the target
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/manifestlist"
|
||||||
"github.com/distribution/distribution/v3/manifest/ocischema"
|
"github.com/distribution/distribution/v3/manifest/ocischema"
|
||||||
"github.com/distribution/distribution/v3/manifest/schema2"
|
"github.com/distribution/distribution/v3/manifest/schema2"
|
||||||
|
|
|
@ -5,9 +5,9 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/context"
|
|
||||||
"github.com/distribution/distribution/v3/internal/client/auth"
|
"github.com/distribution/distribution/v3/internal/client/auth"
|
||||||
"github.com/distribution/distribution/v3/internal/client/auth/challenge"
|
"github.com/distribution/distribution/v3/internal/client/auth/challenge"
|
||||||
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
)
|
)
|
||||||
|
|
||||||
const challengeHeader = "Docker-Distribution-Api-Version"
|
const challengeHeader = "Docker-Distribution-Api-Version"
|
||||||
|
@ -44,7 +44,7 @@ func configureAuth(username, password, remoteURL string) (auth.CredentialStore,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, url := range authURLs {
|
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{
|
creds[url] = userpass{
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/distribution/v3/registry/proxy/scheduler"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
)
|
)
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/distribution/v3/registry/proxy/scheduler"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,11 +10,11 @@ import (
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"github.com/distribution/distribution/v3"
|
||||||
"github.com/distribution/distribution/v3/configuration"
|
"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"
|
||||||
"github.com/distribution/distribution/v3/internal/client/auth"
|
"github.com/distribution/distribution/v3/internal/client/auth"
|
||||||
"github.com/distribution/distribution/v3/internal/client/auth/challenge"
|
"github.com/distribution/distribution/v3/internal/client/auth/challenge"
|
||||||
"github.com/distribution/distribution/v3/internal/client/transport"
|
"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/proxy/scheduler"
|
||||||
"github.com/distribution/distribution/v3/registry/storage"
|
"github.com/distribution/distribution/v3/registry/storage"
|
||||||
"github.com/distribution/distribution/v3/registry/storage/driver"
|
"github.com/distribution/distribution/v3/registry/storage/driver"
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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/distribution/v3/registry/storage/driver"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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/distribution/v3/registry/storage/driver/inmemory"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
)
|
)
|
||||||
|
@ -40,7 +40,7 @@ func TestSchedule(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var mu sync.Mutex
|
var mu sync.Mutex
|
||||||
s := New(context.Background(), inmemory.New(), "/ttl")
|
s := New(dcontext.Background(), inmemory.New(), "/ttl")
|
||||||
deleteFunc := func(repoName reference.Reference) error {
|
deleteFunc := func(repoName reference.Reference) error {
|
||||||
if len(remainingRepos) == 0 {
|
if len(remainingRepos) == 0 {
|
||||||
t.Fatalf("Incorrect expiry count")
|
t.Fatalf("Incorrect expiry count")
|
||||||
|
@ -123,14 +123,14 @@ func TestRestoreOld(t *testing.T) {
|
||||||
t.Fatalf("Error serializing test data: %s", err.Error())
|
t.Fatalf("Error serializing test data: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
pathToStatFile := "/ttl"
|
pathToStatFile := "/ttl"
|
||||||
fs := inmemory.New()
|
fs := inmemory.New()
|
||||||
err = fs.PutContent(ctx, pathToStatFile, serialized)
|
err = fs.PutContent(ctx, pathToStatFile, serialized)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal("Unable to write serialized data to fs")
|
t.Fatal("Unable to write serialized data to fs")
|
||||||
}
|
}
|
||||||
s := New(context.Background(), fs, "/ttl")
|
s := New(dcontext.Background(), fs, "/ttl")
|
||||||
s.OnBlobExpire(deleteFunc)
|
s.OnBlobExpire(deleteFunc)
|
||||||
err = s.Start()
|
err = s.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -165,7 +165,7 @@ func TestStopRestore(t *testing.T) {
|
||||||
|
|
||||||
fs := inmemory.New()
|
fs := inmemory.New()
|
||||||
pathToStateFile := "/ttl"
|
pathToStateFile := "/ttl"
|
||||||
s := New(context.Background(), fs, pathToStateFile)
|
s := New(dcontext.Background(), fs, pathToStateFile)
|
||||||
s.onBlobExpire = deleteFunc
|
s.onBlobExpire = deleteFunc
|
||||||
|
|
||||||
err := s.Start()
|
err := s.Start()
|
||||||
|
@ -181,7 +181,7 @@ func TestStopRestore(t *testing.T) {
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
|
||||||
// v2 will restore state from fs
|
// v2 will restore state from fs
|
||||||
s2 := New(context.Background(), fs, pathToStateFile)
|
s2 := New(dcontext.Background(), fs, pathToStateFile)
|
||||||
s2.onBlobExpire = deleteFunc
|
s2.onBlobExpire = deleteFunc
|
||||||
err = s2.Start()
|
err = s2.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -197,7 +197,7 @@ func TestStopRestore(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDoubleStart(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()
|
err := s.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Unable to start scheduler")
|
t.Fatalf("Unable to start scheduler")
|
||||||
|
|
|
@ -21,8 +21,8 @@ import (
|
||||||
"golang.org/x/crypto/acme/autocert"
|
"golang.org/x/crypto/acme/autocert"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/configuration"
|
"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"
|
||||||
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
"github.com/distribution/distribution/v3/registry/handlers"
|
"github.com/distribution/distribution/v3/registry/handlers"
|
||||||
"github.com/distribution/distribution/v3/registry/listener"
|
"github.com/distribution/distribution/v3/registry/listener"
|
||||||
"github.com/distribution/distribution/v3/version"
|
"github.com/distribution/distribution/v3/version"
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3/configuration"
|
"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/distribution/distribution/v3/registry/storage/driver/inmemory"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"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"
|
||||||
"github.com/distribution/distribution/v3/registry/storage/driver/factory"
|
"github.com/distribution/distribution/v3/registry/storage/driver/factory"
|
||||||
"github.com/distribution/distribution/v3/version"
|
"github.com/distribution/distribution/v3/version"
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/distribution/v3/registry/storage/driver"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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"
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/distribution/distribution/v3/context"
|
"context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// resumeHashAt is a noop when resumable digest support is disabled.
|
// resumeHashAt is a noop when resumable digest support is disabled.
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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"
|
prometheus "github.com/distribution/distribution/v3/metrics"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
|
|
@ -42,7 +42,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
dcontext "github.com/distribution/distribution/v3/context"
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
prometheus "github.com/distribution/distribution/v3/metrics"
|
prometheus "github.com/distribution/distribution/v3/metrics"
|
||||||
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||||
"github.com/docker/go-metrics"
|
"github.com/docker/go-metrics"
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"cloud.google.com/go/storage"
|
"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"
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||||
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/aws/aws-sdk-go/service/cloudfront/sign"
|
"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"
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||||
storagemiddleware "github.com/distribution/distribution/v3/registry/storage/driver/middleware"
|
storagemiddleware "github.com/distribution/distribution/v3/registry/storage/driver/middleware"
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
dcontext "github.com/distribution/distribution/v3/context"
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
dcontext "github.com/distribution/distribution/v3/context"
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Rather than pull in all of testify
|
// Rather than pull in all of testify
|
||||||
|
|
|
@ -36,7 +36,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws/session"
|
"github.com/aws/aws-sdk-go/aws/session"
|
||||||
"github.com/aws/aws-sdk-go/service/s3"
|
"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"
|
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/base"
|
||||||
"github.com/distribution/distribution/v3/registry/storage/driver/factory"
|
"github.com/distribution/distribution/v3/registry/storage/driver/factory"
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/service/s3"
|
"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"
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||||
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
"github.com/distribution/distribution/v3/registry/storage/driver/testsuites"
|
||||||
)
|
)
|
||||||
|
@ -180,7 +180,7 @@ func TestEmptyRootList(t *testing.T) {
|
||||||
|
|
||||||
filename := "/test"
|
filename := "/test"
|
||||||
contents := []byte("contents")
|
contents := []byte("contents")
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
err = rootedDriver.PutContent(ctx, filename, contents)
|
err = rootedDriver.PutContent(ctx, filename, contents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error creating content: %v", err)
|
t.Fatalf("unexpected error creating content: %v", err)
|
||||||
|
@ -209,7 +209,7 @@ func TestStorageClass(t *testing.T) {
|
||||||
|
|
||||||
rootDir := t.TempDir()
|
rootDir := t.TempDir()
|
||||||
contents := []byte("contents")
|
contents := []byte("contents")
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
|
|
||||||
// We don't need to test all the storage classes, just that its selectable.
|
// 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.
|
// 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
|
// init file structure matching objs
|
||||||
var created []string
|
var created []string
|
||||||
for _, p := range objs {
|
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 {
|
if err != nil {
|
||||||
fmt.Printf("unable to init file %s: %s\n", p, err)
|
fmt.Printf("unable to init file %s: %s\n", p, err)
|
||||||
continue
|
continue
|
||||||
|
@ -390,7 +390,7 @@ func TestDelete(t *testing.T) {
|
||||||
cleanup := func(objs []string) {
|
cleanup := func(objs []string) {
|
||||||
var lastErr error
|
var lastErr error
|
||||||
for _, p := range objs {
|
for _, p := range objs {
|
||||||
err := drvr.Delete(context.Background(), p)
|
err := drvr.Delete(dcontext.Background(), p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case storagedriver.PathNotFoundError:
|
case storagedriver.PathNotFoundError:
|
||||||
|
@ -409,7 +409,7 @@ func TestDelete(t *testing.T) {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
objs := init()
|
objs := init()
|
||||||
|
|
||||||
err := drvr.Delete(context.Background(), tc.delete)
|
err := drvr.Delete(dcontext.Background(), tc.delete)
|
||||||
|
|
||||||
if tc.err != nil {
|
if tc.err != nil {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -437,7 +437,7 @@ func TestDelete(t *testing.T) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
for _, path := range objs {
|
for _, path := range objs {
|
||||||
stat, err := drvr.Stat(context.Background(), path)
|
stat, err := drvr.Stat(dcontext.Background(), path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case storagedriver.PathNotFoundError:
|
case storagedriver.PathNotFoundError:
|
||||||
|
@ -491,7 +491,7 @@ func TestWalk(t *testing.T) {
|
||||||
// create file structure matching fileset above
|
// create file structure matching fileset above
|
||||||
created := make([]string, 0, len(fileset))
|
created := make([]string, 0, len(fileset))
|
||||||
for _, p := range 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 {
|
if err != nil {
|
||||||
fmt.Printf("unable to create file %s: %s\n", p, err)
|
fmt.Printf("unable to create file %s: %s\n", p, err)
|
||||||
continue
|
continue
|
||||||
|
@ -503,7 +503,7 @@ func TestWalk(t *testing.T) {
|
||||||
defer func() {
|
defer func() {
|
||||||
var lastErr error
|
var lastErr error
|
||||||
for _, p := range created {
|
for _, p := range created {
|
||||||
err := drvr.Delete(context.Background(), p)
|
err := drvr.Delete(dcontext.Background(), p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = fmt.Errorf("cleanup failed for path %s: %s", p, err)
|
_ = fmt.Errorf("cleanup failed for path %s: %s", p, err)
|
||||||
lastErr = err
|
lastErr = err
|
||||||
|
@ -692,7 +692,7 @@ func TestWalk(t *testing.T) {
|
||||||
tc.from = "/"
|
tc.from = "/"
|
||||||
}
|
}
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
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())
|
walked = append(walked, fileInfo.Path())
|
||||||
return tc.fn(fileInfo)
|
return tc.fn(fileInfo)
|
||||||
}, tc.options...)
|
}, tc.options...)
|
||||||
|
@ -718,7 +718,7 @@ func TestOverThousandBlobs(t *testing.T) {
|
||||||
t.Fatalf("unexpected error creating driver with standard storage: %v", err)
|
t.Fatalf("unexpected error creating driver with standard storage: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
for i := 0; i < 1005; i++ {
|
for i := 0; i < 1005; i++ {
|
||||||
filename := "/thousandfiletest/file" + strconv.Itoa(i)
|
filename := "/thousandfiletest/file" + strconv.Itoa(i)
|
||||||
contents := []byte("contents")
|
contents := []byte("contents")
|
||||||
|
@ -746,7 +746,7 @@ func TestMoveWithMultipartCopy(t *testing.T) {
|
||||||
t.Fatalf("unexpected error creating driver: %v", err)
|
t.Fatalf("unexpected error creating driver: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
sourcePath := "/source"
|
sourcePath := "/source"
|
||||||
destPath := "/dest"
|
destPath := "/dest"
|
||||||
|
|
||||||
|
@ -795,7 +795,7 @@ func TestListObjectsV2(t *testing.T) {
|
||||||
t.Fatalf("unexpected error creating driver: %v", err)
|
t.Fatalf("unexpected error creating driver: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
n := 6
|
n := 6
|
||||||
prefix := "/test-list-objects-v2"
|
prefix := "/test-list-objects-v2"
|
||||||
var filePaths []string
|
var filePaths []string
|
||||||
|
|
|
@ -7,13 +7,13 @@ import (
|
||||||
mrand "math/rand"
|
mrand "math/rand"
|
||||||
"testing"
|
"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/distribution/distribution/v3/registry/storage/driver/inmemory"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSimpleRead(t *testing.T) {
|
func TestSimpleRead(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
content := make([]byte, 1<<20)
|
content := make([]byte, 1<<20)
|
||||||
n, err := crand.Read(content)
|
n, err := crand.Read(content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -55,7 +55,7 @@ func TestFileReaderSeek(t *testing.T) {
|
||||||
repititions := 1024
|
repititions := 1024
|
||||||
path := "/patterned"
|
path := "/patterned"
|
||||||
content := bytes.Repeat([]byte(pattern), repititions)
|
content := bytes.Repeat([]byte(pattern), repititions)
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
|
|
||||||
if err := driver.PutContent(ctx, path, content); err != nil {
|
if err := driver.PutContent(ctx, path, content); err != nil {
|
||||||
t.Fatalf("error putting patterned content: %v", err)
|
t.Fatalf("error putting patterned content: %v", err)
|
||||||
|
@ -156,7 +156,7 @@ func TestFileReaderSeek(t *testing.T) {
|
||||||
// read method, with an io.EOF error.
|
// read method, with an io.EOF error.
|
||||||
func TestFileReaderNonExistentFile(t *testing.T) {
|
func TestFileReaderNonExistentFile(t *testing.T) {
|
||||||
driver := inmemory.New()
|
driver := inmemory.New()
|
||||||
fr, err := newFileReader(context.Background(), driver, "/doesnotexist", 10)
|
fr, err := newFileReader(dcontext.Background(), driver, "/doesnotexist", 10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error initializing reader: %v", err)
|
t.Fatalf("unexpected error initializing reader: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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"
|
||||||
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
||||||
"github.com/distribution/distribution/v3/testutil"
|
"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 {
|
func createRegistry(t *testing.T, driver driver.StorageDriver, options ...RegistryOption) distribution.Namespace {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
options = append(options, EnableDelete)
|
options = append(options, EnableDelete)
|
||||||
registry, err := NewRegistry(ctx, driver, options...)
|
registry, err := NewRegistry(ctx, driver, options...)
|
||||||
if err != nil {
|
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 {
|
func makeRepository(t *testing.T, registry distribution.Namespace, name string) distribution.Repository {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
|
|
||||||
// Initialize a dummy repository
|
// Initialize a dummy repository
|
||||||
named, err := reference.WithName(name)
|
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 {
|
func makeManifestService(t *testing.T, repository distribution.Repository) distribution.ManifestService {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
|
|
||||||
manifestService, err := repository.Manifests(ctx)
|
manifestService, err := repository.Manifests(ctx)
|
||||||
if err != nil {
|
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{} {
|
func allManifests(t *testing.T, manifestService distribution.ManifestService) map[digest.Digest]struct{} {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
allManMap := make(map[digest.Digest]struct{})
|
allManMap := make(map[digest.Digest]struct{})
|
||||||
manifestEnumerator, ok := manifestService.(distribution.ManifestEnumerator)
|
manifestEnumerator, ok := manifestService.(distribution.ManifestEnumerator)
|
||||||
if !ok {
|
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{} {
|
func allBlobs(t *testing.T, registry distribution.Namespace) map[digest.Digest]struct{} {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
blobService := registry.Blobs()
|
blobService := registry.Blobs()
|
||||||
allBlobsMap := make(map[digest.Digest]struct{})
|
allBlobsMap := make(map[digest.Digest]struct{})
|
||||||
err := blobService.Enumerate(ctx, func(dgst digest.Digest) error {
|
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
|
// upload manifest
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
manifestService := makeManifestService(t, repository)
|
manifestService := makeManifestService(t, repository)
|
||||||
manifestDigest, err := manifestService.Put(ctx, im.manifest)
|
manifestDigest, err := manifestService.Put(ctx, im.manifest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -130,7 +130,7 @@ func uploadRandomSchema2Image(t *testing.T, repository distribution.Repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNoDeletionNoEffect(t *testing.T) {
|
func TestNoDeletionNoEffect(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
inmemoryDriver := inmemory.New()
|
inmemoryDriver := inmemory.New()
|
||||||
|
|
||||||
registry := createRegistry(t, inmemoryDriver)
|
registry := createRegistry(t, inmemoryDriver)
|
||||||
|
@ -158,7 +158,7 @@ func TestNoDeletionNoEffect(t *testing.T) {
|
||||||
before := allBlobs(t, registry)
|
before := allBlobs(t, registry)
|
||||||
|
|
||||||
// Run GC
|
// Run GC
|
||||||
err = MarkAndSweep(context.Background(), inmemoryDriver, registry, GCOpts{
|
err = MarkAndSweep(dcontext.Background(), inmemoryDriver, registry, GCOpts{
|
||||||
DryRun: false,
|
DryRun: false,
|
||||||
RemoveUntagged: false,
|
RemoveUntagged: false,
|
||||||
})
|
})
|
||||||
|
@ -173,7 +173,7 @@ func TestNoDeletionNoEffect(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteManifestIfTagNotFound(t *testing.T) {
|
func TestDeleteManifestIfTagNotFound(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
inmemoryDriver := inmemory.New()
|
inmemoryDriver := inmemory.New()
|
||||||
|
|
||||||
registry := createRegistry(t, inmemoryDriver)
|
registry := createRegistry(t, inmemoryDriver)
|
||||||
|
@ -233,7 +233,7 @@ func TestDeleteManifestIfTagNotFound(t *testing.T) {
|
||||||
before2 := allManifests(t, manifestService)
|
before2 := allManifests(t, manifestService)
|
||||||
|
|
||||||
// run GC with dry-run (should not remove anything)
|
// 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,
|
DryRun: true,
|
||||||
RemoveUntagged: true,
|
RemoveUntagged: true,
|
||||||
})
|
})
|
||||||
|
@ -250,7 +250,7 @@ func TestDeleteManifestIfTagNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run GC (removes everything because no manifests with tags exist)
|
// 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,
|
DryRun: false,
|
||||||
RemoveUntagged: true,
|
RemoveUntagged: true,
|
||||||
})
|
})
|
||||||
|
@ -269,7 +269,7 @@ func TestDeleteManifestIfTagNotFound(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGCWithMissingManifests(t *testing.T) {
|
func TestGCWithMissingManifests(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
d := inmemory.New()
|
d := inmemory.New()
|
||||||
|
|
||||||
registry := createRegistry(t, d)
|
registry := createRegistry(t, d)
|
||||||
|
@ -288,7 +288,7 @@ func TestGCWithMissingManifests(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = MarkAndSweep(context.Background(), d, registry, GCOpts{
|
err = MarkAndSweep(dcontext.Background(), d, registry, GCOpts{
|
||||||
DryRun: false,
|
DryRun: false,
|
||||||
RemoveUntagged: false,
|
RemoveUntagged: false,
|
||||||
})
|
})
|
||||||
|
@ -303,7 +303,7 @@ func TestGCWithMissingManifests(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeletionHasEffect(t *testing.T) {
|
func TestDeletionHasEffect(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
inmemoryDriver := inmemory.New()
|
inmemoryDriver := inmemory.New()
|
||||||
|
|
||||||
registry := createRegistry(t, inmemoryDriver)
|
registry := createRegistry(t, inmemoryDriver)
|
||||||
|
@ -318,7 +318,7 @@ func TestDeletionHasEffect(t *testing.T) {
|
||||||
manifests.Delete(ctx, image3.manifestDigest)
|
manifests.Delete(ctx, image3.manifestDigest)
|
||||||
|
|
||||||
// Run GC
|
// Run GC
|
||||||
err := MarkAndSweep(context.Background(), inmemoryDriver, registry, GCOpts{
|
err := MarkAndSweep(dcontext.Background(), inmemoryDriver, registry, GCOpts{
|
||||||
DryRun: false,
|
DryRun: false,
|
||||||
RemoveUntagged: false,
|
RemoveUntagged: false,
|
||||||
})
|
})
|
||||||
|
@ -368,7 +368,7 @@ func getKeys(digests map[digest.Digest]io.ReadSeeker) (ds []digest.Digest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeletionWithSharedLayer(t *testing.T) {
|
func TestDeletionWithSharedLayer(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
inmemoryDriver := inmemory.New()
|
inmemoryDriver := inmemory.New()
|
||||||
|
|
||||||
registry := createRegistry(t, inmemoryDriver)
|
registry := createRegistry(t, inmemoryDriver)
|
||||||
|
@ -455,7 +455,7 @@ func TestOrphanBlobDeleted(t *testing.T) {
|
||||||
uploadRandomSchema2Image(t, repo)
|
uploadRandomSchema2Image(t, repo)
|
||||||
|
|
||||||
// Run GC
|
// Run GC
|
||||||
err = MarkAndSweep(context.Background(), inmemoryDriver, registry, GCOpts{
|
err = MarkAndSweep(dcontext.Background(), inmemoryDriver, registry, GCOpts{
|
||||||
DryRun: false,
|
DryRun: false,
|
||||||
RemoveUntagged: false,
|
RemoveUntagged: false,
|
||||||
})
|
})
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/distribution/v3/registry/storage/driver"
|
||||||
"github.com/distribution/reference"
|
"github.com/distribution/reference"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/manifestlist"
|
||||||
"github.com/distribution/distribution/v3/manifest/ocischema"
|
"github.com/distribution/distribution/v3/manifest/ocischema"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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"
|
||||||
"github.com/distribution/distribution/v3/manifest/manifestlist"
|
"github.com/distribution/distribution/v3/manifest/manifestlist"
|
||||||
"github.com/distribution/distribution/v3/manifest/ocischema"
|
"github.com/distribution/distribution/v3/manifest/ocischema"
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/distribution/distribution/v3/manifest/ocischema"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/distribution/distribution/v3/manifest/ocischema"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/manifest/schema2"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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"
|
||||||
"github.com/distribution/distribution/v3/manifest/schema2"
|
"github.com/distribution/distribution/v3/manifest/schema2"
|
||||||
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
"github.com/distribution/distribution/v3/registry/storage/driver/inmemory"
|
||||||
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVerifyManifestForeignLayer(t *testing.T) {
|
func TestVerifyManifestForeignLayer(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
inmemoryDriver := inmemory.New()
|
inmemoryDriver := inmemory.New()
|
||||||
registry := createRegistry(t, inmemoryDriver,
|
registry := createRegistry(t, inmemoryDriver,
|
||||||
ManifestURLsAllowRegexp(regexp.MustCompile("^https?://foo")),
|
ManifestURLsAllowRegexp(regexp.MustCompile("^https?://foo")),
|
||||||
|
@ -152,7 +152,7 @@ func TestVerifyManifestForeignLayer(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVerifyManifestBlobLayerAndConfig(t *testing.T) {
|
func TestVerifyManifestBlobLayerAndConfig(t *testing.T) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
inmemoryDriver := inmemory.New()
|
inmemoryDriver := inmemory.New()
|
||||||
registry := createRegistry(t, inmemoryDriver,
|
registry := createRegistry(t, inmemoryDriver,
|
||||||
ManifestURLsAllowRegexp(regexp.MustCompile("^https?://foo")),
|
ManifestURLsAllowRegexp(regexp.MustCompile("^https?://foo")),
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"path"
|
"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/distribution/distribution/v3/registry/storage/driver"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"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/manifestlist"
|
||||||
"github.com/distribution/distribution/v3/manifest/schema2"
|
"github.com/distribution/distribution/v3/manifest/schema2"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
|
@ -12,7 +12,7 @@ import (
|
||||||
|
|
||||||
// MakeManifestList constructs a manifest list out of a list of manifest digests
|
// MakeManifestList constructs a manifest list out of a list of manifest digests
|
||||||
func MakeManifestList(blobstatter distribution.BlobStatter, manifestDigests []digest.Digest) (*manifestlist.DeserializedManifestList, error) {
|
func MakeManifestList(blobstatter distribution.BlobStatter, manifestDigests []digest.Digest) (*manifestlist.DeserializedManifestList, error) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
|
|
||||||
manifestDescriptors := make([]manifestlist.ManifestDescriptor, 0, len(manifestDigests))
|
manifestDescriptors := make([]manifestlist.ManifestDescriptor, 0, len(manifestDigests))
|
||||||
for _, manifestDigest := range 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
|
// MakeSchema2Manifest constructs a schema 2 manifest from a given list of digests and returns
|
||||||
// the digest of the manifest
|
// the digest of the manifest
|
||||||
func MakeSchema2Manifest(repository distribution.Repository, digests []digest.Digest) (distribution.Manifest, error) {
|
func MakeSchema2Manifest(repository distribution.Repository, digests []digest.Digest) (distribution.Manifest, error) {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
blobStore := repository.Blobs(ctx)
|
blobStore := repository.Blobs(ctx)
|
||||||
|
|
||||||
var configJSON []byte
|
var configJSON []byte
|
||||||
|
|
|
@ -10,7 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"github.com/distribution/distribution/v3"
|
||||||
"github.com/distribution/distribution/v3/context"
|
"github.com/distribution/distribution/v3/internal/dcontext"
|
||||||
"github.com/opencontainers/go-digest"
|
"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
|
// UploadBlobs lets you upload blobs to a repository
|
||||||
func UploadBlobs(repository distribution.Repository, layers map[digest.Digest]io.ReadSeeker) error {
|
func UploadBlobs(repository distribution.Repository, layers map[digest.Digest]io.ReadSeeker) error {
|
||||||
ctx := context.Background()
|
ctx := dcontext.Background()
|
||||||
for dgst, rs := range layers {
|
for dgst, rs := range layers {
|
||||||
wr, err := repository.Blobs(ctx).Create(ctx)
|
wr, err := repository.Blobs(ctx).Create(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in a new issue