-
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.
feature: allow registering new repositories
- Loading branch information
Showing
14 changed files
with
184 additions
and
16 deletions.
There are no files selected for viewing
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
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
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,17 @@ | ||
from __future__ import annotations | ||
|
||
from ckan.plugins.interfaces import Interface | ||
|
||
import ckanext.event_audit.repositories as repos | ||
|
||
|
||
class IEventAudit(Interface): | ||
def register_repository(self) -> dict[str, type[repos.AbstractRepository]]: | ||
"""Return the repositories provided by this plugin. | ||
Return a dictionary mapping repository names (strings) to | ||
repository classes. For example: | ||
{RedisRepository.get_name(): RedisRepository} | ||
""" | ||
return {} |
Empty file.
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,15 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import ckan.plugins.toolkit as tk | ||
from ckan.types import Context | ||
|
||
from ckanext.event_audit import utils | ||
|
||
|
||
def audit_active_repo_validator(value: Any, context: Context) -> Any: | ||
if value not in utils.get_available_repos(): | ||
raise tk.Invalid(f"Repository `{value}` is not registered") | ||
|
||
return value |
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 |
---|---|---|
@@ -1,7 +1,25 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import yaml | ||
|
||
import ckan.plugins as plugins | ||
import ckan.plugins.toolkit as tk | ||
from ckan.config.declaration import Declaration, Key | ||
from ckan.logic import clear_validators_cache | ||
|
||
|
||
@tk.blanket.config_declarations | ||
@tk.blanket.validators | ||
class EventAuditPlugin(plugins.SingletonPlugin): | ||
pass | ||
plugins.implements(plugins.IConfigDeclaration) | ||
|
||
# IConfigDeclaration | ||
|
||
def declare_config_options(self, declaration: Declaration, key: Key): | ||
# this call allows using custom validators in config declarations | ||
clear_validators_cache() | ||
|
||
here = os.path.dirname(__file__) | ||
with open(os.path.join(here, "config_declaration.yaml"), "rb") as src: | ||
declaration.load_dict(yaml.safe_load(src)) |
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
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
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,41 @@ | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
import ckan.plugins as p | ||
|
||
from ckanext.event_audit.interfaces import IEventAudit | ||
from ckanext.event_audit.repositories import AbstractRepository | ||
from ckanext.event_audit import types, utils | ||
|
||
|
||
class MyRepository(AbstractRepository): | ||
@classmethod | ||
def get_name(cls) -> str: | ||
return "my_repository" | ||
|
||
def write_event(self, event: types.Event) -> types.WriteStatus: | ||
return types.WriteStatus(status=True) | ||
|
||
def get_event(self, event_id: str) -> types.Event | None: | ||
return None | ||
|
||
def filter_events(self, filters: types.Filters) -> list[types.Event]: | ||
return [] | ||
|
||
|
||
class TestEventAuditPlugin(p.SingletonPlugin): | ||
p.implements(IEventAudit, inherit=True) | ||
|
||
def register_repository(self) -> dict[str, type[AbstractRepository]]: | ||
return { | ||
MyRepository.get_name(): MyRepository, | ||
} | ||
|
||
|
||
@pytest.mark.ckan_config("ckan.plugins", "event_audit test_event_audit") | ||
@pytest.mark.usefixtures("non_clean_db", "with_plugins") | ||
class TestOTLInterace(object): | ||
def test_get_available_repos(self, app, user, sysadmin): | ||
repos = utils.get_available_repos() | ||
assert MyRepository.get_name() in repos |
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
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
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 |
---|---|---|
@@ -1 +0,0 @@ | ||
pydantic>=2.3.0,<2.4.0 | ||
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
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