@@ -6,19 +6,24 @@ import (
6
6
"github.com/docker/distribution"
7
7
"github.com/docker/distribution/configuration"
8
8
"github.com/docker/distribution/context"
9
- "github.com/docker/distribution/registry/handlers"
10
9
storagedriver "github.com/docker/distribution/registry/storage/driver"
11
10
12
11
"github.com/openshift/image-registry/pkg/dockerregistry/server/client"
13
12
registryconfig "github.com/openshift/image-registry/pkg/dockerregistry/server/configuration"
14
13
"github.com/openshift/image-registry/pkg/dockerregistry/server/maxconnections"
14
+ "github.com/openshift/image-registry/pkg/dockerregistry/server/supermiddleware"
15
15
)
16
16
17
17
const (
18
18
// Default values
19
19
defaultDigestToRepositoryCacheSize = 2048
20
20
)
21
21
22
+ // appMiddleware should be used only in tests.
23
+ type appMiddleware interface {
24
+ Apply (supermiddleware.App ) supermiddleware.App
25
+ }
26
+
22
27
// App is a global registry application object. Shared resources can be placed
23
28
// on this object that will be accessible from all requests.
24
29
type App struct {
@@ -57,6 +62,16 @@ type App struct {
57
62
quotaEnforcing * quotaEnforcingConfig
58
63
}
59
64
65
+ func (app * App ) Storage (driver storagedriver.StorageDriver , options map [string ]interface {}) (storagedriver.StorageDriver , error ) {
66
+ app .driver = driver
67
+ return driver , nil
68
+ }
69
+
70
+ func (app * App ) Registry (registry distribution.Namespace , options map [string ]interface {}) (distribution.Namespace , error ) {
71
+ app .registry = registry
72
+ return registry , nil
73
+ }
74
+
60
75
// NewApp configures the registry application and returns http.Handler for it.
61
76
// The program will be terminated if an error happens.
62
77
func NewApp (ctx context.Context , registryClient client.RegistryClient , dockerConfig * configuration.Configuration , extraConfig * registryconfig.Configuration , writeLimiter maxconnections.Limiter ) http.Handler {
@@ -74,11 +89,9 @@ func NewApp(ctx context.Context, registryClient client.RegistryClient, dockerCon
74
89
}
75
90
app .cachedLayers = cache
76
91
77
- weaveAppIntoConfig (app , dockerConfig )
78
-
79
92
repositoryEnabled := false
80
93
for _ , middleware := range dockerConfig .Middleware ["repository" ] {
81
- if middleware .Name == middlewareOpenShift {
94
+ if middleware .Name == "openshift" {
82
95
rc , err := newRepositoryConfig (ctx , extraConfig , middleware .Options )
83
96
if err != nil {
84
97
context .GetLogger (ctx ).Fatalf ("error configuring the repository middleware: %s" , err )
@@ -89,8 +102,13 @@ func NewApp(ctx context.Context, registryClient client.RegistryClient, dockerCon
89
102
}
90
103
}
91
104
92
- dockerApp := handlers .NewApp (ctx , dockerConfig )
105
+ superapp := supermiddleware .App (app )
106
+ if am := appMiddlewareFrom (ctx ); am != nil {
107
+ superapp = am .Apply (superapp )
108
+ }
109
+ dockerApp := supermiddleware .NewApp (ctx , dockerConfig , superapp )
93
110
111
+ const middlewareOpenShift = "openshift"
94
112
if repositoryEnabled {
95
113
if app .driver == nil {
96
114
context .GetLogger (ctx ).Fatalf ("configuration error: the storage driver middleware %q is not activated" , middlewareOpenShift )
0 commit comments