2014-12-12 06:10:18 +00:00
|
|
|
package v2
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
|
|
|
|
import (
|
2017-03-01 18:24:08 +00:00
|
|
|
"fmt"
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2015-02-24 22:59:01 +00:00
|
|
|
"strings"
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
|
2023-08-30 15:50:56 +00:00
|
|
|
"github.com/distribution/reference"
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
// URLBuilder creates registry API urls from a single base endpoint. It can be
|
|
|
|
// used to create urls for use in a registry client or server.
|
|
|
|
//
|
|
|
|
// All urls will be created from the given base, including the api version.
|
|
|
|
// For example, if a root of "/foo/" is provided, urls generated will be fall
|
|
|
|
// under "/foo/v2/...". Most application will only provide a schema, host and
|
|
|
|
// port, such as "https://localhost:5000/".
|
|
|
|
type URLBuilder struct {
|
2016-02-23 01:49:23 +00:00
|
|
|
root *url.URL // url root (ie http://localhost/)
|
|
|
|
router *mux.Router
|
|
|
|
relative bool
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
// NewURLBuilder creates a URLBuilder with provided root url object.
|
2016-02-23 01:49:23 +00:00
|
|
|
func NewURLBuilder(root *url.URL, relative bool) *URLBuilder {
|
2014-12-12 05:57:14 +00:00
|
|
|
return &URLBuilder{
|
2016-02-23 01:49:23 +00:00
|
|
|
root: root,
|
|
|
|
router: Router(),
|
|
|
|
relative: relative,
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-29 11:13:05 +00:00
|
|
|
// NewURLBuilderFromString works identically to NewURLBuilder except it takes
|
2014-12-12 05:57:14 +00:00
|
|
|
// a string argument for the root, returning an error if it is not a valid
|
|
|
|
// url.
|
2016-02-23 01:49:23 +00:00
|
|
|
func NewURLBuilderFromString(root string, relative bool) (*URLBuilder, error) {
|
2014-12-12 05:57:14 +00:00
|
|
|
u, err := url.Parse(root)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
return NewURLBuilder(u, relative), nil
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
// NewURLBuilderFromRequest uses information from an *http.Request to
|
|
|
|
// construct the root url.
|
2016-02-23 01:49:23 +00:00
|
|
|
func NewURLBuilderFromRequest(r *http.Request, relative bool) *URLBuilder {
|
2017-03-20 23:13:33 +00:00
|
|
|
var (
|
2015-01-31 19:43:06 +00:00
|
|
|
scheme = "http"
|
2017-03-20 23:13:33 +00:00
|
|
|
host = r.Host
|
|
|
|
)
|
2015-01-31 19:43:06 +00:00
|
|
|
|
2017-03-20 23:13:33 +00:00
|
|
|
if r.TLS != nil {
|
|
|
|
scheme = "https"
|
|
|
|
} else if len(r.URL.Scheme) > 0 {
|
|
|
|
scheme = r.URL.Scheme
|
2016-10-13 15:59:49 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 11:13:05 +00:00
|
|
|
// Handle forwarded headers
|
2017-03-20 23:13:33 +00:00
|
|
|
// Prefer "Forwarded" header as defined by rfc7239 if given
|
|
|
|
// see https://tools.ietf.org/html/rfc7239
|
|
|
|
if forwarded := r.Header.Get("Forwarded"); len(forwarded) > 0 {
|
|
|
|
forwardedHeader, _, err := parseForwardedHeader(forwarded)
|
|
|
|
if err == nil {
|
|
|
|
if fproto := forwardedHeader["proto"]; len(fproto) > 0 {
|
|
|
|
scheme = fproto
|
|
|
|
}
|
|
|
|
if fhost := forwardedHeader["host"]; len(fhost) > 0 {
|
|
|
|
host = fhost
|
|
|
|
}
|
2016-10-13 15:59:49 +00:00
|
|
|
}
|
2017-03-20 23:13:33 +00:00
|
|
|
} else {
|
|
|
|
if forwardedProto := r.Header.Get("X-Forwarded-Proto"); len(forwardedProto) > 0 {
|
|
|
|
scheme = forwardedProto
|
|
|
|
}
|
|
|
|
if forwardedHost := r.Header.Get("X-Forwarded-Host"); len(forwardedHost) > 0 {
|
|
|
|
// According to the Apache mod_proxy docs, X-Forwarded-Host can be a
|
|
|
|
// comma-separated list of hosts, to which each proxy appends the
|
|
|
|
// requested host. We want to grab the first from this comma-separated
|
|
|
|
// list.
|
replace strings.Split(N) for strings.Cut() or alternatives
Go 1.18 and up now provides a strings.Cut() which is better suited for
splitting key/value pairs (and similar constructs), and performs better:
```go
func BenchmarkSplit(b *testing.B) {
b.ReportAllocs()
data := []string{"12hello=world", "12hello=", "12=hello", "12hello"}
for i := 0; i < b.N; i++ {
for _, s := range data {
_ = strings.SplitN(s, "=", 2)[0]
}
}
}
func BenchmarkCut(b *testing.B) {
b.ReportAllocs()
data := []string{"12hello=world", "12hello=", "12=hello", "12hello"}
for i := 0; i < b.N; i++ {
for _, s := range data {
_, _, _ = strings.Cut(s, "=")
}
}
}
```
BenchmarkSplit
BenchmarkSplit-10 8244206 128.0 ns/op 128 B/op 4 allocs/op
BenchmarkCut
BenchmarkCut-10 54411998 21.80 ns/op 0 B/op 0 allocs/op
While looking at occurrences of `strings.Split()`, I also updated some for alternatives,
or added some constraints;
- for cases where an specific number of items is expected, I used `strings.SplitN()`
with a suitable limit. This prevents (theoretical) unlimited splits.
- in some cases it we were using `strings.Split()`, but _actually_ were trying to match
a prefix; for those I replaced the code to just match (and/or strip) the prefix.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-02 19:32:03 +00:00
|
|
|
host, _, _ = strings.Cut(forwardedHost, ",")
|
|
|
|
host = strings.TrimSpace(host)
|
2016-10-13 15:59:49 +00:00
|
|
|
}
|
2015-01-31 19:43:06 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 22:59:01 +00:00
|
|
|
basePath := routeDescriptorsMap[RouteNameBase].Path
|
|
|
|
|
|
|
|
requestPath := r.URL.Path
|
|
|
|
index := strings.Index(requestPath, basePath)
|
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
u := &url.URL{
|
2015-01-31 19:43:06 +00:00
|
|
|
Scheme: scheme,
|
|
|
|
Host: host,
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
|
2015-02-24 22:59:01 +00:00
|
|
|
if index > 0 {
|
|
|
|
// N.B. index+1 is important because we want to include the trailing /
|
|
|
|
u.Path = requestPath[0 : index+1]
|
|
|
|
}
|
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
return NewURLBuilder(u, relative)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
// BuildBaseURL constructs a base url for the API, typically just "/v2/".
|
|
|
|
func (ub *URLBuilder) BuildBaseURL() (string, error) {
|
|
|
|
route := ub.cloneRoute(RouteNameBase)
|
2014-12-11 06:33:36 +00:00
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
baseURL, err := route.URL()
|
2014-12-11 06:33:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return baseURL.String(), nil
|
|
|
|
}
|
|
|
|
|
2015-07-13 20:08:13 +00:00
|
|
|
// BuildCatalogURL constructs a url get a catalog of repositories
|
|
|
|
func (ub *URLBuilder) BuildCatalogURL(values ...url.Values) (string, error) {
|
|
|
|
route := ub.cloneRoute(RouteNameCatalog)
|
|
|
|
|
|
|
|
catalogURL, err := route.URL()
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return appendValuesURL(catalogURL, values...).String(), nil
|
|
|
|
}
|
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
// BuildTagsURL constructs a url to list the tags in the named repository.
|
2021-05-22 14:15:49 +00:00
|
|
|
func (ub *URLBuilder) BuildTagsURL(name reference.Named, values ...url.Values) (string, error) {
|
2014-12-12 05:57:14 +00:00
|
|
|
route := ub.cloneRoute(RouteNameTags)
|
2014-12-09 23:36:26 +00:00
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
tagsURL, err := route.URL("name", name.Name())
|
2014-12-09 23:36:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2021-05-22 14:15:49 +00:00
|
|
|
return appendValuesURL(tagsURL, values...).String(), nil
|
2014-12-09 23:36:26 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 02:04:28 +00:00
|
|
|
// BuildManifestURL constructs a url for the manifest identified by name and
|
|
|
|
// reference. The argument reference may be either a tag or digest.
|
2015-12-16 00:43:13 +00:00
|
|
|
func (ub *URLBuilder) BuildManifestURL(ref reference.Named) (string, error) {
|
2014-12-12 05:57:14 +00:00
|
|
|
route := ub.cloneRoute(RouteNameManifest)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
tagOrDigest := ""
|
|
|
|
switch v := ref.(type) {
|
|
|
|
case reference.Tagged:
|
|
|
|
tagOrDigest = v.Tag()
|
|
|
|
case reference.Digested:
|
|
|
|
tagOrDigest = v.Digest().String()
|
2017-03-01 18:24:08 +00:00
|
|
|
default:
|
|
|
|
return "", fmt.Errorf("reference must have a tag or digest")
|
2015-12-16 00:43:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
manifestURL, err := route.URL("name", ref.Name(), "reference", tagOrDigest)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return manifestURL.String(), nil
|
|
|
|
}
|
|
|
|
|
2014-12-12 06:02:17 +00:00
|
|
|
// BuildBlobURL constructs the url for the blob identified by name and dgst.
|
2015-12-16 00:43:13 +00:00
|
|
|
func (ub *URLBuilder) BuildBlobURL(ref reference.Canonical) (string, error) {
|
2014-12-12 05:57:14 +00:00
|
|
|
route := ub.cloneRoute(RouteNameBlob)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
|
2015-12-16 00:43:13 +00:00
|
|
|
layerURL, err := route.URL("name", ref.Name(), "digest", ref.Digest().String())
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return layerURL.String(), nil
|
|
|
|
}
|
|
|
|
|
2014-12-12 06:02:17 +00:00
|
|
|
// BuildBlobUploadURL constructs a url to begin a blob upload in the
|
|
|
|
// repository identified by name.
|
2015-12-15 22:35:23 +00:00
|
|
|
func (ub *URLBuilder) BuildBlobUploadURL(name reference.Named, values ...url.Values) (string, error) {
|
2014-12-12 05:57:14 +00:00
|
|
|
route := ub.cloneRoute(RouteNameBlobUpload)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
uploadURL, err := route.URL("name", name.Name())
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2014-12-12 21:55:14 +00:00
|
|
|
return appendValuesURL(uploadURL, values...).String(), nil
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
}
|
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
// BuildBlobUploadChunkURL constructs a url for the upload identified by uuid,
|
|
|
|
// including any url values. This should generally not be used by clients, as
|
|
|
|
// this url is provided by server implementations during the blob upload
|
|
|
|
// process.
|
2015-12-15 22:35:23 +00:00
|
|
|
func (ub *URLBuilder) BuildBlobUploadChunkURL(name reference.Named, uuid string, values ...url.Values) (string, error) {
|
2014-12-12 05:57:14 +00:00
|
|
|
route := ub.cloneRoute(RouteNameBlobUploadChunk)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
uploadURL, err := route.URL("name", name.Name(), "uuid", uuid)
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return appendValuesURL(uploadURL, values...).String(), nil
|
|
|
|
}
|
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
// clondedRoute returns a clone of the named route from the router. Routes
|
|
|
|
// must be cloned to avoid modifying them during url generation.
|
2015-01-31 19:43:06 +00:00
|
|
|
func (ub *URLBuilder) cloneRoute(name string) clonedRoute {
|
2014-12-12 05:57:14 +00:00
|
|
|
route := new(mux.Route)
|
2015-01-31 19:43:06 +00:00
|
|
|
root := new(url.URL)
|
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
*route = *ub.router.GetRoute(name) // clone the route
|
2015-01-31 19:43:06 +00:00
|
|
|
*root = *ub.root
|
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
return clonedRoute{Route: route, root: root, relative: ub.relative}
|
2015-01-31 19:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type clonedRoute struct {
|
|
|
|
*mux.Route
|
2016-02-23 01:49:23 +00:00
|
|
|
root *url.URL
|
|
|
|
relative bool
|
2015-01-31 19:43:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (cr clonedRoute) URL(pairs ...string) (*url.URL, error) {
|
|
|
|
routeURL, err := cr.Route.URL(pairs...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2014-12-12 05:57:14 +00:00
|
|
|
|
2016-02-23 01:49:23 +00:00
|
|
|
if cr.relative {
|
|
|
|
return routeURL, nil
|
|
|
|
}
|
|
|
|
|
2015-02-24 22:59:01 +00:00
|
|
|
if routeURL.Scheme == "" && routeURL.User == nil && routeURL.Host == "" {
|
|
|
|
routeURL.Path = routeURL.Path[1:]
|
|
|
|
}
|
|
|
|
|
2015-10-15 08:56:28 +00:00
|
|
|
url := cr.root.ResolveReference(routeURL)
|
|
|
|
url.Scheme = cr.root.Scheme
|
|
|
|
return url, nil
|
2014-12-12 05:57:14 +00:00
|
|
|
}
|
|
|
|
|
Initial implementation of Manifest HTTP API
Push, pull and delete of manifest files in the registry have been implemented
on top of the storage services. Basic workflows, including reporting of missing
manifests are tested, including various proposed response codes. Common testing
functionality has been collected into shared methods. A test suite may be
emerging but it might better to capture more edge cases (such as resumable
upload, range requests, etc.) before we commit to a full approach.
To support clearer test cases and simpler handler methods, an application aware
urlBuilder has been added. We may want to export the functionality for use in
the client, which could allow us to abstract away from gorilla/mux.
A few error codes have been added to fill in error conditions missing from the
proposal. Some use cases have identified some problems with the approach to
error reporting that requires more work to reconcile. To resolve this, the
mapping of Go errors into error types needs to pulled out of the handlers and
into the application. We also need to move to type-based errors, with rich
information, rather than value-based errors. ErrorHandlers will probably
replace the http.Handlers to make this work correctly.
Unrelated to the above, the "length" parameter has been migrated to "size" for
completing layer uploads. This change should have gone out before but these
diffs ending up being coupled with the parameter name change due to updates to
the layer unit tests.
2014-11-26 20:16:58 +00:00
|
|
|
// appendValuesURL appends the parameters to the url.
|
|
|
|
func appendValuesURL(u *url.URL, values ...url.Values) *url.URL {
|
|
|
|
merged := u.Query()
|
|
|
|
|
|
|
|
for _, v := range values {
|
|
|
|
for k, vv := range v {
|
|
|
|
merged[k] = append(merged[k], vv...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u.RawQuery = merged.Encode()
|
|
|
|
return u
|
|
|
|
}
|