Merge pull request #1381 from BrianBland/s3CustomUAString
Adds custom registry User-Agent header to s3 HTTP requests
This commit is contained in:
commit
6417c05a27
4 changed files with 58 additions and 29 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
|
@ -31,6 +32,7 @@ import (
|
|||
storagedriver "github.com/docker/distribution/registry/storage/driver"
|
||||
"github.com/docker/distribution/registry/storage/driver/factory"
|
||||
storagemiddleware "github.com/docker/distribution/registry/storage/driver/middleware"
|
||||
"github.com/docker/distribution/version"
|
||||
"github.com/docker/libtrust"
|
||||
"github.com/garyburd/redigo/redis"
|
||||
"github.com/gorilla/mux"
|
||||
|
@ -84,12 +86,12 @@ type App struct {
|
|||
// NewApp takes a configuration and returns a configured app, ready to serve
|
||||
// requests. The app only implements ServeHTTP and can be wrapped in other
|
||||
// handlers accordingly.
|
||||
func NewApp(ctx context.Context, configuration *configuration.Configuration) *App {
|
||||
func NewApp(ctx context.Context, config *configuration.Configuration) *App {
|
||||
app := &App{
|
||||
Config: configuration,
|
||||
Config: config,
|
||||
Context: ctx,
|
||||
router: v2.RouterWithPrefix(configuration.HTTP.Prefix),
|
||||
isCache: configuration.Proxy.RemoteURL != "",
|
||||
router: v2.RouterWithPrefix(config.HTTP.Prefix),
|
||||
isCache: config.Proxy.RemoteURL != "",
|
||||
}
|
||||
|
||||
// Register the handler dispatchers.
|
||||
|
@ -103,8 +105,15 @@ func NewApp(ctx context.Context, configuration *configuration.Configuration) *Ap
|
|||
app.register(v2.RouteNameBlobUpload, blobUploadDispatcher)
|
||||
app.register(v2.RouteNameBlobUploadChunk, blobUploadDispatcher)
|
||||
|
||||
// override the storage driver's UA string for registry outbound HTTP requests
|
||||
storageParams := config.Storage.Parameters()
|
||||
if storageParams == nil {
|
||||
storageParams = make(configuration.Parameters)
|
||||
}
|
||||
storageParams["useragent"] = fmt.Sprintf("docker-distribution/%s %s", version.Version, runtime.Version())
|
||||
|
||||
var err error
|
||||
app.driver, err = factory.Create(configuration.Storage.Type(), configuration.Storage.Parameters())
|
||||
app.driver, err = factory.Create(config.Storage.Type(), storageParams)
|
||||
if err != nil {
|
||||
// TODO(stevvooe): Move the creation of a service into a protected
|
||||
// method, where this is created lazily. Its status can be queried via
|
||||
|
@ -113,7 +122,7 @@ func NewApp(ctx context.Context, configuration *configuration.Configuration) *Ap
|
|||
}
|
||||
|
||||
purgeConfig := uploadPurgeDefaultConfig()
|
||||
if mc, ok := configuration.Storage["maintenance"]; ok {
|
||||
if mc, ok := config.Storage["maintenance"]; ok {
|
||||
if v, ok := mc["uploadpurging"]; ok {
|
||||
purgeConfig, ok = v.(map[interface{}]interface{})
|
||||
if !ok {
|
||||
|
@ -136,15 +145,15 @@ func NewApp(ctx context.Context, configuration *configuration.Configuration) *Ap
|
|||
|
||||
startUploadPurger(app, app.driver, ctxu.GetLogger(app), purgeConfig)
|
||||
|
||||
app.driver, err = applyStorageMiddleware(app.driver, configuration.Middleware["storage"])
|
||||
app.driver, err = applyStorageMiddleware(app.driver, config.Middleware["storage"])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
app.configureSecret(configuration)
|
||||
app.configureEvents(configuration)
|
||||
app.configureRedis(configuration)
|
||||
app.configureLogHook(configuration)
|
||||
app.configureSecret(config)
|
||||
app.configureEvents(config)
|
||||
app.configureRedis(config)
|
||||
app.configureLogHook(config)
|
||||
|
||||
// Generate an ephemeral key to be used for signing converted manifests
|
||||
// for clients that don't support schema2.
|
||||
|
@ -153,8 +162,8 @@ func NewApp(ctx context.Context, configuration *configuration.Configuration) *Ap
|
|||
panic(err)
|
||||
}
|
||||
|
||||
if configuration.HTTP.Host != "" {
|
||||
u, err := url.Parse(configuration.HTTP.Host)
|
||||
if config.HTTP.Host != "" {
|
||||
u, err := url.Parse(config.HTTP.Host)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf(`could not parse http "host" parameter: %v`, err))
|
||||
}
|
||||
|
@ -168,7 +177,7 @@ func NewApp(ctx context.Context, configuration *configuration.Configuration) *Ap
|
|||
}
|
||||
|
||||
// configure deletion
|
||||
if d, ok := configuration.Storage["delete"]; ok {
|
||||
if d, ok := config.Storage["delete"]; ok {
|
||||
e, ok := d["enabled"]
|
||||
if ok {
|
||||
if deleteEnabled, ok := e.(bool); ok && deleteEnabled {
|
||||
|
@ -179,7 +188,7 @@ func NewApp(ctx context.Context, configuration *configuration.Configuration) *Ap
|
|||
|
||||
// configure redirects
|
||||
var redirectDisabled bool
|
||||
if redirectConfig, ok := configuration.Storage["redirect"]; ok {
|
||||
if redirectConfig, ok := config.Storage["redirect"]; ok {
|
||||
v := redirectConfig["disable"]
|
||||
switch v := v.(type) {
|
||||
case bool:
|
||||
|
@ -195,7 +204,7 @@ func NewApp(ctx context.Context, configuration *configuration.Configuration) *Ap
|
|||
}
|
||||
|
||||
// configure storage caches
|
||||
if cc, ok := configuration.Storage["cache"]; ok {
|
||||
if cc, ok := config.Storage["cache"]; ok {
|
||||
v, ok := cc["blobdescriptor"]
|
||||
if !ok {
|
||||
// Backwards compatible: "layerinfo" == "blobdescriptor"
|
||||
|
@ -224,7 +233,7 @@ func NewApp(ctx context.Context, configuration *configuration.Configuration) *Ap
|
|||
ctxu.GetLogger(app).Infof("using inmemory blob descriptor cache")
|
||||
default:
|
||||
if v != "" {
|
||||
ctxu.GetLogger(app).Warnf("unknown cache type %q, caching disabled", configuration.Storage["cache"])
|
||||
ctxu.GetLogger(app).Warnf("unknown cache type %q, caching disabled", config.Storage["cache"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -237,15 +246,15 @@ func NewApp(ctx context.Context, configuration *configuration.Configuration) *Ap
|
|||
}
|
||||
}
|
||||
|
||||
app.registry, err = applyRegistryMiddleware(app.Context, app.registry, configuration.Middleware["registry"])
|
||||
app.registry, err = applyRegistryMiddleware(app.Context, app.registry, config.Middleware["registry"])
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
authType := configuration.Auth.Type()
|
||||
authType := config.Auth.Type()
|
||||
|
||||
if authType != "" {
|
||||
accessController, err := auth.GetAccessController(configuration.Auth.Type(), configuration.Auth.Parameters())
|
||||
accessController, err := auth.GetAccessController(config.Auth.Type(), config.Auth.Parameters())
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("unable to configure authorization (%s): %v", authType, err))
|
||||
}
|
||||
|
@ -254,13 +263,13 @@ func NewApp(ctx context.Context, configuration *configuration.Configuration) *Ap
|
|||
}
|
||||
|
||||
// configure as a pull through cache
|
||||
if configuration.Proxy.RemoteURL != "" {
|
||||
app.registry, err = proxy.NewRegistryPullThroughCache(ctx, app.registry, app.driver, configuration.Proxy)
|
||||
if config.Proxy.RemoteURL != "" {
|
||||
app.registry, err = proxy.NewRegistryPullThroughCache(ctx, app.registry, app.driver, config.Proxy)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
app.isCache = true
|
||||
ctxu.GetLogger(app).Info("Registry configured as a proxy cache to ", configuration.Proxy.RemoteURL)
|
||||
ctxu.GetLogger(app).Info("Registry configured as a proxy cache to ", config.Proxy.RemoteURL)
|
||||
}
|
||||
|
||||
return app
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue