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 (
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
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
|
|
|
|
2014-12-24 01:01:38 +01:00
|
|
|
"github.com/docker/distribution/digest"
|
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 {
|
|
|
|
root *url.URL // url root (ie http://localhost/)
|
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
|
|
|
router *mux.Router
|
|
|
|
}
|
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
// NewURLBuilder creates a URLBuilder with provided root url object.
|
|
|
|
func NewURLBuilder(root *url.URL) *URLBuilder {
|
|
|
|
return &URLBuilder{
|
|
|
|
root: root,
|
|
|
|
router: Router(),
|
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.
|
|
|
|
func NewURLBuilderFromString(root string) (*URLBuilder, error) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
return NewURLBuilder(u), 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.
|
|
|
|
func NewURLBuilderFromRequest(r *http.Request) *URLBuilder {
|
2015-01-31 20:43:06 +01:00
|
|
|
var scheme string
|
|
|
|
|
|
|
|
forwardedProto := r.Header.Get("X-Forwarded-Proto")
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case len(forwardedProto) > 0:
|
|
|
|
scheme = forwardedProto
|
|
|
|
case r.TLS != nil:
|
|
|
|
scheme = "https"
|
|
|
|
case len(r.URL.Scheme) > 0:
|
|
|
|
scheme = r.URL.Scheme
|
|
|
|
default:
|
|
|
|
scheme = "http"
|
|
|
|
}
|
|
|
|
|
|
|
|
host := r.Host
|
|
|
|
forwardedHost := r.Header.Get("X-Forwarded-Host")
|
|
|
|
if 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])
|
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]
|
|
|
|
}
|
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
return NewURLBuilder(u)
|
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.
|
|
|
|
func (ub *URLBuilder) BuildTagsURL(name string) (string, error) {
|
|
|
|
route := ub.cloneRoute(RouteNameTags)
|
2014-12-10 00:36:26 +01:00
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
tagsURL, err := route.URL("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.
|
|
|
|
func (ub *URLBuilder) BuildManifestURL(name, reference string) (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-02-26 03:04:28 +01:00
|
|
|
manifestURL, err := route.URL("name", name, "reference", 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
|
|
|
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.
|
2014-12-12 06:57:14 +01:00
|
|
|
func (ub *URLBuilder) BuildBlobURL(name string, dgst digest.Digest) (string, error) {
|
|
|
|
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
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
layerURL, err := route.URL("name", name, "digest", dgst.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.
|
2014-12-12 22:55:14 +01:00
|
|
|
func (ub *URLBuilder) BuildBlobUploadURL(name string, 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
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
uploadURL, err := route.URL("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.
|
|
|
|
func (ub *URLBuilder) BuildBlobUploadChunkURL(name, uuid string, values ...url.Values) (string, error) {
|
|
|
|
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
|
|
|
|
2014-12-12 06:57:14 +01:00
|
|
|
uploadURL, err := route.URL("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
|
|
|
|
|
|
|
|
return clonedRoute{Route: route, root: root}
|
|
|
|
}
|
|
|
|
|
|
|
|
type clonedRoute struct {
|
|
|
|
*mux.Route
|
|
|
|
root *url.URL
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
2015-02-24 23:59:01 +01:00
|
|
|
if routeURL.Scheme == "" && routeURL.User == nil && routeURL.Host == "" {
|
|
|
|
routeURL.Path = routeURL.Path[1:]
|
|
|
|
}
|
|
|
|
|
2015-01-31 20:43:06 +01:00
|
|
|
return cr.root.ResolveReference(routeURL), 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()
|
|
|
|
}
|