Skip to content

Commit bacd7eb

Browse files
authored
Merge branch 'dev' into upgrades
2 parents 9c124cf + f6526be commit bacd7eb

File tree

11 files changed

+67
-59
lines changed

11 files changed

+67
-59
lines changed

.github/workflows/checks.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ jobs:
3535
python-version: ${{ matrix.py-version-img[0] }}
3636
- name: Install requirements
3737
run: |
38-
pip install -e .
39-
pip install -r requirements_dev.txt
38+
pip install -e .[dev]
4039
- name: Lint with flake8
4140
run: flake8
4241
- name: Run mypy

foca/models/config.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
)
2020

2121

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

4040

@@ -593,7 +593,7 @@ def set_abs_path(cls, v): # pylint: disable=E0213
593593
absolute path provided.
594594
"""
595595
# if path is not a list, convert it to single-item list
596-
if(isinstance(v, Path)):
596+
if (isinstance(v, Path)):
597597
if not v.is_absolute():
598598
return [Path.cwd() / v]
599599
return [v]
@@ -1181,10 +1181,10 @@ class LogConfig(FOCABaseConfig):
11811181
version: int = 1
11821182
disable_existing_loggers: bool = False
11831183
formatters: Optional[Dict[str, LogFormatterConfig]] = {
1184-
"standard": LogFormatterConfig(),
1184+
"standard": LogFormatterConfig(), # type: ignore
11851185
}
11861186
handlers: Optional[Dict[str, LogHandlerConfig]] = {
1187-
"console": LogHandlerConfig(),
1187+
"console": LogHandlerConfig(), # type: ignore
11881188
}
11891189
root: Optional[LogRootConfig] = LogRootConfig()
11901190

foca/security/access_control/foca_casbin_adapter/adapter.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def __init__(
4242
self._collection = db[collection]
4343

4444
def load_policy(self, model: CasbinRule):
45-
"""Implementing add Interface for casbin. Load all policy rules from mongodb
45+
"""Implementing add Interface for casbin.
46+
47+
Load all policy rules from MongoDB.
4648
4749
Args:
4850
model: CasbinRule object.

foca/security/access_control/register_access_control.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
"""Methods to manage permission management configuration"""
22

33
import logging
4-
from connexion import App
5-
from connexion.exceptions import Forbidden
6-
from flask_authz import CasbinEnforcer
4+
from functools import wraps
75
from pkg_resources import resource_filename
6+
from pathlib import Path
87
from typing import (Callable, Optional, Tuple)
9-
from functools import wraps
8+
9+
from connexion import App
10+
from connexion.exceptions import Forbidden
1011
from flask import current_app
1112
from flask.wrappers import Response
13+
from flask_authz import CasbinEnforcer
1214

1315
from foca.models.config import (
1416
DBConfig,
@@ -50,7 +52,7 @@ def register_access_control(
5052
access_db_conf = DBConfig(
5153
collections={
5254
access_control_config.collection_name: CollectionConfig()
53-
},
55+
} if access_control_config.collection_name is not None else {},
5456
client=None
5557
)
5658

@@ -113,7 +115,7 @@ def register_permission_specs(
113115
spec_path = access_control_config.api_specs
114116

115117
spec = SpecConfig(
116-
path=spec_path,
118+
path=Path(spec_path),
117119
add_operation_fields={
118120
"x-openapi-router-controller": (
119121
access_control_config.api_controllers
@@ -191,7 +193,9 @@ def check_permissions(
191193
"""
192194

193195
def _decorator_check_permissions(fn):
194-
"""User access decorator. Used to facilitate optional decorator arguments.
196+
"""User access decorator.
197+
198+
Used to facilitate optional decorator arguments.
195199
196200
Args:
197201
fn: The function to be decorated.
@@ -200,7 +204,7 @@ def _decorator_check_permissions(fn):
200204
The response returned from the input function.
201205
"""
202206
@wraps(fn)
203-
def _wrapper(*args, **kwargs):
207+
def _wrapper(*args, **kwargs) -> Tuple[Response, int]:
204208
"""Wrapper for permissions decorator.
205209
206210
Args:

