forked from TrueCloudLab/distribution
Update to provide small and clear interfaces
Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
parent
b72f1fd2e3
commit
582a0661bf
6 changed files with 26 additions and 18 deletions
|
@ -13,7 +13,7 @@ var (
|
||||||
nameParameterDescriptor = ParameterDescriptor{
|
nameParameterDescriptor = ParameterDescriptor{
|
||||||
Name: "name",
|
Name: "name",
|
||||||
Type: "string",
|
Type: "string",
|
||||||
Format: reference.RepositoryNameRegexp.String(),
|
Format: reference.NameRegexp.String(),
|
||||||
Required: true,
|
Required: true,
|
||||||
Description: `Name of the target repository.`,
|
Description: `Name of the target repository.`,
|
||||||
}
|
}
|
||||||
|
@ -390,7 +390,7 @@ var routeDescriptors = []RouteDescriptor{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: RouteNameTags,
|
Name: RouteNameTags,
|
||||||
Path: "/v2/{name:" + reference.RepositoryNameRegexp.String() + "}/tags/list",
|
Path: "/v2/{name:" + reference.NameRegexp.String() + "}/tags/list",
|
||||||
Entity: "Tags",
|
Entity: "Tags",
|
||||||
Description: "Retrieve information about tags.",
|
Description: "Retrieve information about tags.",
|
||||||
Methods: []MethodDescriptor{
|
Methods: []MethodDescriptor{
|
||||||
|
@ -518,7 +518,7 @@ var routeDescriptors = []RouteDescriptor{
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: RouteNameManifest,
|
Name: RouteNameManifest,
|
||||||
Path: "/v2/{name:" + reference.RepositoryNameRegexp.String() + "}/manifests/{reference:" + reference.TagRegexp.String() + "|" + digest.DigestRegexp.String() + "}",
|
Path: "/v2/{name:" + reference.NameRegexp.String() + "}/manifests/{reference:" + reference.TagRegexp.String() + "|" + digest.DigestRegexp.String() + "}",
|
||||||
Entity: "Manifest",
|
Entity: "Manifest",
|
||||||
Description: "Create, update, delete and retrieve manifests.",
|
Description: "Create, update, delete and retrieve manifests.",
|
||||||
Methods: []MethodDescriptor{
|
Methods: []MethodDescriptor{
|
||||||
|
@ -783,7 +783,7 @@ var routeDescriptors = []RouteDescriptor{
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: RouteNameBlob,
|
Name: RouteNameBlob,
|
||||||
Path: "/v2/{name:" + reference.RepositoryNameRegexp.String() + "}/blobs/{digest:" + digest.DigestRegexp.String() + "}",
|
Path: "/v2/{name:" + reference.NameRegexp.String() + "}/blobs/{digest:" + digest.DigestRegexp.String() + "}",
|
||||||
Entity: "Blob",
|
Entity: "Blob",
|
||||||
Description: "Operations on blobs identified by `name` and `digest`. Used to fetch or delete layers by digest.",
|
Description: "Operations on blobs identified by `name` and `digest`. Used to fetch or delete layers by digest.",
|
||||||
Methods: []MethodDescriptor{
|
Methods: []MethodDescriptor{
|
||||||
|
@ -1007,7 +1007,7 @@ var routeDescriptors = []RouteDescriptor{
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: RouteNameBlobUpload,
|
Name: RouteNameBlobUpload,
|
||||||
Path: "/v2/{name:" + reference.RepositoryNameRegexp.String() + "}/blobs/uploads/",
|
Path: "/v2/{name:" + reference.NameRegexp.String() + "}/blobs/uploads/",
|
||||||
Entity: "Initiate Blob Upload",
|
Entity: "Initiate Blob Upload",
|
||||||
Description: "Initiate a blob upload. This endpoint can be used to create resumable uploads or monolithic uploads.",
|
Description: "Initiate a blob upload. This endpoint can be used to create resumable uploads or monolithic uploads.",
|
||||||
Methods: []MethodDescriptor{
|
Methods: []MethodDescriptor{
|
||||||
|
@ -1129,7 +1129,7 @@ var routeDescriptors = []RouteDescriptor{
|
||||||
|
|
||||||
{
|
{
|
||||||
Name: RouteNameBlobUploadChunk,
|
Name: RouteNameBlobUploadChunk,
|
||||||
Path: "/v2/{name:" + reference.RepositoryNameRegexp.String() + "}/blobs/uploads/{uuid:[a-zA-Z0-9-_.=]+}",
|
Path: "/v2/{name:" + reference.NameRegexp.String() + "}/blobs/uploads/{uuid:[a-zA-Z0-9-_.=]+}",
|
||||||
Entity: "Blob Upload",
|
Entity: "Blob Upload",
|
||||||
Description: "Interact with blob uploads. Clients should never assemble URLs for this endpoint and should only take it through the `Location` header on related API requests. The `Location` header and its parameters should be preserved by clients, using the latest value returned via upload related API calls.",
|
Description: "Interact with blob uploads. Clients should never assemble URLs for this endpoint and should only take it through the `Location` header on related API requests. The `Location` header and its parameters should be preserved by clients, using the latest value returned via upload related API calls.",
|
||||||
Methods: []MethodDescriptor{
|
Methods: []MethodDescriptor{
|
||||||
|
|
|
@ -170,6 +170,14 @@ func TestRouter(t *testing.T) {
|
||||||
"name": "foo/bar/manifests",
|
"name": "foo/bar/manifests",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
RouteName: RouteNameManifest,
|
||||||
|
RequestURI: "/v2/locahost:8080/foo/bar/baz/manifests/tag",
|
||||||
|
Vars: map[string]string{
|
||||||
|
"name": "locahost:8080/foo/bar/baz",
|
||||||
|
"reference": "tag",
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
checkTestRouter(t, testCases, "", true)
|
checkTestRouter(t, testCases, "", true)
|
||||||
|
|
|
@ -97,9 +97,9 @@ func (r *registry) Repositories(ctx context.Context, entries []string, last stri
|
||||||
return numFilled, returnErr
|
return numFilled, returnErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRepository creates a new Repository for the given canonical repository name and base URL.
|
// NewRepository creates a new Repository for the given repository name and base URL.
|
||||||
func NewRepository(ctx context.Context, canonicalName, baseURL string, transport http.RoundTripper) (distribution.Repository, error) {
|
func NewRepository(ctx context.Context, name, baseURL string, transport http.RoundTripper) (distribution.Repository, error) {
|
||||||
if _, err := reference.NewRepository(canonicalName); err != nil {
|
if _, err := reference.ParseNamed(name); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ func NewRepository(ctx context.Context, canonicalName, baseURL string, transport
|
||||||
return &repository{
|
return &repository{
|
||||||
client: client,
|
client: client,
|
||||||
ub: ub,
|
ub: ub,
|
||||||
name: canonicalName,
|
name: name,
|
||||||
context: ctx,
|
context: ctx,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
8
docs/storage/cache/memory/memory.go
vendored
8
docs/storage/cache/memory/memory.go
vendored
|
@ -25,8 +25,8 @@ func NewInMemoryBlobDescriptorCacheProvider() cache.BlobDescriptorCacheProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (imbdcp *inMemoryBlobDescriptorCacheProvider) RepositoryScoped(canonicalName string) (distribution.BlobDescriptorService, error) {
|
func (imbdcp *inMemoryBlobDescriptorCacheProvider) RepositoryScoped(repo string) (distribution.BlobDescriptorService, error) {
|
||||||
if _, err := reference.NewRepository(canonicalName); err != nil {
|
if _, err := reference.ParseNamed(repo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,9 +34,9 @@ func (imbdcp *inMemoryBlobDescriptorCacheProvider) RepositoryScoped(canonicalNam
|
||||||
defer imbdcp.mu.RUnlock()
|
defer imbdcp.mu.RUnlock()
|
||||||
|
|
||||||
return &repositoryScopedInMemoryBlobDescriptorCache{
|
return &repositoryScopedInMemoryBlobDescriptorCache{
|
||||||
repo: canonicalName,
|
repo: repo,
|
||||||
parent: imbdcp,
|
parent: imbdcp,
|
||||||
repository: imbdcp.repositories[canonicalName],
|
repository: imbdcp.repositories[repo],
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
docs/storage/cache/redis/redis.go
vendored
6
docs/storage/cache/redis/redis.go
vendored
|
@ -40,13 +40,13 @@ func NewRedisBlobDescriptorCacheProvider(pool *redis.Pool) cache.BlobDescriptorC
|
||||||
}
|
}
|
||||||
|
|
||||||
// RepositoryScoped returns the scoped cache.
|
// RepositoryScoped returns the scoped cache.
|
||||||
func (rbds *redisBlobDescriptorService) RepositoryScoped(canonicalName string) (distribution.BlobDescriptorService, error) {
|
func (rbds *redisBlobDescriptorService) RepositoryScoped(repo string) (distribution.BlobDescriptorService, error) {
|
||||||
if _, err := reference.NewRepository(canonicalName); err != nil {
|
if _, err := reference.ParseNamed(repo); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &repositoryScopedRedisBlobDescriptorService{
|
return &repositoryScopedRedisBlobDescriptorService{
|
||||||
repo: canonicalName,
|
repo: repo,
|
||||||
upstream: rbds,
|
upstream: rbds,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,7 +108,7 @@ func (reg *registry) Scope() distribution.Scope {
|
||||||
// Instances should not be shared between goroutines but are cheap to
|
// Instances should not be shared between goroutines but are cheap to
|
||||||
// allocate. In general, they should be request scoped.
|
// allocate. In general, they should be request scoped.
|
||||||
func (reg *registry) Repository(ctx context.Context, canonicalName string) (distribution.Repository, error) {
|
func (reg *registry) Repository(ctx context.Context, canonicalName string) (distribution.Repository, error) {
|
||||||
if _, err := reference.NewRepository(canonicalName); err != nil {
|
if _, err := reference.ParseNamed(canonicalName); err != nil {
|
||||||
return nil, distribution.ErrRepositoryNameInvalid{
|
return nil, distribution.ErrRepositoryNameInvalid{
|
||||||
Name: canonicalName,
|
Name: canonicalName,
|
||||||
Reason: err,
|
Reason: err,
|
||||||
|
|
Loading…
Reference in a new issue