summaryrefslogtreecommitdiff
path: root/api/server
diff options
context:
space:
mode:
authorSebastiaan van Stijn <github@gone.nl>2021-08-26 21:08:38 +0200
committerSebastiaan van Stijn <github@gone.nl>2022-07-29 23:04:34 +0200
commit857cb260c79a4c43fa0705ac4f117b85bcc9dfc5 (patch)
treea2f3788284b1a822ed37567ca475a6f051de1d36 /api/server
parent6e213899177faac5c4bf9bdc68ac2899fb0916e1 (diff)
downloaddocker-857cb260c79a4c43fa0705ac4f117b85bcc9dfc5.tar.gz
api: add const for 'X-Registry-Auth'
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Diffstat (limited to 'api/server')
-rw-r--r--api/server/middleware/cors.go3
-rw-r--r--api/server/router/distribution/distribution_routes.go6
-rw-r--r--api/server/router/image/image_routes.go7
-rw-r--r--api/server/router/plugin/plugin_routes.go2
-rw-r--r--api/server/router/swarm/cluster_routes.go5
5 files changed, 13 insertions, 10 deletions
diff --git a/api/server/middleware/cors.go b/api/server/middleware/cors.go
index 54374690e6..79bed14564 100644
--- a/api/server/middleware/cors.go
+++ b/api/server/middleware/cors.go
@@ -4,6 +4,7 @@ import (
"context"
"net/http"
+ "github.com/docker/docker/api/types/registry"
"github.com/sirupsen/logrus"
)
@@ -30,7 +31,7 @@ func (c CORSMiddleware) WrapHandler(handler func(ctx context.Context, w http.Res
logrus.Debugf("CORS header is enabled and set to: %s", corsHeaders)
w.Header().Add("Access-Control-Allow-Origin", corsHeaders)
- w.Header().Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, X-Registry-Auth")
+ w.Header().Add("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, "+registry.AuthHeader)
w.Header().Add("Access-Control-Allow-Methods", "HEAD, GET, POST, DELETE, PUT, OPTIONS")
return handler(ctx, w, r, vars)
}
diff --git a/api/server/router/distribution/distribution_routes.go b/api/server/router/distribution/distribution_routes.go
index 86b93d3c62..48107d1456 100644
--- a/api/server/router/distribution/distribution_routes.go
+++ b/api/server/router/distribution/distribution_routes.go
@@ -13,7 +13,7 @@ import (
"github.com/docker/distribution/reference"
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
- registrytypes "github.com/docker/docker/api/types/registry"
+ "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/errdefs"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
@@ -28,8 +28,8 @@ func (s *distributionRouter) getDistributionInfo(ctx context.Context, w http.Res
var (
config = &types.AuthConfig{}
- authEncoded = r.Header.Get("X-Registry-Auth")
- distributionInspect registrytypes.DistributionInspect
+ authEncoded = r.Header.Get(registry.AuthHeader)
+ distributionInspect registry.DistributionInspect
)
if authEncoded != "" {
diff --git a/api/server/router/image/image_routes.go b/api/server/router/image/image_routes.go
index b186e61ade..1184102cd8 100644
--- a/api/server/router/image/image_routes.go
+++ b/api/server/router/image/image_routes.go
@@ -14,6 +14,7 @@ import (
"github.com/docker/docker/api/server/httputils"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
+ "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/errdefs"
"github.com/docker/docker/image"
@@ -63,7 +64,7 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite
}
}
- authEncoded := r.Header.Get("X-Registry-Auth")
+ authEncoded := r.Header.Get(registry.AuthHeader)
authConfig := &types.AuthConfig{}
if authEncoded != "" {
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
@@ -100,7 +101,7 @@ func (s *imageRouter) postImagesPush(ctx context.Context, w http.ResponseWriter,
}
authConfig := &types.AuthConfig{}
- authEncoded := r.Header.Get("X-Registry-Auth")
+ authEncoded := r.Header.Get(registry.AuthHeader)
if authEncoded != "" {
// the new format is to handle the authConfig as a header
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
@@ -360,7 +361,7 @@ func (s *imageRouter) getImagesSearch(ctx context.Context, w http.ResponseWriter
}
var (
config *types.AuthConfig
- authEncoded = r.Header.Get("X-Registry-Auth")
+ authEncoded = r.Header.Get(registry.AuthHeader)
headers = map[string][]string{}
)
diff --git a/api/server/router/plugin/plugin_routes.go b/api/server/router/plugin/plugin_routes.go
index c82996679d..175a0f7537 100644
--- a/api/server/router/plugin/plugin_routes.go
+++ b/api/server/router/plugin/plugin_routes.go
@@ -27,7 +27,7 @@ func parseHeaders(headers http.Header) (map[string][]string, *types.AuthConfig)
}
// Get X-Registry-Auth
- authEncoded := headers.Get("X-Registry-Auth")
+ authEncoded := headers.Get(registry.AuthHeader)
authConfig := &types.AuthConfig{}
if authEncoded != "" {
authJSON := base64.NewDecoder(base64.URLEncoding, strings.NewReader(authEncoded))
diff --git a/api/server/router/swarm/cluster_routes.go b/api/server/router/swarm/cluster_routes.go
index 05c10082a1..293e4f1421 100644
--- a/api/server/router/swarm/cluster_routes.go
+++ b/api/server/router/swarm/cluster_routes.go
@@ -10,6 +10,7 @@ import (
basictypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/backend"
"github.com/docker/docker/api/types/filters"
+ "github.com/docker/docker/api/types/registry"
types "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/errdefs"
@@ -207,7 +208,7 @@ func (sr *swarmRouter) createService(ctx context.Context, w http.ResponseWriter,
}
// Get returns "" if the header does not exist
- encodedAuth := r.Header.Get("X-Registry-Auth")
+ encodedAuth := r.Header.Get(registry.AuthHeader)
queryRegistry := false
if v := httputils.VersionFromContext(ctx); v != "" {
if versions.LessThan(v, "1.30") {
@@ -240,7 +241,7 @@ func (sr *swarmRouter) updateService(ctx context.Context, w http.ResponseWriter,
var flags basictypes.ServiceUpdateOptions
// Get returns "" if the header does not exist
- flags.EncodedRegistryAuth = r.Header.Get("X-Registry-Auth")
+ flags.EncodedRegistryAuth = r.Header.Get(registry.AuthHeader)
flags.RegistryAuthFrom = r.URL.Query().Get("registryAuthFrom")
flags.Rollback = r.URL.Query().Get("rollback")
queryRegistry := false