Skip to content

Commit

Permalink
build: relax dependency version constraints (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
uniqueg committed May 20, 2024
1 parent 9b5b668 commit f6526be
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 59 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ jobs:
python-version: ${{ matrix.py-version-img[0] }}
- name: Install requirements
run: |
pip install -e .
pip install -r requirements_dev.txt
pip install -e .[dev]
- name: Lint with flake8
run: flake8
- name: Run mypy
Expand Down
14 changes: 7 additions & 7 deletions foca/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
)


def _validate_log_level_choices(level: int) -> int:
def _validate_log_level_choices(cls, level: int) -> int:
"""Custom validation function for Pydantic to ensure that a valid
logging level is configured.
Expand All @@ -32,9 +32,9 @@ def _validate_log_level_choices(level: int) -> int:
Raises:
ValueError: Raised if validation fails.
"""
choices = [0, 10, 20, 30, 40, 50]
if level not in choices:
raise ValueError("illegal log level specified")
CHOICES = [0, 10, 20, 30, 40, 50]
if level not in CHOICES:
raise ValueError(f"illegal log level specified: {level}")
return level


Expand Down Expand Up @@ -593,7 +593,7 @@ def set_abs_path(cls, v): # pylint: disable=E0213
absolute path provided.
"""
# if path is not a list, convert it to single-item list
if(isinstance(v, Path)):
if (isinstance(v, Path)):
if not v.is_absolute():
return [Path.cwd() / v]
return [v]
Expand Down Expand Up @@ -1181,10 +1181,10 @@ class LogConfig(FOCABaseConfig):
version: int = 1
disable_existing_loggers: bool = False
formatters: Optional[Dict[str, LogFormatterConfig]] = {
"standard": LogFormatterConfig(),
"standard": LogFormatterConfig(), # type: ignore
}
handlers: Optional[Dict[str, LogHandlerConfig]] = {
"console": LogHandlerConfig(),
"console": LogHandlerConfig(), # type: ignore
}
root: Optional[LogRootConfig] = LogRootConfig()

Expand Down
4 changes: 3 additions & 1 deletion foca/security/access_control/foca_casbin_adapter/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ def __init__(
self._collection = db[collection]

def load_policy(self, model: CasbinRule):
"""Implementing add Interface for casbin. Load all policy rules from mongodb
"""Implementing add Interface for casbin.
Load all policy rules from MongoDB.
Args:
model: CasbinRule object.
Expand Down
20 changes: 12 additions & 8 deletions foca/security/access_control/register_access_control.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
"""Methods to manage permission management configuration"""

import logging
from connexion import App
from connexion.exceptions import Forbidden
from flask_authz import CasbinEnforcer
from functools import wraps
from pkg_resources import resource_filename
from pathlib import Path
from typing import (Callable, Optional, Tuple)
from functools import wraps

from connexion import App
from connexion.exceptions import Forbidden
from flask import current_app
from flask.wrappers import Response
from flask_authz import CasbinEnforcer

from foca.models.config import (
DBConfig,
Expand Down Expand Up @@ -50,7 +52,7 @@ def register_access_control(
access_db_conf = DBConfig(
collections={
access_control_config.collection_name: CollectionConfig()
},
} if access_control_config.collection_name is not None else {},
client=None
)

Expand Down Expand Up @@ -113,7 +115,7 @@ def register_permission_specs(
spec_path = access_control_config.api_specs

spec = SpecConfig(
path=spec_path,
path=Path(spec_path),
add_operation_fields={
"x-openapi-router-controller": (
access_control_config.api_controllers
Expand Down Expand Up @@ -191,7 +193,9 @@ def check_permissions(
"""

