cardo-python-utils 0.5.dev5__tar.gz → 0.5.dev6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cardo_python_utils-0.5.dev5/cardo_python_utils.egg-info → cardo_python_utils-0.5.dev6}/PKG-INFO +8 -16
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6/cardo_python_utils.egg-info}/PKG-INFO +8 -16
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/cardo_python_utils.egg-info/SOURCES.txt +3 -4
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/cardo_python_utils.egg-info/requires.txt +7 -17
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/pyproject.toml +7 -17
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/django/keycloak/admin.py +49 -1
- cardo_python_utils-0.5.dev5/python_utils/django/auth/admin.py +0 -47
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/LICENSE +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/MANIFEST.in +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/README.rst +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/cardo_python_utils.egg-info/dependency_links.txt +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/cardo_python_utils.egg-info/top_level.txt +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/__init__.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/choices.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/data_structures.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/db.py +0 -0
- {cardo_python_utils-0.5.dev5/python_utils/django/auth → cardo_python_utils-0.5.dev6/python_utils/django/keycloak}/__init__.py +0 -0
- {cardo_python_utils-0.5.dev5/python_utils/django/auth → cardo_python_utils-0.5.dev6/python_utils/django/keycloak}/drf.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/django/keycloak/models.py +0 -0
- {cardo_python_utils-0.5.dev5/python_utils/django/auth → cardo_python_utils-0.5.dev6/python_utils/django/keycloak}/ninja.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/django/keycloak/service.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/django/keycloak/user_groups_changelist.html +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/django/utils.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/esma_choices.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/exceptions.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/imports.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/math.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/text.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/time.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/types_hinting.py +0 -0
- {cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/setup.cfg +0 -0
{cardo_python_utils-0.5.dev5/cardo_python_utils.egg-info → cardo_python_utils-0.5.dev6}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cardo-python-utils
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.dev6
|
|
4
4
|
Summary: Python library enhanced with a wide range of functions for different scenarios.
|
|
5
5
|
Author-email: CardoAI <hello@cardoai.com>
|
|
6
6
|
License: MIT
|
|
@@ -24,24 +24,16 @@ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
|
24
24
|
Requires-Python: >=3.8
|
|
25
25
|
Description-Content-Type: text/x-rst
|
|
26
26
|
License-File: LICENSE
|
|
27
|
-
Provides-Extra: django
|
|
28
|
-
Requires-Dist:
|
|
29
|
-
Provides-Extra: django-
|
|
30
|
-
Requires-Dist:
|
|
31
|
-
Requires-Dist: django-ninja; extra == "django-ninja"
|
|
32
|
-
Requires-Dist: PyJWT; extra == "django-ninja"
|
|
33
|
-
Provides-Extra: drf
|
|
34
|
-
Requires-Dist: Django; extra == "drf"
|
|
35
|
-
Requires-Dist: djangorestframework; extra == "drf"
|
|
36
|
-
Requires-Dist: PyJWT; extra == "drf"
|
|
37
|
-
Provides-Extra: django-admin-auth
|
|
38
|
-
Requires-Dist: Django; extra == "django-admin-auth"
|
|
39
|
-
Requires-Dist: mozilla-django-oidc>=4.0.1; extra == "django-admin-auth"
|
|
27
|
+
Provides-Extra: django-keycloak-api
|
|
28
|
+
Requires-Dist: PyJWT>=2.10.1; extra == "django-keycloak-api"
|
|
29
|
+
Provides-Extra: django-keycloak-admin
|
|
30
|
+
Requires-Dist: mozilla-django-oidc>=4.0.1; extra == "django-keycloak-admin"
|
|
40
31
|
Provides-Extra: django-keycloak-groups
|
|
41
|
-
Requires-Dist: Django; extra == "django-keycloak-groups"
|
|
42
32
|
Requires-Dist: python-keycloak>=5.8.1; extra == "django-keycloak-groups"
|
|
43
33
|
Provides-Extra: all
|
|
44
|
-
Requires-Dist:
|
|
34
|
+
Requires-Dist: PyJWT>=2.10.1; extra == "all"
|
|
35
|
+
Requires-Dist: mozilla-django-oidc>=4.0.1; extra == "all"
|
|
36
|
+
Requires-Dist: python-keycloak>=5.8.1; extra == "all"
|
|
45
37
|
Provides-Extra: dev
|
|
46
38
|
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
47
39
|
Requires-Dist: pytest-django>=4.5; extra == "dev"
|
{cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6/cardo_python_utils.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cardo-python-utils
|
|
3
|
-
Version: 0.5.
|
|
3
|
+
Version: 0.5.dev6
|
|
4
4
|
Summary: Python library enhanced with a wide range of functions for different scenarios.
|
|
5
5
|
Author-email: CardoAI <hello@cardoai.com>
|
|
6
6
|
License: MIT
|
|
@@ -24,24 +24,16 @@ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
|
|
|
24
24
|
Requires-Python: >=3.8
|
|
25
25
|
Description-Content-Type: text/x-rst
|
|
26
26
|
License-File: LICENSE
|
|
27
|
-
Provides-Extra: django
|
|
28
|
-
Requires-Dist:
|
|
29
|
-
Provides-Extra: django-
|
|
30
|
-
Requires-Dist:
|
|
31
|
-
Requires-Dist: django-ninja; extra == "django-ninja"
|
|
32
|
-
Requires-Dist: PyJWT; extra == "django-ninja"
|
|
33
|
-
Provides-Extra: drf
|
|
34
|
-
Requires-Dist: Django; extra == "drf"
|
|
35
|
-
Requires-Dist: djangorestframework; extra == "drf"
|
|
36
|
-
Requires-Dist: PyJWT; extra == "drf"
|
|
37
|
-
Provides-Extra: django-admin-auth
|
|
38
|
-
Requires-Dist: Django; extra == "django-admin-auth"
|
|
39
|
-
Requires-Dist: mozilla-django-oidc>=4.0.1; extra == "django-admin-auth"
|
|
27
|
+
Provides-Extra: django-keycloak-api
|
|
28
|
+
Requires-Dist: PyJWT>=2.10.1; extra == "django-keycloak-api"
|
|
29
|
+
Provides-Extra: django-keycloak-admin
|
|
30
|
+
Requires-Dist: mozilla-django-oidc>=4.0.1; extra == "django-keycloak-admin"
|
|
40
31
|
Provides-Extra: django-keycloak-groups
|
|
41
|
-
Requires-Dist: Django; extra == "django-keycloak-groups"
|
|
42
32
|
Requires-Dist: python-keycloak>=5.8.1; extra == "django-keycloak-groups"
|
|
43
33
|
Provides-Extra: all
|
|
44
|
-
Requires-Dist:
|
|
34
|
+
Requires-Dist: PyJWT>=2.10.1; extra == "all"
|
|
35
|
+
Requires-Dist: mozilla-django-oidc>=4.0.1; extra == "all"
|
|
36
|
+
Requires-Dist: python-keycloak>=5.8.1; extra == "all"
|
|
45
37
|
Provides-Extra: dev
|
|
46
38
|
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
47
39
|
Requires-Dist: pytest-django>=4.5; extra == "dev"
|
{cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/cardo_python_utils.egg-info/SOURCES.txt
RENAMED
|
@@ -19,11 +19,10 @@ python_utils/text.py
|
|
|
19
19
|
python_utils/time.py
|
|
20
20
|
python_utils/types_hinting.py
|
|
21
21
|
python_utils/django/utils.py
|
|
22
|
-
python_utils/django/
|
|
23
|
-
python_utils/django/auth/admin.py
|
|
24
|
-
python_utils/django/auth/drf.py
|
|
25
|
-
python_utils/django/auth/ninja.py
|
|
22
|
+
python_utils/django/keycloak/__init__.py
|
|
26
23
|
python_utils/django/keycloak/admin.py
|
|
24
|
+
python_utils/django/keycloak/drf.py
|
|
27
25
|
python_utils/django/keycloak/models.py
|
|
26
|
+
python_utils/django/keycloak/ninja.py
|
|
28
27
|
python_utils/django/keycloak/service.py
|
|
29
28
|
python_utils/django/keycloak/user_groups_changelist.html
|
{cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/cardo_python_utils.egg-info/requires.txt
RENAMED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
[all]
|
|
3
|
-
|
|
3
|
+
PyJWT>=2.10.1
|
|
4
|
+
mozilla-django-oidc>=4.0.1
|
|
5
|
+
python-keycloak>=5.8.1
|
|
4
6
|
|
|
5
7
|
[dev]
|
|
6
8
|
pytest>=7.0
|
|
@@ -8,23 +10,11 @@ pytest-django>=4.5
|
|
|
8
10
|
coverage>=6.0
|
|
9
11
|
tox>=3.25
|
|
10
12
|
|
|
11
|
-
[django]
|
|
12
|
-
Django
|
|
13
|
-
|
|
14
|
-
[django-admin-auth]
|
|
15
|
-
Django
|
|
13
|
+
[django-keycloak-admin]
|
|
16
14
|
mozilla-django-oidc>=4.0.1
|
|
17
15
|
|
|
16
|
+
[django-keycloak-api]
|
|
17
|
+
PyJWT>=2.10.1
|
|
18
|
+
|
|
18
19
|
[django-keycloak-groups]
|
|
19
|
-
Django
|
|
20
20
|
python-keycloak>=5.8.1
|
|
21
|
-
|
|
22
|
-
[django-ninja]
|
|
23
|
-
Django
|
|
24
|
-
django-ninja
|
|
25
|
-
PyJWT
|
|
26
|
-
|
|
27
|
-
[drf]
|
|
28
|
-
Django
|
|
29
|
-
djangorestframework
|
|
30
|
-
PyJWT
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cardo-python-utils"
|
|
7
|
-
version = "0.5.
|
|
7
|
+
version = "0.5.dev6"
|
|
8
8
|
description = "Python library enhanced with a wide range of functions for different scenarios."
|
|
9
9
|
readme = "README.rst"
|
|
10
10
|
requires-python = ">=3.8"
|
|
@@ -31,29 +31,19 @@ classifiers = [
|
|
|
31
31
|
dependencies = []
|
|
32
32
|
|
|
33
33
|
[project.optional-dependencies]
|
|
34
|
-
django = [
|
|
35
|
-
"
|
|
34
|
+
django-keycloak-api = [
|
|
35
|
+
"PyJWT>=2.10.1",
|
|
36
36
|
]
|
|
37
|
-
django-
|
|
38
|
-
"Django",
|
|
39
|
-
"django-ninja",
|
|
40
|
-
"PyJWT",
|
|
41
|
-
]
|
|
42
|
-
drf = [
|
|
43
|
-
"Django",
|
|
44
|
-
"djangorestframework",
|
|
45
|
-
"PyJWT",
|
|
46
|
-
]
|
|
47
|
-
django-admin-auth = [
|
|
48
|
-
"Django",
|
|
37
|
+
django-keycloak-admin = [
|
|
49
38
|
"mozilla-django-oidc>=4.0.1",
|
|
50
39
|
]
|
|
51
40
|
django-keycloak-groups = [
|
|
52
|
-
"Django",
|
|
53
41
|
"python-keycloak>=5.8.1",
|
|
54
42
|
]
|
|
55
43
|
all = [
|
|
56
|
-
"
|
|
44
|
+
"PyJWT>=2.10.1",
|
|
45
|
+
"mozilla-django-oidc>=4.0.1",
|
|
46
|
+
"python-keycloak>=5.8.1",
|
|
57
47
|
]
|
|
58
48
|
dev = [
|
|
59
49
|
"pytest>=7.0",
|
{cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/django/keycloak/admin.py
RENAMED
|
@@ -1,16 +1,64 @@
|
|
|
1
|
+
from django.conf import settings
|
|
1
2
|
from django.contrib import admin, messages
|
|
2
3
|
from django.core.cache import cache
|
|
3
4
|
from django.urls import path
|
|
4
5
|
from django.shortcuts import redirect
|
|
6
|
+
from mozilla_django_oidc.auth import OIDCAuthenticationBackend
|
|
5
7
|
|
|
6
8
|
from .service import KeycloakService
|
|
7
9
|
|
|
8
10
|
|
|
11
|
+
class KeycloakAuthenticationBackend(OIDCAuthenticationBackend):
|
|
12
|
+
def _get_user_data(self, claims) -> dict:
|
|
13
|
+
client_roles = (
|
|
14
|
+
claims.get("resource_access", {})
|
|
15
|
+
.get(getattr(settings, "OIDC_RP_CLIENT_ID", ""), {})
|
|
16
|
+
.get("roles", [])
|
|
17
|
+
)
|
|
18
|
+
is_superuser = "Admin" in client_roles
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
"username": claims.get("preferred_username"),
|
|
22
|
+
"email": claims.get("email"),
|
|
23
|
+
"first_name": claims.get("given_name", ""),
|
|
24
|
+
"last_name": claims.get("family_name", ""),
|
|
25
|
+
"is_staff": claims.get("is_staff", False),
|
|
26
|
+
"is_superuser": is_superuser,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
def filter_users_by_claims(self, claims):
|
|
30
|
+
username = claims.get("preferred_username")
|
|
31
|
+
if not username:
|
|
32
|
+
return self.UserModel.objects.none()
|
|
33
|
+
return self.UserModel.objects.filter(username=username)
|
|
34
|
+
|
|
35
|
+
def create_user(self, claims):
|
|
36
|
+
return self.UserModel.objects.create_user(**self._get_user_data(claims))
|
|
37
|
+
|
|
38
|
+
def update_user(self, user, claims):
|
|
39
|
+
save_needed = False
|
|
40
|
+
|
|
41
|
+
for attr, value in self._get_user_data(claims).items():
|
|
42
|
+
if getattr(user, attr) != value:
|
|
43
|
+
setattr(user, attr, value)
|
|
44
|
+
save_needed = True
|
|
45
|
+
|
|
46
|
+
if save_needed:
|
|
47
|
+
user.save()
|
|
48
|
+
|
|
49
|
+
return user
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def has_admin_site_permission(request):
|
|
53
|
+
"""Admin site is not publicly accessible."""
|
|
54
|
+
return request.user.is_active
|
|
55
|
+
|
|
56
|
+
|
|
9
57
|
class UserGroupAdminBase(admin.ModelAdmin):
|
|
10
58
|
list_display = ("path",)
|
|
11
59
|
search_fields = ("id", "path")
|
|
12
60
|
readonly_fields = ("id", "path")
|
|
13
|
-
|
|
61
|
+
|
|
14
62
|
# To show ManyToMany fields with a horizontal filter widget
|
|
15
63
|
# filter_horizontal = ("allowed_entities",)
|
|
16
64
|
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
from django.conf import settings
|
|
2
|
-
from mozilla_django_oidc.auth import OIDCAuthenticationBackend
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
class OIDCCustomAuthenticationBackend(OIDCAuthenticationBackend):
|
|
6
|
-
def _get_user_data(self, claims) -> dict:
|
|
7
|
-
client_roles = (
|
|
8
|
-
claims.get("resource_access", {})
|
|
9
|
-
.get(getattr(settings, "OIDC_RP_CLIENT_ID", ""), {})
|
|
10
|
-
.get("roles", [])
|
|
11
|
-
)
|
|
12
|
-
is_superuser = "Admin" in client_roles
|
|
13
|
-
|
|
14
|
-
return {
|
|
15
|
-
"username": claims.get("preferred_username"),
|
|
16
|
-
"email": claims.get("email"),
|
|
17
|
-
"first_name": claims.get("given_name", ""),
|
|
18
|
-
"last_name": claims.get("family_name", ""),
|
|
19
|
-
"is_staff": claims.get("is_staff", False),
|
|
20
|
-
"is_superuser": is_superuser,
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
def filter_users_by_claims(self, claims):
|
|
24
|
-
username = claims.get("preferred_username")
|
|
25
|
-
if not username:
|
|
26
|
-
return self.UserModel.objects.none()
|
|
27
|
-
return self.UserModel.objects.filter(username=username)
|
|
28
|
-
|
|
29
|
-
def create_user(self, claims):
|
|
30
|
-
return self.UserModel.objects.create_user(**self._get_user_data(claims))
|
|
31
|
-
|
|
32
|
-
def update_user(self, user, claims):
|
|
33
|
-
save_needed = False
|
|
34
|
-
|
|
35
|
-
for attr, value in self._get_user_data(claims).items():
|
|
36
|
-
if getattr(user, attr) != value:
|
|
37
|
-
setattr(user, attr, value)
|
|
38
|
-
save_needed = True
|
|
39
|
-
|
|
40
|
-
if save_needed:
|
|
41
|
-
user.save()
|
|
42
|
-
|
|
43
|
-
return user
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def has_permission(request):
|
|
47
|
-
return request.user.is_active
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/django/keycloak/models.py
RENAMED
|
File without changes
|
|
File without changes
|
{cardo_python_utils-0.5.dev5 → cardo_python_utils-0.5.dev6}/python_utils/django/keycloak/service.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|