ebesha-core-engine 0.1.1__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.
Files changed (31) hide show
  1. ebesha_core_engine-0.1.1/PKG-INFO +80 -0
  2. ebesha_core_engine-0.1.1/README.md +49 -0
  3. ebesha_core_engine-0.1.1/core_engine/__init__.py +0 -0
  4. ebesha_core_engine-0.1.1/core_engine/auth/__init__.py +0 -0
  5. ebesha_core_engine-0.1.1/core_engine/auth/services.py +50 -0
  6. ebesha_core_engine-0.1.1/core_engine/bridges/__init__.py +0 -0
  7. ebesha_core_engine-0.1.1/core_engine/bridges/access.py +47 -0
  8. ebesha_core_engine-0.1.1/core_engine/bridges/integration.py +484 -0
  9. ebesha_core_engine-0.1.1/core_engine/caches/__init__.py +0 -0
  10. ebesha_core_engine-0.1.1/core_engine/caches/services.py +110 -0
  11. ebesha_core_engine-0.1.1/core_engine/connection.py +895 -0
  12. ebesha_core_engine-0.1.1/core_engine/connectivity/__init__.py +0 -0
  13. ebesha_core_engine-0.1.1/core_engine/connectivity/query_builder.py +83 -0
  14. ebesha_core_engine-0.1.1/core_engine/connectivity/services.py +307 -0
  15. ebesha_core_engine-0.1.1/core_engine/constants.py +987 -0
  16. ebesha_core_engine-0.1.1/core_engine/custom_query/__init__.py +0 -0
  17. ebesha_core_engine-0.1.1/core_engine/external_integration/__init__.py +0 -0
  18. ebesha_core_engine-0.1.1/core_engine/external_integration/services.py +569 -0
  19. ebesha_core_engine-0.1.1/core_engine/queueing/__init__.py +0 -0
  20. ebesha_core_engine-0.1.1/core_engine/queueing/queue.py +425 -0
  21. ebesha_core_engine-0.1.1/core_engine/utilities/__init__.py +0 -0
  22. ebesha_core_engine-0.1.1/core_engine/utilities/paginations.py +35 -0
  23. ebesha_core_engine-0.1.1/core_engine/utilities/utils.py +197 -0
  24. ebesha_core_engine-0.1.1/core_engine/utilities/validator.py +155 -0
  25. ebesha_core_engine-0.1.1/ebesha_core_engine.egg-info/PKG-INFO +80 -0
  26. ebesha_core_engine-0.1.1/ebesha_core_engine.egg-info/SOURCES.txt +29 -0
  27. ebesha_core_engine-0.1.1/ebesha_core_engine.egg-info/dependency_links.txt +1 -0
  28. ebesha_core_engine-0.1.1/ebesha_core_engine.egg-info/requires.txt +22 -0
  29. ebesha_core_engine-0.1.1/ebesha_core_engine.egg-info/top_level.txt +1 -0
  30. ebesha_core_engine-0.1.1/pyproject.toml +43 -0
  31. ebesha_core_engine-0.1.1/setup.cfg +4 -0
