context: remove definition of Context
Back in the before time, the best practices surrounding usage of Context weren't quite worked out. We defined our own type to make usage easier. As this packaged was used elsewhere, it make it more and more challenging to integrate with the forked `Context` type. Now that it is available in the standard library, we can just use that one directly. To make usage more consistent, we now use `dcontext` when referring to the distribution context package. Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
parent
7a8efe719e
commit
9c88801a12
90 changed files with 396 additions and 373 deletions
|
@ -1,6 +1,7 @@
|
|||
package registry
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
|
@ -14,7 +15,7 @@ import (
|
|||
logstash "github.com/bshuster-repo/logrus-logstash-hook"
|
||||
"github.com/bugsnag/bugsnag-go"
|
||||
"github.com/docker/distribution/configuration"
|
||||
"github.com/docker/distribution/context"
|
||||
dcontext "github.com/docker/distribution/context"
|
||||
"github.com/docker/distribution/health"
|
||||
"github.com/docker/distribution/registry/handlers"
|
||||
"github.com/docker/distribution/registry/listener"
|
||||
|
@ -34,7 +35,7 @@ var ServeCmd = &cobra.Command{
|
|||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
// setup context
|
||||
ctx := context.WithVersion(context.Background(), version.Version)
|
||||
ctx := dcontext.WithVersion(dcontext.Background(), version.Version)
|
||||
|
||||
config, err := resolveConfiguration(args)
|
||||
if err != nil {
|
||||
|
@ -81,7 +82,7 @@ func NewRegistry(ctx context.Context, config *configuration.Configuration) (*Reg
|
|||
|
||||
// inject a logger into the uuid library. warns us if there is a problem
|
||||
// with uuid generation under low entropy.
|
||||
uuid.Loggerf = context.GetLogger(ctx).Warnf
|
||||
uuid.Loggerf = dcontext.GetLogger(ctx).Warnf
|
||||
|
||||
app := handlers.NewApp(ctx, config)
|
||||
// TODO(aaronl): The global scope of the health checks means NewRegistry
|
||||
|
@ -170,7 +171,7 @@ func (registry *Registry) ListenAndServe() error {
|
|||
}
|
||||
|
||||
for _, subj := range pool.Subjects() {
|
||||
context.GetLogger(registry.app).Debugf("CA Subject: %s", string(subj))
|
||||
dcontext.GetLogger(registry.app).Debugf("CA Subject: %s", string(subj))
|
||||
}
|
||||
|
||||
tlsConf.ClientAuth = tls.RequireAndVerifyClientCert
|
||||
|
@ -178,9 +179,9 @@ func (registry *Registry) ListenAndServe() error {
|
|||
}
|
||||
|
||||
ln = tls.NewListener(ln, tlsConf)
|
||||
context.GetLogger(registry.app).Infof("listening on %v, tls", ln.Addr())
|
||||
dcontext.GetLogger(registry.app).Infof("listening on %v, tls", ln.Addr())
|
||||
} else {
|
||||
context.GetLogger(registry.app).Infof("listening on %v", ln.Addr())
|
||||
dcontext.GetLogger(registry.app).Infof("listening on %v", ln.Addr())
|
||||
}
|
||||
|
||||
return registry.server.Serve(ln)
|
||||
|
@ -228,7 +229,7 @@ func configureLogging(ctx context.Context, config *configuration.Configuration)
|
|||
if config.Log.Level == "" && config.Log.Formatter == "" {
|
||||
// If no config for logging is set, fallback to deprecated "Loglevel".
|
||||
log.SetLevel(logLevel(config.Loglevel))
|
||||
ctx = context.WithLogger(ctx, context.GetLogger(ctx))
|
||||
ctx = dcontext.WithLogger(ctx, dcontext.GetLogger(ctx))
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
|
@ -270,8 +271,8 @@ func configureLogging(ctx context.Context, config *configuration.Configuration)
|
|||
fields = append(fields, k)
|
||||
}
|
||||
|
||||
ctx = context.WithValues(ctx, config.Log.Fields)
|
||||
ctx = context.WithLogger(ctx, context.GetLogger(ctx, fields...))
|
||||
ctx = dcontext.WithValues(ctx, config.Log.Fields)
|
||||
ctx = dcontext.WithLogger(ctx, dcontext.GetLogger(ctx, fields...))
|
||||
}
|
||||
|
||||
return ctx, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue