-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Roughed in files and entry points for extension to provision commons …
…search
- Loading branch information
1 parent
9b69b89
commit 35ee48a
Showing
6 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
site/knowledge_commons_repository/invenio_remote_search_provisioner/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from __future__ import absolute_import, print_function | ||
from .ext import InvenioRemoteSearchProvisioner | ||
|
||
"""An InvenioRDM Flask extension to provision remote search indexes | ||
for InvenioRDM records. | ||
Sends a POST request to a remote search index API endpoint to provide the | ||
index with metadata whenever a new record is created in InvenioRDM. | ||
""" | ||
|
||
__version__ = "1.0.0a" | ||
|
||
__all__ = ("__version__", "InvenioRemoteSearchProvisioner") |
57 changes: 57 additions & 0 deletions
57
site/knowledge_commons_repository/invenio_remote_search_provisioner/ext.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of the invenio-remote-user-data package. | ||
# Copyright (C) 2024, Mesh Research. | ||
# | ||
# invenio-remote-search-provisioner is free software; you can redistribute it | ||
# and/or modify it under the terms of the MIT License; see | ||
# LICENSE file for more details. | ||
|
||
from . import config | ||
from .service import RemoteSearchProvisionerService | ||
|
||
# from .config import RemoteUserDataServiceConfig | ||
|
||
|
||
class InvenioRemoteSearchProvisioner(object): | ||
"""Flask extension for invenio-remote-search-provisioner. | ||
Args: | ||
object (_type_): _description_ | ||
""" | ||
|
||
def __init__(self, app=None) -> None: | ||
"""Extention initialization.""" | ||
if app: | ||
self.init_app(app) | ||
|
||
def init_app(self, app) -> None: | ||
"""Registers the Flask extension during app initialization. | ||
Args: | ||
app (Flask): the Flask application object on which to initialize | ||
the extension | ||
""" | ||
self.init_config(app) | ||
self.init_services(app) | ||
app.extensions["invenio-remote-search-provisioner"] = self | ||
|
||
def init_config(self, app) -> None: | ||
"""Initialize configuration for the extention. | ||
Args: | ||
app (_type_): _description_ | ||
""" | ||
for k in dir(config): | ||
if k.startswith("REMOTE_SEARCH_PROVISIONER_"): | ||
app.config.setdefault(k, getattr(config, k)) | ||
|
||
def init_services(self, app): | ||
"""Initialize services for the extension. | ||
Args: | ||
app (_type_): _description_ | ||
""" | ||
self.service = RemoteSearchProvisionerService(app, config=app.config) | ||
# self.service = RemoteUserDataService( | ||
# config=RemoteUserDataServiceConfig) |
10 changes: 10 additions & 0 deletions
10
site/knowledge_commons_repository/invenio_remote_search_provisioner/service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from invenio_records_resources.services import Service | ||
from .utils import logger as update_logger | ||
|
||
|
||
class RemoteUserDataService(Service): | ||
"""Service for retrieving user data from a Remote server.""" | ||
|
||
def __init__(self, app, config={}, **kwargs): | ||
"""Constructor.""" | ||
super().__init__(config=config, **kwargs) |
24 changes: 24 additions & 0 deletions
24
site/knowledge_commons_repository/invenio_remote_search_provisioner/utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of the invenio-remote-search-provisioner package. | ||
# Copyright (C) 2024, MESH Research. | ||
# | ||
# invenio-remote-search-provisioner is free software; you can redistribute it | ||
# and/or modify it under the terms of the MIT License; see | ||
# LICENSE file for more details. | ||
|
||
"""Utility functions for invenio-remote-search-provisioner. | ||
""" | ||
|
||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.INFO) | ||
formatter = logging.Formatter("%(asctime)s:%(levelname)s : %(message)s") | ||
file_handler = logging.handlers.RotatingFileHandler( | ||
"logs/remote_search_provisioner.log", maxBytes=1000000, backupCount=5 | ||
) | ||
file_handler.setFormatter(formatter) | ||
if logger.hasHandlers(): | ||
logger.handlers.clear() | ||
logger.addHandler(file_handler) |
25 changes: 25 additions & 0 deletions
25
site/knowledge_commons_repository/invenio_remote_search_provisioner/views.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from flask import Blueprint | ||
|
||
|
||
def create_api_blueprint(app): | ||
"""Register blueprint on api app.""" | ||
blueprint = Blueprint("invenio_remote_search_provisioner", __name__) | ||
|
||
# routes = app.config.get("APP_RDM_ROUTES") | ||
|
||
# blueprint.add_url_rule( | ||
# "/webhooks/idp_data_update", | ||
# view_func=IDPUpdateWebhook.as_view("ipd_update_webhook"), | ||
# ) | ||
|
||
# Register error handlers | ||
# blueprint.register_error_handler(Forbidden, | ||
# lambda e: make_response(jsonify({"error": "Forbidden", | ||
# "status": 403}), 403) | ||
# ) | ||
# blueprint.register_error_handler(MethodNotAllowed, | ||
# lambda e: make_response(jsonify({"message": "Method not allowed", | ||
# "status": 405}), 405) | ||
# ) | ||
|
||
return blueprint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters