Skip to content

Commit

Permalink
fix: small bugs, use ruff as linter, added annotations
Browse files Browse the repository at this point in the history
* fix: ruffing up

* test: linting done

* fix: tests and code

* fix: new docs

* docs: updated conf

* docs: update
  • Loading branch information
ryshoooo authored Jan 26, 2025
1 parent f0a82a6 commit 327efd8
Show file tree
Hide file tree
Showing 30 changed files with 6,303 additions and 3,791 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ main2.py
s3air-authz-config.json
.vscode
_build

.ruff_cache
.DS_Store

test.py
7 changes: 5 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
version: 2

sphinx:
configuration: docs/source/conf.py

build:
os: "ubuntu-22.04"
os: "ubuntu-24.04"
tools:
python: "3.12"
python: "3.13"
jobs:
post_create_environment:
- python -m pip install poetry
Expand Down
9 changes: 4 additions & 5 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# python-keycloak documentation build configuration file, created by
# sphinx-quickstart on Tue Aug 15 11:02:59 2017.
Expand Down Expand Up @@ -101,12 +100,12 @@
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"
html_theme = "sphinx_book_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#

# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
Expand Down Expand Up @@ -169,7 +168,7 @@
"python-keycloak Documentation",
"Marcos Pereira",
"manual",
)
),
]


Expand All @@ -194,5 +193,5 @@
"python-keycloak",
"One line description of project.",
"Miscellaneous",
)
),
]
1,049 changes: 536 additions & 513 deletions poetry.lock

Large diffs are not rendered by default.

35 changes: 23 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ deprecation = ">=2.1.0"
jwcrypto = ">=1.5.4"
httpx = ">=0.23.2"
async-property = ">=0.2.2"
aiofiles = ">=24.1.0"

[tool.poetry.group.docs.dependencies]
alabaster = ">=0.7.0"
commonmark = ">=0.9.1"
recommonmark = ">=0.7.1"
Sphinx = ">=7.0.0"
sphinx-rtd-theme = ">=1.0.0"
readthedocs-sphinx-ext = ">=2.1.9"
m2r2 = ">=0.3.2"
sphinx-autoapi = ">=3.0.0"
setuptools = ">=70.0.0"
sphinx-book-theme = ">=1.1.3"

[tool.poetry.group.dev.dependencies]
tox = ">=4.0.0"
Expand All @@ -56,17 +56,14 @@ pytest-cov = ">=3.0.0"
pytest-asyncio = ">=0.23.7"
wheel = ">=0.38.4"
pre-commit = ">=3.5.0"
isort = ">=5.10.1"
black = ">=22.3.0"
flake8 = ">=7.0.0"
flake8-docstrings = ">=1.6.0"
commitizen = ">=2.28.0"
cryptography = ">=42.0.0"
codespell = ">=2.1.0"
darglint = ">=1.8.1"
twine = ">=4.0.2"
freezegun = ">=1.2.2"
docutils = "<0.21"
ruff = ">=0.9.3"

[[tool.poetry.source]]
name = "PyPI"
Expand All @@ -76,15 +73,29 @@ priority = "primary"
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.black]
[tool.ruff]
line-length = 99

[tool.isort]
line_length = 99
profile = "black"
[tool.ruff.lint]
select = ["ALL"]
ignore = [
"BLE001",
"C901",
"D203",
"D212",
"FBT001",
"FBT002",
"FBT003",
"N818",
"PLR0912",
"PLR0913",
"PLR0915",
"TRY003",
]

[tool.darglint]
enable = "DAR104"
[tool.ruff.lint.per-file-ignores]
"tests/*" = ["ARG001","PLR2004", "PT011", "S101", "SLF001"]
"docs/*" = ["A001", "EXE001", "ERA001"]

[tool.pytest.ini_options]
asyncio_default_fixture_loop_scope = "function"
9 changes: 4 additions & 5 deletions src/keycloak/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# The MIT License (MIT)
#
Expand Down Expand Up @@ -46,8 +45,8 @@
from .openid_connection import KeycloakOpenIDConnection

__all__ = [
"__version__",
"ConnectionManager",
"KeycloakAdmin",
"KeycloakAuthenticationError",
"KeycloakAuthorizationConfigError",
"KeycloakConnectionError",
Expand All @@ -56,13 +55,13 @@
"KeycloakError",
"KeycloakGetError",
"KeycloakInvalidTokenError",
"KeycloakOpenID",
"KeycloakOpenIDConnection",
"KeycloakOperationError",
"KeycloakPostError",
"KeycloakPutError",
"KeycloakRPTNotFound",
"KeycloakSecretNotFound",
"KeycloakAdmin",
"KeycloakOpenID",
"KeycloakOpenIDConnection",
"KeycloakUMA",
"__version__",
]
1 change: 0 additions & 1 deletion src/keycloak/_version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# The MIT License (MIT)
#
Expand Down
18 changes: 10 additions & 8 deletions src/keycloak/authorization/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# The MIT License (MIT)
#
Expand Down Expand Up @@ -32,31 +31,34 @@


class Authorization:
"""Keycloak Authorization (policies, roles, scopes and resources).
"""
Keycloak Authorization (policies, roles, scopes and resources).
https://keycloak.gitbooks.io/documentation/authorization_services/index.html
"""

def __init__(self):
def __init__(self) -> None:
"""Init method."""
self.policies = {}

@property
def policies(self):
"""Get policies.
def policies(self) -> dict:
"""
Get policies.
:returns: Policies
:rtype: dict
"""
return self._policies

@policies.setter
def policies(self, value):
def policies(self, value: dict) -> None:
self._policies = value

def load_config(self, data):
"""Load policies, roles and permissions (scope/resources).
def load_config(self, data: dict) -> None:
"""
Load policies, roles and permissions (scope/resources).
:param data: keycloak authorization data (dict)
:type data: dict
Expand Down
65 changes: 37 additions & 28 deletions src/keycloak/authorization/permission.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# The MIT License (MIT)
#
Expand All @@ -25,7 +24,8 @@


class Permission:
"""Base permission class.
"""
Base permission class.
Consider this simple and very common permission:
Expand Down Expand Up @@ -56,8 +56,9 @@ class Permission:
"""

def __init__(self, name, type, logic, decision_strategy):
"""Init method.
def __init__(self, name: str, type: str, logic: str, decision_strategy: str) -> None: # noqa: A002
"""
Init method.
:param name: Name
:type name: str
Expand All @@ -75,96 +76,104 @@ def __init__(self, name, type, logic, decision_strategy):
self.resources = []
self.scopes = []

def __repr__(self):
"""Repr method.
def __repr__(self) -> str:
"""
Repr method.
:returns: Class representation
:rtype: str
"""
return "<Permission: %s (%s)>" % (self.name, self.type)
return f"<Permission: {self.name} ({self.type})>"

def __str__(self):
"""Str method.
def __str__(self) -> str:
"""
Str method.
:returns: Class string representation
:rtype: str
"""
return "Permission: %s (%s)" % (self.name, self.type)
return f"Permission: {self.name} ({self.type})"

@property
def name(self):
"""Get name.
def name(self) -> str:
"""
Get name.
:returns: name
:rtype: str
"""
return self._name

@name.setter
def name(self, value):
def name(self, value: str) -> None:
self._name = value

@property
def type(self):
"""Get type.
def type(self) -> str:
"""
Get type.
:returns: type
:rtype: str
"""
return self._type

@type.setter
def type(self, value):
def type(self, value: str) -> None:
self._type = value

@property
def logic(self):
"""Get logic.
def logic(self) -> str:
"""
Get logic.
:returns: Logic
:rtype: str
"""
return self._logic

@logic.setter
def logic(self, value):
def logic(self, value: str) -> str:
self._logic = value

@property
def decision_strategy(self):
"""Get decision strategy.
def decision_strategy(self) -> str:
"""
Get decision strategy.
:returns: Decision strategy
:rtype: str
"""
return self._decision_strategy

@decision_strategy.setter
def decision_strategy(self, value):
def decision_strategy(self, value: str) -> None:
self._decision_strategy = value

@property
def resources(self):
"""Get resources.
def resources(self) -> list:
"""
Get resources.
:returns: Resources
:rtype: list
"""
return self._resources

@resources.setter
def resources(self, value):
def resources(self, value: list) -> None:
self._resources = value

@property
def scopes(self):
"""Get scopes.
def scopes(self) -> list:
"""
Get scopes.
:returns: Scopes
:rtype: list
"""
return self._scopes

@scopes.setter
def scopes(self, value):
def scopes(self, value: list) -> None:
self._scopes = value
Loading

0 comments on commit 327efd8

Please sign in to comment.