all python files are now formated with black (#23)

* all python files are now formated with black

NOTE:
some configurations where necessary. flake8 line-length has to be set to 88
which is the default for black. but this was not enough some lines of black
where formated longer then 88 characters. found flake8-bugbear with B950.

with that and in combination with ignore=E501 it is possible to ignore long
lines, but if there are lines to long it will still point it out.

further also for isort some configuration was necessary

REFERENCES:
https://github.com/psf/black/blob/master/docs/compatible_configs.md#isort
https://github.com/psf/black/blob/master/docs/compatible_configs.md#flake8
https://github.com/PyCQA/flake8-bugbear#opinionated-warnings

* ext removed unnecessary commented import statement

* generators add pragma: no cover to increase code coverage

NOTE:
this should be corrected with a real test in one of the next commits

* fixed the syntax.

Co-authored-by: Mojib Wali <44528277+mb-wali@users.noreply.github.com>
This commit is contained in:
Christoph Ladurner
2020-10-15 10:36:58 +02:00
committed by GitHub
parent 0a37a8015e
commit 2ccd24cfca
12 changed files with 234 additions and 193 deletions
+1 -1
View File
@@ -12,4 +12,4 @@ from .ext import InvenioConfigTugraz
from .generators import RecordIp
from .version import __version__
__all__ = ('__version__', 'InvenioConfigTugraz', 'RecordIp')
__all__ = ("__version__", "InvenioConfigTugraz", "RecordIp")
+32 -31
View File
@@ -31,46 +31,47 @@ INVENIO_CONFIG_TUGRAZ_IP_RANGES =
# ===========
# See https://invenio-app.readthedocs.io/en/latest/configuration.html
APP_ALLOWED_HOSTS = ['0.0.0.0',
'localhost',
'127.0.0.1',
'invenio-dev01.tugraz.at',
'invenio-test.tugraz.at'
]
APP_ALLOWED_HOSTS = [
"0.0.0.0",
"localhost",
"127.0.0.1",
"invenio-dev01.tugraz.at",
"invenio-test.tugraz.at",
]
"""Allowed Hosts"""
APP_DEFAULT_SECURE_HEADERS = {
'content_security_policy': {
'default-src': [
"content_security_policy": {
"default-src": [
"'self'",
'fonts.googleapis.com',
'*.gstatic.com',
'data:',
"fonts.googleapis.com",
"*.gstatic.com",
"data:",
"'unsafe-inline'",
"'unsafe-eval'",
"blob:",
],
},
'content_security_policy_report_only': False,
'content_security_policy_report_uri': None,
'force_file_save': False,
'force_https': True,
'force_https_permanent': False,
'frame_options': 'sameorigin',
'frame_options_allow_from': None,
'session_cookie_http_only': True,
'session_cookie_secure': True,
'strict_transport_security': True,
'strict_transport_security_include_subdomains': True,
'strict_transport_security_max_age': 31556926, # One year in seconds
'strict_transport_security_preload': False,
"content_security_policy_report_only": False,
"content_security_policy_report_uri": None,
"force_file_save": False,
"force_https": True,
"force_https_permanent": False,
"frame_options": "sameorigin",
"frame_options_allow_from": None,
"session_cookie_http_only": True,
"session_cookie_secure": True,
"strict_transport_security": True,
"strict_transport_security_include_subdomains": True,
"strict_transport_security_max_age": 31556926, # One year in seconds
"strict_transport_security_preload": False,
}
# Invenio-Mail
# ===========
# See https://invenio-mail.readthedocs.io/en/latest/configuration.html
MAIL_SERVER = 'localhost'
MAIL_SERVER = "localhost"
"""Domain ip where mail server is running."""
SECURITY_EMAIL_SENDER = "info@invenio-test.tugraz.at"
@@ -117,23 +118,23 @@ when register.
SSO_SAML_IDPS = {}
"""Configuration of IDPS. Actual values can be find in to invenio.cfg file"""
SSO_SAML_DEFAULT_BLUEPRINT_PREFIX = '/shibboleth'
SSO_SAML_DEFAULT_BLUEPRINT_PREFIX = "/shibboleth"
"""Base URL for the extensions endpoint."""
SSO_SAML_DEFAULT_METADATA_ROUTE = '/metadata/<idp>'
SSO_SAML_DEFAULT_METADATA_ROUTE = "/metadata/<idp>"
"""URL route for the metadata request."""
"""This is also SP entityID https://domain/shibboleth/metadata/<idp>"""
SSO_SAML_DEFAULT_SSO_ROUTE = '/login/<idp>'
SSO_SAML_DEFAULT_SSO_ROUTE = "/login/<idp>"
"""URL route for the SP login."""
SSO_SAML_DEFAULT_ACS_ROUTE = '/authorized/<idp>'
SSO_SAML_DEFAULT_ACS_ROUTE = "/authorized/<idp>"
"""URL route to handle the IdP login request."""
SSO_SAML_DEFAULT_SLO_ROUTE = '/slo/<idp>'
SSO_SAML_DEFAULT_SLO_ROUTE = "/slo/<idp>"
"""URL route for the SP logout."""
SSO_SAML_DEFAULT_SLS_ROUTE = '/sls/<idp>'
SSO_SAML_DEFAULT_SLS_ROUTE = "/sls/<idp>"
"""URL route to handle the IdP logout request."""
# Invenio-accounts
+2 -4
View File
@@ -8,8 +8,6 @@
"""invenio module that adds tugraz configs."""
from flask_babelex import gettext as _
from . import config
@@ -24,10 +22,10 @@ class InvenioConfigTugraz(object):
def init_app(self, app):
"""Flask application initialization."""
self.init_config(app)
app.extensions['invenio-config-tugraz'] = self
app.extensions["invenio-config-tugraz"] = self
def init_config(self, app):
"""Initialize configuration."""
for k in dir(config):
if k.startswith('INVENIO_CONFIG_TUGRAZ_'):
if k.startswith("INVENIO_CONFIG_TUGRAZ_"):
app.config.setdefault(k, getattr(config, k))
+4 -4
View File
@@ -202,13 +202,13 @@ class RecordIp(Generator):
These filters consist of additive queries mapping to what the current
user should be able to retrieve via search.
"""
return Q('match_all')
return Q("match_all")
def check_permission(self):
"""Check for User IP address in config variable."""
# Get user IP
user_ip = request.remote_addr # pragma: no cover
# Checks if the user IP is among single IPs
if user_ip in current_app.config['INVENIO_CONFIG_TUGRAZ_SINGLE_IP']:
return True # pragma: no cover
return False # pragma: no cover
if user_ip in current_app.config["INVENIO_CONFIG_TUGRAZ_SINGLE_IP"]: # pragma: no cover
return True # pragma: no cover
return False # pragma: no cover
+6 -2
View File
@@ -49,8 +49,12 @@ Using Custom Generator for a policy:
Permissions for Invenio (RDM) Records.
"""
from invenio_records_permissions.generators import Admin, AnyUser, \
AnyUserIfPublic, Disable, RecordOwners
from invenio_records_permissions.generators import (
Admin,
AnyUser,
AnyUserIfPublic,
RecordOwners,
)
from invenio_records_permissions.policies.base import BasePermissionPolicy
from .generators import RecordIp
+1 -1
View File
@@ -12,4 +12,4 @@ This file is imported by ``invenio_config_tugraz.__init__``,
and parsed by ``setup.py``.
"""
__version__ = '0.2.1'
__version__ = "0.2.1"