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
|
|
|
|
2015-12-15 22:35:23 +00:00
|
|
|
"github.com/docker/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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-12 05:57:14 +00:00
|
|
|
// NewURLBuilderFromString workes identically to NewURLBuilder except it takes
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2017-03-20 23:13:33 +00:00
|
|
|
// Handle fowarded headers
|
|
|
|
// 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.
|
|
|
|
hosts := strings.SplitN(forwardedHost, ",", 2)
|
|
|
|
host = strings.TrimSpace(hosts[0])
|
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.
|
2015-12-15 22:35:23 +00:00
|
|
|
func (ub *URLBuilder) BuildTagsURL(name reference.Named) (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
|
|
|
|
}
|
|
|
|
|
|
|
|
return tagsURL.String(), nil
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|