|
@@ -5,7 +5,7 @@ import (
|
|
"net/http"
|
|
"net/http"
|
|
"runtime"
|
|
"runtime"
|
|
|
|
|
|
- "github.com/docker/docker/pkg/version"
|
|
|
|
|
|
+ "github.com/docker/engine-api/types/versions"
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/net/context"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -20,14 +20,14 @@ func (badRequestError) HTTPErrorStatusCode() int {
|
|
// VersionMiddleware is a middleware that
|
|
// VersionMiddleware is a middleware that
|
|
// validates the client and server versions.
|
|
// validates the client and server versions.
|
|
type VersionMiddleware struct {
|
|
type VersionMiddleware struct {
|
|
- serverVersion version.Version
|
|
|
|
- defaultVersion version.Version
|
|
|
|
- minVersion version.Version
|
|
|
|
|
|
+ serverVersion string
|
|
|
|
+ defaultVersion string
|
|
|
|
+ minVersion string
|
|
}
|
|
}
|
|
|
|
|
|
// NewVersionMiddleware creates a new VersionMiddleware
|
|
// NewVersionMiddleware creates a new VersionMiddleware
|
|
// with the default versions.
|
|
// with the default versions.
|
|
-func NewVersionMiddleware(s, d, m version.Version) VersionMiddleware {
|
|
|
|
|
|
+func NewVersionMiddleware(s, d, m string) VersionMiddleware {
|
|
return VersionMiddleware{
|
|
return VersionMiddleware{
|
|
serverVersion: s,
|
|
serverVersion: s,
|
|
defaultVersion: d,
|
|
defaultVersion: d,
|
|
@@ -38,15 +38,15 @@ func NewVersionMiddleware(s, d, m version.Version) VersionMiddleware {
|
|
// WrapHandler returns a new handler function wrapping the previous one in the request chain.
|
|
// WrapHandler returns a new handler function wrapping the previous one in the request chain.
|
|
func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error) func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
|
- apiVersion := version.Version(vars["version"])
|
|
|
|
|
|
+ apiVersion := vars["version"]
|
|
if apiVersion == "" {
|
|
if apiVersion == "" {
|
|
apiVersion = v.defaultVersion
|
|
apiVersion = v.defaultVersion
|
|
}
|
|
}
|
|
|
|
|
|
- if apiVersion.GreaterThan(v.defaultVersion) {
|
|
|
|
|
|
+ if versions.GreaterThan(apiVersion, v.defaultVersion) {
|
|
return badRequestError{fmt.Errorf("client is newer than server (client API version: %s, server API version: %s)", apiVersion, v.defaultVersion)}
|
|
return badRequestError{fmt.Errorf("client is newer than server (client API version: %s, server API version: %s)", apiVersion, v.defaultVersion)}
|
|
}
|
|
}
|
|
- if apiVersion.LessThan(v.minVersion) {
|
|
|
|
|
|
+ if versions.LessThan(apiVersion, v.minVersion) {
|
|
return badRequestError{fmt.Errorf("client version %s is too old. Minimum supported API version is %s, please upgrade your client to a newer version", apiVersion, v.minVersion)}
|
|
return badRequestError{fmt.Errorf("client version %s is too old. Minimum supported API version is %s, please upgrade your client to a newer version", apiVersion, v.minVersion)}
|
|
}
|
|
}
|
|
|
|
|