def _decorator_check_permissions(fn):
"""User access decorator. Used to facilitate optional decorator arguments.
"""User access decorator.
Used to facilitate optional decorator arguments.
Args:
fn: The function to be decorated.
Expand All @@ -200,7 +204,7 @@ def _decorator_check_permissions(fn):
The response returned from the input function.
"""
@wraps(fn)
def _wrapper(*args, **kwargs):
def _wrapper(*args, **kwargs) -> Tuple[Response, int]:
"""Wrapper for permissions decorator.
Args:
Expand Down
6 changes: 4 additions & 2 deletions foca/security/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ def _get_public_keys(
public_keys = {}
for jwk in response.json().get(claim_keys, []):
try:
key = jwt.algorithms.RSAAlgorithm.from_jwk(json.dumps(jwk))
key = jwt.algorithms.RSAAlgorithm.from_jwk( # type:ignore
json.dumps(jwk)
)

# Ensure key is public
if not isinstance(key, RSAPublicKey):
Expand All @@ -328,7 +330,7 @@ def _get_public_keys(

# Convert to PEM if requested
if pem:
key = key.public_bytes(
key = key.public_bytes( # type: ignore
encoding=serialization.Encoding.PEM,
format=serialization.PublicFormat.SubjectPublicKeyInfo,
).decode('utf-8').encode('unicode_escape').decode('utf-8')
Expand Down
34 changes: 17 additions & 17 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
addict==2.2.1
celery==5.2.2
connexion>=2.11.2,<3.0.0
cryptography==42.0.4
Flask==2.2.5
flask-authz==2.5.1
Flask-Cors==4.0.1
Flask-PyMongo==2.3.0
pydantic==1.10.13
PyJWT==2.4.0
pymongo==4.7.2
PyYAML==6.0.1
requests==2.31.0
swagger-ui-bundle==0.0.6
toml==0.10.0
typing==3.7.4.1
Werkzeug>=2.2.2,<3.0.0
addict~=2.2
celery~=5.2
connexion~=2.11
cryptography~=42.0
Flask~=2.2
flask-authz~=2.5
Flask-Cors~=4.0
Flask-PyMongo~=2.3
pydantic~=1.10
PyJWT~=2.4
pymongo~=4.7
PyYAML~=6.0
requests~=2.31
swagger-ui-bundle~=0.0
toml~=0.10
typing~=3.7
Werkzeug~=2.2
24 changes: 12 additions & 12 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
coverage==6.3.2
flake8==4.0.1
mongomock==4.0.0
mypy==0.971
mypy-extensions==0.4.3
pylint==2.13.2
pytest==7.1.1
python-semantic-release==7.32.2
types-PyYAML==6.0.12
types-requests==2.28.11
types-setuptools==65.3.0
types-urllib3==1.26.25
coverage>=6.5
flake8>=6.1
mongomock>=4.1
mypy>=0.991
mypy-extensions>=0.4.4
pylint>=3.2
pytest>=7.4
python-semantic-release>=7.34,<8.2
types-PyYAML
types-requests
types-setuptools
types-urllib3
6 changes: 3 additions & 3 deletions requirements_docs.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Sphinx==7.2.6
readthedocs-sphinx-ext==2.2.3
sphinx-rtd-theme==1.3.0
Sphinx>=7.2
readthedocs-sphinx-ext>=2.2
sphinx-rtd-theme>=1.3
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@
},
packages=find_packages(),
setup_requires=[
"setuptools_git==1.2",
"twine==3.8.0"
"setuptools_git>=1.2",
"twine>=3.8.0"
],
install_requires=install_requires,
extras_require={
"docs": docs_require,
"dev": dev_requires,
"docs": docs_require,
},
include_package_data=True,
package_data={
Expand Down
4 changes: 2 additions & 2 deletions tests/api/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ def listPets():


def createPets():
return{}
return {}


def showPetById():
return{}
return {}


def putPetsById():
Expand Down
5 changes: 3 additions & 2 deletions tests/security/access_control/test_access_control_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ def test_getAllPermissions(self):
assert res == [data]

def test_getAllPermissions_filters(self):
"""Test for getting a list of all available permissions; all defined filters
specified.
"""Test for getting a list of all available permissions.
All defined filters specified.
"""
app = Flask(__name__)
base_config = Config(db=MongoConfig(**MONGO_CONFIG))
Expand Down

0 comments on commit f6526be

Please sign in to comment.