Skip to content
Snippets Groups Projects
Commit c6aa4f94 authored by Florian Spreckelsen's avatar Florian Spreckelsen
Browse files

Merge branch 'f-extend-json-schema' into 'dev'

FIX: JSON schema now is more permissive, and fixed if-conditions.

See merge request !54
parents b1feec60 9e310bad
No related branches found
No related tags found
2 merge requests!57RELEASE 0.7.3,!54FIX: JSON schema now is more permissive, and fixed if-conditions.
Pipeline #21287 passed
......@@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ###
* [#75](https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/issues/75), [#103](https://gitlab.indiscale.com/caosdb/src/caosdb-pylib/-/issues/103) Fixed JSON schema to allow more sections, and correct requirements for
password method.
### Security ###
### Documentation ###
......
......@@ -49,7 +49,11 @@ ISRELEASED = False
MAJOR = 0
MINOR = 8
MICRO = 0
PRE = "dev" # e.g. rc0, alpha.1, 0.beta-23
# Do not tag as pre-release until this commit
# https://github.com/pypa/packaging/pull/515
# has made it into a release. Probably we should wait for pypa/packaging>=21.4
# https://github.com/pypa/packaging/releases
PRE = "" # "dev" # e.g. rc0, alpha.1, 0.beta-23
if PRE:
VERSION = "{}.{}.{}-{}".format(MAJOR, MINOR, MICRO, PRE)
......
......@@ -84,23 +84,28 @@ def config_to_yaml(config):
def validate_yaml_schema(valobj):
# TODO: Re-enable warning once the schema has been extended to also cover
# SSS pycaosdb.inis and integration tests.
if optional_jsonschema_validate:
with open(os.path.join(os.path.dirname(__file__), "schema-pycaosdb-ini.yml")) as f:
schema = yaml.load(f, Loader=yaml.SafeLoader)
optional_jsonschema_validate(instance=valobj, schema=schema["schema-pycaosdb-ini"])
# else:
# warnings.warn("""
# Warning: The validation could not be performed because `jsonschema` is not installed.
# """)
else:
warnings.warn("""
Warning: The validation could not be performed because `jsonschema` is not installed.
""")
def _read_config_files():
"""Function to read config files from different paths. Checks for path in $PYCAOSDBINI or home directory (.pycaosdb.ini) and in the current working directory (pycaosdb.ini).
"""Function to read config files from different paths.
Checks for path either in ``$PYCAOSDBINI`` or home directory (``.pycaosdb.ini``), and
additionally in the current working directory (``pycaosdb.ini``).
Returns
-------
ini files: list
The successfully parsed ini-files. Order: env_var or home directory, cwd. Used for testing the function.
Returns:
[list]: list with successfully parsed ini-files. Order: env_var or home directory, cwd. Used for testing the function.
"""
return_var = []
if "PYCAOSDBINI" in environ:
......
......@@ -65,26 +65,39 @@ schema-pycaosdb-ini:
properties:
password_method:
const: input
required: [password_method]
then:
required: [url]
- if:
properties:
password_method:
const: plain
required: [password_method]
then:
required: [url, username, password]
- if:
properties:
password_method:
const: pass
required: [password_method]
then:
required: [url, username, password_identifier]
- if:
properties:
password_method:
const: keyring
required: [password_method]
then:
required: [url, username]
IntegrationTests:
description: "Used by the integration test suite from the caosdb-pyinttest repo."
additionalProperties: true
Misc:
description: "Some additional configuration settings."
additionalProperties: true
advancedtools:
description: "Configuration settings for the caosadvancedtools."
additionalProperties: true
sss_helper:
description: "Configuration settings for server-side scripting."
additionalProperties: true
# -*- mode:conf; -*-
## This sections needs to exist in addition to the usual section
[IntegrationTests]
# test_server_side_scripting.bin_dir.local=/path/to/scripting/bin
test_server_side_scripting.bin_dir.local=/home/myself/test/caosdb-server/scripting/bin
# test_server_side_scripting.bin_dir.server=/opt/caosdb/git/caosdb-server/scripting/bin
# # location of the files from the pyinttest perspective
# test_files.test_insert_files_in_dir.local=/extroot/test_insert_files_in_dir/
test_files.test_insert_files_in_dir.local=/home/myself/test/debug_advanced/paths/extroot/test_insert_files_in_dir
# # location of the files from the caosdb_servers perspective
test_files.test_insert_files_in_dir.server=/opt/caosdb/mnt/extroot/test_insert_files_in_dir/
########## Files ##################
## Used by tests of file handling. Specify the path to an existing
## directory in which file tests are performed, once as seen by the
## host and once as seen by the server.
# location of the files from the pyinttest (i.e. host) perspective
#test_files.test_insert_files_in_dir.local=/extroot/test_insert_files_in_dir/
# location of the files from the caosdb server's perspective
#test_files.test_insert_files_in_dir.server=/opt/caosdb/mnt/extroot/test_insert_files_in_dir/
# # location of the one-time tokens from the pyinttest's perspective
# test_authentication.admin_token_crud = /authtoken/admin_token_crud.txt
# test_authentication.admin_token_expired = /authtoken/admin_token_expired.txt
# test_authentication.admin_token_3_attempts = /authtoken/admin_token_3_attempts.txt
## Insert your usual settings here
[Connection]
url=https://localhost:10443/
username=admin
password_method=plain
password=caosdb
[Connection]
url = https://localhost:10443
cacert = /opt/caosdb/cert/caosdb.cert.pem
debug = 0
timeout = 5000
[Misc]
sendmail = /usr/local/bin/sendmail_to_file
entity_loan.curator_mail_from=crawler-test@example.com
entity_loan.curator_mail_to=crawler-test@example.com
[sss_helper]
external_uri = https://caosdb.example.com:443
[advancedtools]
crawler.from_mail=admin@example.com
crawler.to_mail=admin@example.com
[Connection]
url = https://samplemanager.example.com:443
cacert = /opt/caosdb/cert/caosdb.cert.pem
debug = 0
timeout = 5000
[Misc]
sendmail = /usr/local/bin/sendmail_to_file
entity_loan.curator_mail_from=crawler-test@example.com
entity_loan.curator_mail_to=crawler-test@example.com
[sss_helper]
external_uri = https://localhost:10443
[advancedtools]
crawler.from_mail=crawler-test@example.com
crawler.to_mail=crawler-test@example.com
; this is the pycaosdb.ini for the server-side-scripting home.
[Connection]
url = https://caosdb-server:10443
cacert = /opt/caosdb/cert/caosdb.cert.pem
debug = 0
timeout = 5000
[Misc]
sendmail = /usr/local/bin/sendmail_to_file
[Connection]
url=https://localhost:10443/
username=admin
password_method=input
[Connection]
url=https://localhost:10443/
username=admin
# No password method: should be "input" by default
......@@ -2,7 +2,9 @@
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2022 Indiscale GmbH <info@indiscale.com>
# Copyright (C) 2021 Alexander Schlemmer
# Copyright (C) 2022 Daniel Hornung <d.hornung@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
......@@ -31,15 +33,18 @@ from configparser import ConfigParser
def test_config_files():
for fn in glob(os.path.join(os.path.dirname(__file__), "test_configs", "*.ini")):
print(f"Testing {fn}.")
c = ConfigParser()
c.read(fn)
print(config_to_yaml(c))
validate_yaml_schema(config_to_yaml(c))
def test_broken_config_files():
for fn in glob(os.path.join(os.path.dirname(__file__), "broken_configs", "*.ini")):
print(fn)
print(f"Testing {fn}.")
with raises(ValidationError):
c = ConfigParser()
c.read(fn)
print(config_to_yaml(c))
validate_yaml_schema(config_to_yaml(c))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment