Skip to content
This repository was archived by the owner on Sep 12, 2018. It is now read-only.

Commit a8bd4a4

Browse files
committed
index: Expand load() to handle arbitrary module names
It would be nice if users could point to their own index implementations if a suitable backend is not supplied by docker-registry. This commit adds support for loading Index implementations from arbitrary modules. Reported-by: Lee Trout <[email protected]>
1 parent 294880a commit a8bd4a4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,16 @@ backend-specific configuration options are:
227227
`sqlalchemy_index_database`, which is passed through to
228228
[create_engine][].
229229

230+
If `search_backend` is neither empty nor one of the above backends, it
231+
should point to a module:
232+
233+
```yaml
234+
search_backend: foo.registry.index.xapian
235+
```
236+
237+
In this case, the module is imported, and an instance of it's `Index`
238+
class is used as the search backend.
239+
230240
### Email options
231241

232242
Settings these options makes the Registry send an email on each code Exception:

lib/index/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Index backends for the search endpoint
22
"""
33

4+
import importlib
45
import signals
56

67
import config
@@ -76,5 +77,10 @@ def load(kind=None):
7677
if kind == 'sqlalchemy':
7778
from . import db
7879
return db.SQLAlchemyIndex()
80+
try:
81+
module = importlib.import_module(kind)
82+
except ImportError:
83+
pass
7984
else:
80-
raise NotImplementedError('Unknown index type {0!r}'.format(kind))
85+
return module.Index()
86+
raise NotImplementedError('Unknown index type {0!r}'.format(kind))

0 commit comments

Comments
 (0)