@@ -0,0 +1,80 @@
1
+ Metadata-Version: 2.4
2
+ Name: ebesha-core-engine
3
+ Version: 0.1.1
4
+ Summary: Modular core engine for Python microservices
5
+ Author-email: Lintas Media Danawa <hello@ebesha.net>
6
+ License: LMD
7
+ Requires-Python: >=3.12
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: cryptography>=44.0.0
10
+ Requires-Dist: djangorestframework>=3.15.2
11
+ Requires-Dist: django-celery-beat>=2.7.0
12
+ Requires-Dist: django-cors-headers>=4.6.0
13
+ Requires-Dist: django-extensions>=3.2.3
14
+ Requires-Dist: django-filter>=24.3
15
+ Requires-Dist: django-request-logging>=0.7.5
16
+ Requires-Dist: django-rest-swagger>=2.2.0
17
+ Requires-Dist: django-timezone-field>=7.1
18
+ Requires-Dist: django-user-agents>=0.4.0
19
+ Requires-Dist: djangorestframework>=3.15.2
20
+ Requires-Dist: djangorestframework-recursive>=0.1.2
21
+ Requires-Dist: amqp>=5.3.1
22
+ Requires-Dist: jwt>=1.3.1
23
+ Requires-Dist: kombu>=5.4.2
24
+ Requires-Dist: pika>=1.3.2
25
+ Requires-Dist: python-dotenv>=1.1.0
26
+ Requires-Dist: typer>=0.15.4
27
+ Requires-Dist: psycopg2>=2.9
28
+ Requires-Dist: redis>=5.2.1
29
+ Requires-Dist: requests>=2.32.3
30
+ Requires-Dist: celery>=5.4.0
31
+
32
+ # core_engine
33
+
34
+ Modular core engine for Python-based microservices.
35
+ This package provides reusable components such as authentication, caching, database connectivity, queue management, and external integrations.
36
+
37
+ ---
38
+
39
+ ## 📦 Features
40
+
41
+ - **Authentication (`auth`)**
42
+ Handle user authentication logic and services.
43
+
44
+ - **Bridges (`bridges`)**
45
+ Communication logic between internal modules.
46
+ - `module`: Handles system integration logic.
47
+ - `user_management`: Manages user access control.
48
+
49
+ - **Caching (`caches`)**
50
+ Redis-based caching services.
51
+
52
+ - **Database Connectivity (`connectivity`)**
53
+ Abstractions for building and running database queries.
54
+
55
+ - **Custom Query (`custom_query`)**
56
+ Contains raw SQL files and custom database queries.
57
+
58
+ - **External Integration (`external_integration`)**
59
+ Handles API and service communication with external systems.
60
+
61
+ - **Queueing (`queueing`)**
62
+ RabbitMQ or similar queue implementations.
63
+
64
+ - **Utilities (`utilities`)**
65
+ Helper functions such as validation, pagination, etc.
66
+
67
+ - **Connection Modules**
68
+ Shared connection helpers:
69
+ - `connection.py`: DB or external service connection.
70
+ - `constants.py`: Shared constant values.
71
+
72
+ ---
73
+
74
+ ## 🛠️ Installation
75
+
76
+ Make sure you have Python 3.8+ and `pip`.
77
+
78
+ ```bash
79
+ # Install as package
80
+ pip install .
@@ -0,0 +1,49 @@
1
+ # core_engine
2
+
3
+ Modular core engine for Python-based microservices.
4
+ This package provides reusable components such as authentication, caching, database connectivity, queue management, and external integrations.
5
+
6
+ ---
7
+
8
+ ## 📦 Features
9
+
10
+ - **Authentication (`auth`)**
11
+ Handle user authentication logic and services.
12
+
13
+ - **Bridges (`bridges`)**
14
+ Communication logic between internal modules.
15
+ - `module`: Handles system integration logic.
16
+ - `user_management`: Manages user access control.
17
+
18
+ - **Caching (`caches`)**
19
+ Redis-based caching services.
20
+
21
+ - **Database Connectivity (`connectivity`)**
22
+ Abstractions for building and running database queries.
23
+
24
+ - **Custom Query (`custom_query`)**
25
+ Contains raw SQL files and custom database queries.
26
+
27
+ - **External Integration (`external_integration`)**
28
+ Handles API and service communication with external systems.
29
+
30
+ - **Queueing (`queueing`)**
31
+ RabbitMQ or similar queue implementations.
32
+
33
+ - **Utilities (`utilities`)**
34
+ Helper functions such as validation, pagination, etc.
35
+
36
+ - **Connection Modules**
37
+ Shared connection helpers:
38
+ - `connection.py`: DB or external service connection.
39
+ - `constants.py`: Shared constant values.
40
+
41
+ ---
42
+
43
+ ## 🛠️ Installation
44
+
45
+ Make sure you have Python 3.8+ and `pip`.
46
+
47
+ ```bash
48
+ # Install as package
49
+ pip install .
File without changes
File without changes
@@ -0,0 +1,50 @@
1
+ import os
2
+ import jwt
3
+ from core_engine.caches.services import CacheServices
4
+ from datetime import datetime, timedelta
5
+
6
+ from core_engine.bridges.access import UserManagement
7
+
8
+ caches = {}
9
+
10
+ class AuthorizationService(object):
11
+ def __init__(self):
12
+ self.cache_services = CacheServices()
13
+
14
+ def get_access(self, token, module, access, tenant=None):
15
+ datas = self._caching_autorization(token, module, access, tenant)
16
+ return self._decode_access(datas)
17
+
18
+ def _decode_access(self, datas):
19
+ if datas.get('status') == 200:
20
+ jwt_token = bytes(datas.get('data').get('detail'), 'utf-8')
21
+ results = {"status":datas.get('status'), "detail":jwt.decode(jwt_token, os.environ.get("JWT_TOKEN"), algorithms=['HS256'])}
22
+ return results
23
+ return datas
24
+
25
+ def _caching_autorization(self, token, module, access, tenant=None):
26
+ '''if caches.get(f"{token}|{module}|{access}{tenant}"):
27
+ if caches.get(f"{token}|{module}|{access}{tenant}").get('detail').get('status') == 200:
28
+ if (datetime.now() - caches.get(f"{token}|{module}|{access}{tenant}").get('last_date')) > (timedelta(0, int(os.environ.get("CACHE_IDLE")) * 60, 0)):
29
+ del caches[f"{token}|{module}|{access}{tenant}"]
30
+ return self._request_access(token, module, access, tenant)
31
+ else:
32
+ return self._request_access(token, module, access, tenant)
33
+ return caches.get(f"{token}|{module}|{access}{tenant}").get('detail')
34
+ else:
35
+ return self._request_access(token, module, access, tenant)'''
36
+ data_cache = self.cache_services.get_idle_caches(f"{module}_{tenant}_{token}_{access}")
37
+ if data_cache:
38
+ if data_cache.get('detail').get('status') == 200:
39
+ return data_cache.get('detail')
40
+ else:
41
+ return self._request_access(token, module, access, tenant)
42
+ else:
43
+ return self._request_access(token, module, access, tenant)
44
+
45
+ def _request_access(self, token, module, access, tenant=None):
46
+ user_management_client = UserManagement(token, module, access, tenant)
47
+ datas = user_management_client.check_token()
48
+ #caches.update({f"{token}|{module}|{access}{tenant}":{"module":module, "access":access, "last_date":datetime.now(), "detail":datas}})
49
+ self.cache_services.set_idle_caches(f"{module}_{tenant}_{token}_{access}", {"module":module, "access":access, "detail":datas})
50
+ return datas
@@ -0,0 +1,47 @@
1
+ import json
2
+ import requests
3
+ from core_engine.constants import (
4
+ MappingPathAPI
5
+ )
6
+
7
+ class UserManagement(object):
8
+ def __init__(self, token, module, access, tenant=None):
9
+ self.token = token
10
+ self.module = module
11
+ self.access = access
12
+ self.tenant = tenant
13
+
14
+ def _construct_response(self, resp):
15
+ if resp.status_code==200:
16
+ response = dict(
17
+ status=resp.status_code,
18
+ data=resp.json()
19
+ )
20
+ return response
21
+ else:
22
+ response = dict(
23
+ status=resp.status_code,
24
+ detail=resp.json()
25
+ )
26
+ return response
27
+
28
+ def _construct_responses(self, status, resp):
29
+ response = dict(
30
+ status=status,
31
+ data=resp
32
+ )
33
+ return response
34
+
35
+ def check_token(self):
36
+ try:
37
+ headers = dict(
38
+ Authorization=self.token
39
+ )
40
+ body = dict(module=self.module, access=self.access, tenant=self.tenant)
41
+ res = requests.post(url=f"{MappingPathAPI.path.get('valid_token')}", headers=headers, data=body)
42
+
43
+ response = self._construct_response(res)
44
+ return response
45
+ except Exception as err:
46
+ message = {"status":"400", "detail":str(err).split("\n")}
47
+ return message