Add registry middleware access to storage drivers
Signed-off-by: David Wu <dwu7401@gmail.com>
This commit is contained in:
parent
89337b7a25
commit
db1d0cbf35
3 changed files with 21 additions and 6 deletions
|
@ -301,7 +301,7 @@ func NewApp(ctx context.Context, config *configuration.Configuration) *App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
app.registry, err = applyRegistryMiddleware(app, app.registry, config.Middleware["registry"])
|
app.registry, err = applyRegistryMiddleware(app, app.registry, app.driver, config.Middleware["registry"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -958,9 +958,9 @@ func appendCatalogAccessRecord(accessRecords []auth.Access, r *http.Request) []a
|
||||||
}
|
}
|
||||||
|
|
||||||
// applyRegistryMiddleware wraps a registry instance with the configured middlewares
|
// applyRegistryMiddleware wraps a registry instance with the configured middlewares
|
||||||
func applyRegistryMiddleware(ctx context.Context, registry distribution.Namespace, middlewares []configuration.Middleware) (distribution.Namespace, error) {
|
func applyRegistryMiddleware(ctx context.Context, registry distribution.Namespace, driver storagedriver.StorageDriver, middlewares []configuration.Middleware) (distribution.Namespace, error) {
|
||||||
for _, mw := range middlewares {
|
for _, mw := range middlewares {
|
||||||
rmw, err := registrymiddleware.Get(ctx, mw.Name, mw.Options, registry)
|
rmw, err := registrymiddleware.Get(ctx, mw.Name, mw.Options, registry, driver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to configure registry middleware (%s): %s", mw.Name, err)
|
return nil, fmt.Errorf("unable to configure registry middleware (%s): %s", mw.Name, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,11 +6,12 @@ import (
|
||||||
|
|
||||||
"github.com/distribution/distribution/v3"
|
"github.com/distribution/distribution/v3"
|
||||||
"github.com/distribution/distribution/v3/registry/storage"
|
"github.com/distribution/distribution/v3/registry/storage"
|
||||||
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InitFunc is the type of a RegistryMiddleware factory function and is
|
// InitFunc is the type of a RegistryMiddleware factory function and is
|
||||||
// used to register the constructor for different RegistryMiddleware backends.
|
// used to register the constructor for different RegistryMiddleware backends.
|
||||||
type InitFunc func(ctx context.Context, registry distribution.Namespace, options map[string]interface{}) (distribution.Namespace, error)
|
type InitFunc func(ctx context.Context, registry distribution.Namespace, driver storagedriver.StorageDriver, options map[string]interface{}) (distribution.Namespace, error)
|
||||||
|
|
||||||
var middlewares map[string]InitFunc
|
var middlewares map[string]InitFunc
|
||||||
var registryoptions []storage.RegistryOption
|
var registryoptions []storage.RegistryOption
|
||||||
|
@ -31,10 +32,10 @@ func Register(name string, initFunc InitFunc) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get constructs a RegistryMiddleware with the given options using the named backend.
|
// Get constructs a RegistryMiddleware with the given options using the named backend.
|
||||||
func Get(ctx context.Context, name string, options map[string]interface{}, registry distribution.Namespace) (distribution.Namespace, error) {
|
func Get(ctx context.Context, name string, options map[string]interface{}, registry distribution.Namespace, driver storagedriver.StorageDriver) (distribution.Namespace, error) {
|
||||||
if middlewares != nil {
|
if middlewares != nil {
|
||||||
if initFunc, exists := middlewares[name]; exists {
|
if initFunc, exists := middlewares[name]; exists {
|
||||||
return initFunc(ctx, registry, options)
|
return initFunc(ctx, registry, driver, options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,6 +92,16 @@ var tlsVersions = map[string]uint16{
|
||||||
// this channel gets notified when process receives signal. It is global to ease unit testing
|
// this channel gets notified when process receives signal. It is global to ease unit testing
|
||||||
var quit = make(chan os.Signal, 1)
|
var quit = make(chan os.Signal, 1)
|
||||||
|
|
||||||
|
// HandlerFunc defines an http middleware
|
||||||
|
type HandlerFunc func(config *configuration.Configuration, handler http.Handler) http.Handler
|
||||||
|
|
||||||
|
var handlerMiddlewares []HandlerFunc
|
||||||
|
|
||||||
|
// RegisterHandler is used to register http middlewares to the registry service
|
||||||
|
func RegisterHandler(handlerFunc HandlerFunc) {
|
||||||
|
handlerMiddlewares = append(handlerMiddlewares, handlerFunc)
|
||||||
|
}
|
||||||
|
|
||||||
// ServeCmd is a cobra command for running the registry.
|
// ServeCmd is a cobra command for running the registry.
|
||||||
var ServeCmd = &cobra.Command{
|
var ServeCmd = &cobra.Command{
|
||||||
Use: "serve <config>",
|
Use: "serve <config>",
|
||||||
|
@ -172,6 +182,10 @@ func NewRegistry(ctx context.Context, config *configuration.Configuration) (*Reg
|
||||||
handler = gorhandlers.CombinedLoggingHandler(os.Stdout, handler)
|
handler = gorhandlers.CombinedLoggingHandler(os.Stdout, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, applyHandlerMiddleware := range handlerMiddlewares {
|
||||||
|
handler = applyHandlerMiddleware(config, handler)
|
||||||
|
}
|
||||||
|
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Handler: handler,
|
Handler: handler,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue