Skip to content

Commit

Permalink
schemas: add config fixture, update serializer
Browse files Browse the repository at this point in the history
* closes cernanalysispreservation#2215

Signed-off-by: Ilias Koutsakis <ilias.koutsakis@cern.ch>
  • Loading branch information
Lilykos committed Jun 15, 2021
1 parent beb8ab6 commit ef9fcd3
Show file tree
Hide file tree
Showing 10 changed files with 913 additions and 2 deletions.
7 changes: 7 additions & 0 deletions cap/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from invenio_records_rest.utils import allow_all, deny_all
from jsonresolver import JSONResolver
from jsonresolver.contrib.jsonref import json_loader_factory
from jsonresolver.contrib.jsonschema import ref_resolver_factory

from cap.modules.deposit.permissions import (AdminDepositPermission,
CreateDepositPermission,
Expand Down Expand Up @@ -594,6 +595,12 @@ def _(x):
'cap.modules.schemas.resolvers', 'cap.modules.schemas.resolvers_api'
], ))

JSONSCHEMAS_CONFIG_RESOLVER_CLS = ref_resolver_factory(
JSONResolver(plugins=[
'cap.modules.schemas.resolvers_config'
]))


# WARNING: Do not share the secret key - especially do not commit it to
# version control.
SECRET_KEY = "changeme"
Expand Down
12 changes: 11 additions & 1 deletion cap/modules/schemas/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
from cap.modules.schemas.models import Schema
from cap.modules.schemas.resolvers import resolve_schema_by_url,\
resolve_schema_by_name_and_version, schema_name_to_url
from cap.modules.schemas.utils import is_later_version
from cap.modules.schemas.utils import is_later_version, validate_schema_config

DEPOSIT_REQUIRED_FIELDS = [
'_buckets',
Expand Down Expand Up @@ -253,6 +253,16 @@ def add_schema_from_json(data, replace=None, force_version=None):
allow_all = data.pop("allow_all", False)
version = data['version']
name = data['name']
config = data.get('config')

if config:
errors = validate_schema_config(config)
if errors:
click.secho(errors, fg='red')
click.secho(
f'Configuration is invalid. '
f'Aborting update for schema {name}.', fg='red')
return

try:
with db.session.begin_nested():
Expand Down
16 changes: 16 additions & 0 deletions cap/modules/schemas/configs/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"type": "object",
"title": "General Configuration",
"additionalProperties":false,
"properties": {
"notifications": {
"$ref": "https://analysispreservation.cern.ch/configs/notifications.json"
},
"reviewable": {
"$ref": "https://analysispreservation.cern.ch/configs/reviewable.json"
},
"repositories": {
"$ref": "https://analysispreservation.cern.ch/configs/repositories.json"
}
}
}
Loading

0 comments on commit ef9fcd3

Please sign in to comment.