Skip to content

Commit

Permalink
Roughed in files and entry points for extension to provision commons …
Browse files Browse the repository at this point in the history
…search
  • Loading branch information
monotasker committed Jan 16, 2024
1 parent 9b69b89 commit 35ee48a
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 0 deletions.
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")
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)
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)
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)
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
2 changes: 2 additions & 0 deletions site/setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ tests =
[options.entry_points]
invenio_base.api_apps =
invenio_remote_user_data = knowledge_commons_repository.invenio_remote_user_data.ext:InvenioRemoteUserData
invenio_remote_user_data = knowledge_commons_repository.invenio_remote_search_provisioner.ext:InvenioRemoteSearchProvisioner
invenio_base.apps =
invenio_remote_user_data = knowledge_commons_repository.invenio_remote_user_data.ext:InvenioRemoteUserData
invenio_queues.queues =
Expand All @@ -19,6 +20,7 @@ invenio_base.blueprints =
knowledge_commons_repository_views = knowledge_commons_repository.views.views:create_blueprint
invenio_base.api_blueprints =
invenio_remote_user_data = knowledge_commons_repository.invenio_remote_user_data.views:create_api_blueprint
invenio_remote_search_provisioner= knowledge_commons_repository.invenio_remote_search_provisioner.views:create_api_blueprint
invenio_assets.webpack =
knowledge_commons_repository_theme = knowledge_commons_repository.webpack:theme
invenio_i18n.translations =
Expand Down

0 comments on commit 35ee48a

Please sign in to comment.