foca/security/auth.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ def _get_public_keys(
319319
public_keys = {}
320320
for jwk in response.json().get(claim_keys, []):
321321
try:
322-
key = jwt.algorithms.RSAAlgorithm.from_jwk(json.dumps(jwk))
322+
key = jwt.algorithms.RSAAlgorithm.from_jwk( # type:ignore
323+
json.dumps(jwk)
324+
)
323325

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

329331
# Convert to PEM if requested
330332
if pem:
331-
key = key.public_bytes(
333+
key = key.public_bytes( # type: ignore
332334
encoding=serialization.Encoding.PEM,
333335
format=serialization.PublicFormat.SubjectPublicKeyInfo,
334336
).decode('utf-8').encode('unicode_escape').decode('utf-8')

requirements.txt

+17-17
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
addict==2.2.1
2-
celery==5.2.2
3-
connexion>=2.11.2,<3.0.0
4-
cryptography==42.0.4
5-
Flask==2.2.5
6-
flask-authz==2.5.1
7-
Flask-Cors==4.0.1
8-
Flask-PyMongo==2.3.0
9-
pydantic==1.10.13
10-
PyJWT==2.4.0
11-
pymongo==4.7.2
12-
PyYAML==6.0.1
13-
requests==2.31.0
14-
swagger-ui-bundle==0.0.6
15-
toml==0.10.0
16-
typing==3.7.4.1
17-
Werkzeug>=2.2.2,<3.0.0
1+
addict~=2.2
2+
celery~=5.2
3+
connexion~=2.11
4+
cryptography~=42.0
5+
Flask~=2.2
6+
flask-authz~=2.5
7+
Flask-Cors~=4.0
8+
Flask-PyMongo~=2.3
9+
pydantic~=1.10
10+
PyJWT~=2.4
11+
pymongo~=4.7
12+
PyYAML~=6.0
13+
requests~=2.31
14+
swagger-ui-bundle~=0.0
15+
toml~=0.10
16+
typing~=3.7
17+
Werkzeug~=2.2

requirements_dev.txt

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
coverage==6.3.2
2-
flake8==4.0.1
3-
mongomock==4.0.0
4-
mypy==0.971
5-
mypy-extensions==0.4.3
6-
pylint==2.13.2
7-
pytest==7.1.1
8-
python-semantic-release==7.32.2
9-
types-PyYAML==6.0.12
10-
types-requests==2.28.11
11-
types-setuptools==65.3.0
12-
types-urllib3==1.26.25
1+
coverage>=6.5
2+
flake8>=6.1
3+
mongomock>=4.1
4+
mypy>=0.991
5+
mypy-extensions>=0.4.4
6+
pylint>=3.2
7+
pytest>=7.4
8+
python-semantic-release>=7.34,<8.2
9+
types-PyYAML
10+
types-requests
11+
types-setuptools
12+
types-urllib3

requirements_docs.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Sphinx==7.2.6
2-
readthedocs-sphinx-ext==2.2.3
3-
sphinx-rtd-theme==1.3.0
1+
Sphinx>=7.2
2+
readthedocs-sphinx-ext>=2.2
3+
sphinx-rtd-theme>=1.3

setup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@
7474
},
7575
packages=find_packages(),
7676
setup_requires=[
77-
"setuptools_git==1.2",
78-
"twine==3.8.0"
77+
"setuptools_git>=1.2",
78+
"twine>=3.8.0"
7979
],
8080
install_requires=install_requires,
8181
extras_require={
82-
"docs": docs_require,
8382
"dev": dev_requires,
83+
"docs": docs_require,
8484
},
8585
include_package_data=True,
8686
package_data={

tests/api/controllers/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ def listPets():
66

77

88
def createPets():
9-
return{}
9+
return {}
1010

1111

1212
def showPetById():
13-
return{}
13+
return {}
1414

1515

1616
def putPetsById():

tests/security/access_control/test_access_control_server.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,9 @@ def test_getAllPermissions(self):
193193
assert res == [data]
194194

195195
def test_getAllPermissions_filters(self):
196-
"""Test for getting a list of all available permissions; all defined filters
197-
specified.
196+
"""Test for getting a list of all available permissions.
197+
198+
All defined filters specified.
198199
"""
199200
app = Flask(__name__)
200201
base_config = Config(db=MongoConfig(**MONGO_CONFIG))

0 commit comments

Comments
 (0)