2014-12-12 07:10:18 +01: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 21:16:58 +01:00
|
|
|
|
|
|
|
import (
|
2016-10-13 17:59:49 +02:00
|
|
|
"net"
|
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 21:16:58 +01:00
|
|
|
"net/http"
|
|
|
|
"net/url"
|
2016-10-13 17:59:49 +02:00
|
|
|
"strconv"
|
2015-02-24 23:59:01 +01: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 21:16:58 +01:00
|
|
|
|
2015-12-15 23:35:23 +01: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 21:16:58 +01:00
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
2014-12-12 06:57:14 +01: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 02:49:23 +01: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 21:16:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
// NewURLBuilder creates a URLBuilder with provided root url object.
|
2016-02-23 02:49:23 +01:00
|
|
|
func NewURLBuilder(root *url.URL, relative bool) *URLBuilder {
|
2014-12-12 06:57:14 +01:00
|
|
|
return &URLBuilder{
|
2016-02-23 02:49:23 +01: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 21:16:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-12 06:57:14 +01: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 02:49:23 +01:00
|
|
|
func NewURLBuilderFromString(root string, relative bool) (*URLBuilder, error) {
|
2014-12-12 06:57:14 +01: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 21:16:58 +01:00
|
|
|
}
|
|
|
|
|
2016-02-23 02:49:23 +01: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 21:16:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
// NewURLBuilderFromRequest uses information from an *http.Request to
|
|
|
|
// construct the root url.
|
2016-02-23 02:49:23 +01:00
|
|
|
func NewURLBuilderFromRequest(r *http.Request, relative bool) *URLBuilder {
|
2015-01-31 20:43:06 +01:00
|
|
|
var scheme string
|
|
|
|
|
|
|
|
forwardedProto := r.Header.Get("X-Forwarded-Proto")
|
2016-10-13 17:59:49 +02:00
|
|
|
// TODO: log the error
|
|
|
|
forwardedHeader, _, _ := parseForwardedHeader(r.Header.Get("Forwarded"))
|
2015-01-31 20:43:06 +01:00
|
|
|
|
|
|
|
switch {
|
|
|
|
case len(forwardedProto) > 0:
|
|
|
|
scheme = forwardedProto
|
2016-10-13 17:59:49 +02:00
|
|
|
case len(forwardedHeader["proto"]) > 0:
|
|
|
|
scheme = forwardedHeader["proto"]
|
2015-01-31 20:43:06 +01:00
|
|
|
case r.TLS != nil:
|
|
|
|
scheme = "https"
|
|
|
|
case len(r.URL.Scheme) > 0:
|
|
|
|
scheme = r.URL.Scheme
|
|
|
|
default:
|
|
|
|
scheme = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
host := r.Host
|
2016-10-13 17:59:49 +02:00
|
|
|
|
|
|
|
if forwardedHost := r.Header.Get("X-Forwarded-Host"); len(forwardedHost) > 0 {
|
2015-04-24 23:04:48 +02:00
|
|
|
// 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 17:59:49 +02:00
|
|
|
} else if addr, exists := forwardedHeader["for"]; exists {
|
|
|
|
host = addr
|
|
|
|
} else if h, exists := forwardedHeader["host"]; exists {
|
|
|
|
host = h
|
|
|
|
}
|
|
|
|
|
|
|
|
portLessHost, port := host, ""
|
|
|
|
if !isIPv6Address(portLessHost) {
|
|
|
|
// with go 1.6, this would treat the last part of IPv6 address as a port
|
|
|
|
portLessHost, port, _ = net.SplitHostPort(host)
|
|
|
|
}
|
|
|
|
if forwardedPort := r.Header.Get("X-Forwarded-Port"); len(port) == 0 && len(forwardedPort) > 0 {
|
|
|
|
ports := strings.SplitN(forwardedPort, ",", 2)
|
|
|
|
forwardedPort = strings.TrimSpace(ports[0])
|
|
|
|
if _, err := strconv.ParseInt(forwardedPort, 10, 32); err == nil {
|
|
|
|
port = forwardedPort
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(portLessHost) > 0 {
|
|
|
|
host = portLessHost
|
|
|
|
}
|
|
|
|
if len(port) > 0 {
|
|
|
|
// remove enclosing brackets of ipv6 address otherwise they will be duplicated
|
|
|
|
if len(host) > 1 && host[0] == '[' && host[len(host)-1] == ']' {
|
|
|
|
host = host[1 : len(host)-1]
|
|
|
|
}
|
|
|
|
// JoinHostPort properly encloses ipv6 addresses in square brackets
|
|
|
|
host = net.JoinHostPort(host, port)
|
|
|
|
} else if isIPv6Address(host) && host[0] != '[' {
|
|
|
|
// ipv6 needs to be enclosed in square brackets in urls
|
|
|
|
host = "[" + host + "]"
|
2015-01-31 20:43:06 +01:00
|
|
|
}
|
|
|
|
|
2015-02-24 23:59:01 +01:00
|
|
|
basePath := routeDescriptorsMap[RouteNameBase].Path
|
|
|
|
|
|
|
|
requestPath := r.URL.Path
|
|
|
|
index := strings.Index(requestPath, basePath)
|
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
u := &url.URL{
|
2015-01-31 20:43:06 +01: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 21:16:58 +01:00
|
|
|
}
|
|
|
|
|
2015-02-24 23:59:01 +01: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 02:49:23 +01: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 21:16:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-12 06:57:14 +01: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 07:33:36 +01:00
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
baseURL, err := route.URL()
|
2014-12-11 07:33:36 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return baseURL.String(), nil
|
|
|
|
}
|
|
|
|
|
2015-07-13 22:08:13 +02: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 06:57:14 +01:00
|
|
|
// BuildTagsURL constructs a url to list the tags in the named repository.
|
2015-12-15 23:35:23 +01:00
|
|
|
func (ub *URLBuilder) BuildTagsURL(name reference.Named) (string, error) {
|
2014-12-12 06:57:14 +01:00
|
|
|
route := ub.cloneRoute(RouteNameTags)
|
2014-12-10 00:36:26 +01:00
|
|
|
|
2015-12-15 23:35:23 +01:00
|
|
|
tagsURL, err := route.URL("name", name.Name())
|
2014-12-10 00:36:26 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return tagsURL.String(), nil
|
|
|
|
}
|
|
|
|
|
2015-02-26 03:04:28 +01: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 01:43:13 +01:00
|
|
|
func (ub *URLBuilder) BuildManifestURL(ref reference.Named) (string, error) {
|
2014-12-12 06:57:14 +01: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 21:16:58 +01:00
|
|
|
|
2015-12-16 01:43:13 +01:00
|
|
|
tagOrDigest := ""
|
|
|
|
switch v := ref.(type) {
|
|
|
|
case reference.Tagged:
|
|
|
|
tagOrDigest = v.Tag()
|
|
|
|
case reference.Digested:
|
|
|
|
tagOrDigest = v.Digest().String()
|
|
|
|
}
|
|
|
|
|
|
|
|
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 21:16:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return manifestURL.String(), nil
|
|
|
|
}
|
|
|
|
|
2014-12-12 07:02:17 +01:00
|
|
|
// BuildBlobURL constructs the url for the blob identified by name and dgst.
|
2015-12-16 01:43:13 +01:00
|
|
|
func (ub *URLBuilder) BuildBlobURL(ref reference.Canonical) (string, error) {
|
2014-12-12 06:57:14 +01: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 21:16:58 +01:00
|
|
|
|
2015-12-16 01:43:13 +01: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 21:16:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return layerURL.String(), nil
|
|
|
|
}
|
|
|
|
|
2014-12-12 07:02:17 +01:00
|
|
|
// BuildBlobUploadURL constructs a url to begin a blob upload in the
|
|
|
|
// repository identified by name.
|
2015-12-15 23:35:23 +01:00
|
|
|
func (ub *URLBuilder) BuildBlobUploadURL(name reference.Named, values ...url.Values) (string, error) {
|
2014-12-12 06:57:14 +01: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 21:16:58 +01:00
|
|
|
|
2015-12-15 23:35:23 +01: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 21:16:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
2014-12-12 22:55:14 +01: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 21:16:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-12 06:57:14 +01: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 23:35:23 +01:00
|
|
|
func (ub *URLBuilder) BuildBlobUploadChunkURL(name reference.Named, uuid string, values ...url.Values) (string, error) {
|
2014-12-12 06:57:14 +01: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 21:16:58 +01:00
|
|
|
|
2015-12-15 23:35:23 +01: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 21:16:58 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return appendValuesURL(uploadURL, values...).String(), nil
|
|
|
|
}
|
|
|
|
|
2014-12-12 06:57:14 +01: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 20:43:06 +01:00
|
|
|
func (ub *URLBuilder) cloneRoute(name string) clonedRoute {
|
2014-12-12 06:57:14 +01:00
|
|
|
route := new(mux.Route)
|
2015-01-31 20:43:06 +01:00
|
|
|
root := new(url.URL)
|
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
*route = *ub.router.GetRoute(name) // clone the route
|
2015-01-31 20:43:06 +01:00
|
|
|
*root = *ub.root
|
|
|
|
|
2016-02-23 02:49:23 +01:00
|
|
|
return clonedRoute{Route: route, root: root, relative: ub.relative}
|
2015-01-31 20:43:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type clonedRoute struct {
|
|
|
|
*mux.Route
|
2016-02-23 02:49:23 +01:00
|
|
|
root *url.URL
|
|
|
|
relative bool
|
2015-01-31 20:43:06 +01: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 06:57:14 +01:00
|
|
|
|
2016-02-23 02:49:23 +01:00
|
|
|
if cr.relative {
|
|
|
|
return routeURL, nil
|
|
|
|
}
|
|
|
|
|
2015-02-24 23:59:01 +01:00
|
|
|
if routeURL.Scheme == "" && routeURL.User == nil && routeURL.Host == "" {
|
|
|
|
routeURL.Path = routeURL.Path[1:]
|
|
|
|
}
|
|
|
|
|
2015-10-15 10:56:28 +02:00
|
|
|
url := cr.root.ResolveReference(routeURL)
|
|
|
|
url.Scheme = cr.root.Scheme
|
|
|
|
return url, nil
|
2014-12-12 06:57:14 +01: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 21:16:58 +01: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
|
|
|
|
}
|
|
|
|
|
|
|
|
// appendValues appends the parameters to the url. Panics if the string is not
|
|
|
|
// a url.
|
|
|
|
func appendValues(u string, values ...url.Values) string {
|
|
|
|
up, err := url.Parse(u)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
panic(err) // should never happen
|
|
|
|
}
|
|
|
|
|
|
|
|
return appendValuesURL(up, values...).String()
|
|
|
|
}
|
2016-10-13 17:59:49 +02:00
|
|
|
|
|
|
|
// isIPv6Address returns true if given string is a valid IPv6 address. No port is allowed. The address may be
|
|
|
|
// enclosed in square brackets.
|
|
|
|
func isIPv6Address(host string) bool {
|
|
|
|
if len(host) > 1 && host[0] == '[' && host[len(host)-1] == ']' {
|
|
|
|
host = host[1 : len(host)-1]
|
|
|
|
}
|
|
|
|
// The IPv6 scoped addressing zone identifier starts after the last percent sign.
|
|
|
|
if i := strings.LastIndexByte(host, '%'); i > 0 {
|
|
|
|
host = host[:i]
|
|
|
|
}
|
|
|
|
ip := net.ParseIP(host)
|
|
|
|
if ip == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if ip.To16() == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if ip.To4() == nil {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
// dot can be present in ipv4-mapped address, it needs to come after a colon though
|
|
|
|
i := strings.IndexAny(host, ":.")
|
|
|
|
return i >= 0 && host[i] == ':'
|
|
|
|
}
|