miso-client 0.1.0__py3-none-any.whl → 3.7.2__py3-none-any.whl

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 (69) hide show
  1. miso_client/__init__.py +523 -130
  2. miso_client/api/__init__.py +35 -0
  3. miso_client/api/auth_api.py +367 -0
  4. miso_client/api/logs_api.py +91 -0
  5. miso_client/api/permissions_api.py +88 -0
  6. miso_client/api/roles_api.py +88 -0
  7. miso_client/api/types/__init__.py +75 -0
  8. miso_client/api/types/auth_types.py +183 -0
  9. miso_client/api/types/logs_types.py +71 -0
  10. miso_client/api/types/permissions_types.py +31 -0
  11. miso_client/api/types/roles_types.py +31 -0
  12. miso_client/errors.py +30 -4
  13. miso_client/models/__init__.py +4 -0
  14. miso_client/models/config.py +275 -72
  15. miso_client/models/error_response.py +39 -0
  16. miso_client/models/filter.py +255 -0
  17. miso_client/models/pagination.py +44 -0
  18. miso_client/models/sort.py +25 -0
  19. miso_client/services/__init__.py +6 -5
  20. miso_client/services/auth.py +496 -87
  21. miso_client/services/cache.py +42 -41
  22. miso_client/services/encryption.py +18 -17
  23. miso_client/services/logger.py +467 -328
  24. miso_client/services/logger_chain.py +288 -0
  25. miso_client/services/permission.py +130 -67
  26. miso_client/services/redis.py +28 -23
  27. miso_client/services/role.py +145 -62
  28. miso_client/utils/__init__.py +3 -3
  29. miso_client/utils/audit_log_queue.py +222 -0
  30. miso_client/utils/auth_strategy.py +88 -0
  31. miso_client/utils/auth_utils.py +65 -0
  32. miso_client/utils/circuit_breaker.py +125 -0
  33. miso_client/utils/client_token_manager.py +244 -0
  34. miso_client/utils/config_loader.py +88 -17
  35. miso_client/utils/controller_url_resolver.py +80 -0
  36. miso_client/utils/data_masker.py +104 -33
  37. miso_client/utils/environment_token.py +126 -0
  38. miso_client/utils/error_utils.py +216 -0
  39. miso_client/utils/fastapi_endpoints.py +166 -0
  40. miso_client/utils/filter.py +364 -0
  41. miso_client/utils/filter_applier.py +143 -0
  42. miso_client/utils/filter_parser.py +110 -0
  43. miso_client/utils/flask_endpoints.py +169 -0
  44. miso_client/utils/http_client.py +494 -262
  45. miso_client/utils/http_client_logging.py +352 -0
  46. miso_client/utils/http_client_logging_helpers.py +197 -0
  47. miso_client/utils/http_client_query_helpers.py +138 -0
  48. miso_client/utils/http_error_handler.py +92 -0
  49. miso_client/utils/http_log_formatter.py +115 -0
  50. miso_client/utils/http_log_masker.py +203 -0
  51. miso_client/utils/internal_http_client.py +435 -0
  52. miso_client/utils/jwt_tools.py +125 -16
  53. miso_client/utils/logger_helpers.py +206 -0
  54. miso_client/utils/logging_helpers.py +70 -0
  55. miso_client/utils/origin_validator.py +128 -0
  56. miso_client/utils/pagination.py +275 -0
  57. miso_client/utils/request_context.py +285 -0
  58. miso_client/utils/sensitive_fields_loader.py +116 -0
  59. miso_client/utils/sort.py +116 -0
  60. miso_client/utils/token_utils.py +114 -0
  61. miso_client/utils/url_validator.py +66 -0
  62. miso_client/utils/user_token_refresh.py +245 -0
  63. miso_client-3.7.2.dist-info/METADATA +1021 -0
  64. miso_client-3.7.2.dist-info/RECORD +68 -0
  65. miso_client-0.1.0.dist-info/METADATA +0 -551
  66. miso_client-0.1.0.dist-info/RECORD +0 -23
  67. {miso_client-0.1.0.dist-info → miso_client-3.7.2.dist-info}/WHEEL +0 -0
  68. {miso_client-0.1.0.dist-info → miso_client-3.7.2.dist-info}/licenses/LICENSE +0 -0
  69. {miso_client-0.1.0.dist-info → miso_client-3.7.2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,68 @@
1
+ miso_client/__init__.py,sha256=Y-LrX8W1ToRKfllditYgcNTWACQUFPPUErJtakMwfZw,28566
2
+ miso_client/errors.py,sha256=uyS5j-_bUCA5gbINPYQd0wMpGsaEH0tJRK0obQTq2oo,1976
3
+ miso_client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ miso_client/api/__init__.py,sha256=ZQ8lrOHG2vRUNeOlusRFJv2QcJx0cBJtRiTIvJvnMBM,943
5
+ miso_client/api/auth_api.py,sha256=X8goYGEbqW3h2M95X9e08rukurBmfTVmhuc5K_6g7Ag,12127
6
+ miso_client/api/logs_api.py,sha256=E3eapR6m_YFIqQJLJZDMHGWB243ph98ZI_H3Ath-gS8,2942
7
+ miso_client/api/permissions_api.py,sha256=7O9Cmx_P8EnywV7mi0U9kUW2yd1J93ssGkGH_Hbwvnk,2860
8
+ miso_client/api/roles_api.py,sha256=3OTK4YFNzAwL-NO7h8XlM3W-aN6svnIPA38mh37KL8U,2686
9
+ miso_client/api/types/__init__.py,sha256=6N-s3QSWqUPOnU_Y-cd766L5rEKDti5Oslxven59BM8,2111
10
+ miso_client/api/types/auth_types.py,sha256=QQU-94joCVPDN4wGKeoHJi_evtVh20PsjctIKG0I3C0,6650
11
+ miso_client/api/types/logs_types.py,sha256=GiuqV9S1GzS6WnUbR2aXBajDGYtdK23N5-Jg2yJtCUw,2622
12
+ miso_client/api/types/permissions_types.py,sha256=eg38U2fWasC6Fg0UCNEPutrfyMBqFZd58I2BlA-QrFA,995
13
+ miso_client/api/types/roles_types.py,sha256=3qXtC9XvPrOpNJGbhPzmYzEaedcyRC0BXyISC_Su0p0,917
14
+ miso_client/models/__init__.py,sha256=lMnzU7j2Z5_UehvOeIrbJIo3MH4j5KINGfU1vJTzTyU,139
15
+ miso_client/models/config.py,sha256=Y6HG79O0sXHvtFx3jsrxQ88kJs4jMXfB2Rsj5PHpDOc,16843
16
+ miso_client/models/error_response.py,sha256=L6-nk3rwtzUTVzGiQIjkyNky9WlBQObFp1l8qJTpozQ,1371
17
+ miso_client/models/filter.py,sha256=YCsHJK8_2up8msiEe7ira7V9zpiaqEK_PlHJa-cODfw,8038
18
+ miso_client/models/pagination.py,sha256=FddEqwJkOh7LreW4P5MYDdaQkLwDzCx_g8D1DDRltQI,1384
19
+ miso_client/models/sort.py,sha256=CutVQnYC4uRgesJ8zgd4OmPGZIop1KzvtgiTjNproSM,621
20
+ miso_client/services/__init__.py,sha256=vY27_TwPmXbf0YHvMFINaq-gwlPNdKVkw81FVShc-qM,514
21
+ miso_client/services/auth.py,sha256=4Q_H5YiW7IlgKqAWm-mo9d29_un7vjP8V6oOM3_npy4,20856
22
+ miso_client/services/cache.py,sha256=lXcLcRm56snOX3AQiEKi-j7FIikCLYnEK2HXxBkxm2M,6510
23
+ miso_client/services/encryption.py,sha256=8512ACLt0P8t3W_CGzmG0JRSvzDinvjPRvkifdDxIRs,3022
24
+ miso_client/services/logger.py,sha256=zCm2SdUcIakkuRRNnql-d8zpiQUpnolE5Ta59qu68-U,20677
25
+ miso_client/services/logger_chain.py,sha256=Y8ilOsplD3nxSWaCN7eGItEkig0bJVYNmqI7j8m0Yx0,9481
26
+ miso_client/services/permission.py,sha256=SolhDgfO4zgza5fgasy4a7qhnf2o7ucGJpDREcSNrxc,10268
27
+ miso_client/services/redis.py,sha256=LzZ5sOldWVvZSCsU9pmUnxwfSrCp0YKMQEOmhsBofgY,5494
28
+ miso_client/services/role.py,sha256=nv8FTEE-BEBeXG7Xum_fzavHWeGpoj2VedIiW7Q_goQ,9666
29
+ miso_client/utils/__init__.py,sha256=HArSxVKrmCqFkqFOPwe1i3B2IBHJ1vRqYu98c_KASV0,366
30
+ miso_client/utils/audit_log_queue.py,sha256=pi6Ow_sPJXz22jG8ZGtJByWoXHH0ebmRG9kJvTBPn3E,7032
31
+ miso_client/utils/auth_strategy.py,sha256=nIU7a7DBLQ7ff5Q3lqFGljdlrDR-FSfAbOJDV_4t15k,3030
32
+ miso_client/utils/auth_utils.py,sha256=uUqNKoGC2468_ra0z1oMd_zpBSgf1p_34tW7QG3rsZs,2222
33
+ miso_client/utils/circuit_breaker.py,sha256=12gf1oEMmg2zZXA90hNWbBngaWjMXXm2-R6qVoIRhYY,3920
34
+ miso_client/utils/client_token_manager.py,sha256=14fw4KkflOREE6ogkmbOYa795HL9XxtwImpy50x3Eqg,9395
35
+ miso_client/utils/config_loader.py,sha256=Fk37qabRSkzi-B4QGW6RQ3_Z8IeR6oEH0Wyd4_wuHAY,5957
36
+ miso_client/utils/controller_url_resolver.py,sha256=17yhzhE1KM3KciAG53BjsHJh8TuGRR35IOMaZXd9NZ8,2430
37
+ miso_client/utils/data_masker.py,sha256=D7AEyViGxoShLa5UUZHYhRCPQMPKqX7qNilTK9h87OM,7035
38
+ miso_client/utils/environment_token.py,sha256=rAe6zxTylS89VX2OGs_e8weYK1HsTxU3WUbKYA_bQvQ,4262
39
+ miso_client/utils/error_utils.py,sha256=4ij6bNNYGOq22mdH4bk147tLNr6ZwbmKq-Aa9ciceLg,6556
40
+ miso_client/utils/fastapi_endpoints.py,sha256=FYrqV0OsqdP-cNxi_u8Vem7iSDcez4-Qxcl7IKps6p4,5980
41
+ miso_client/utils/filter.py,sha256=GMSr4VDpYVLcZeoC7qMbnkOHwkNHIsvD6NoEopQRS7A,11561
42
+ miso_client/utils/filter_applier.py,sha256=C5pMMz7YUsoFNCi3PYHGsD85hlpGIsPKGMsBvy7f2Pc,5195
43
+ miso_client/utils/filter_parser.py,sha256=oxtTtnrUSlIqmm_ok2cizM-82qbZ9ubpgOj-hIeH2Ao,3598
44
+ miso_client/utils/flask_endpoints.py,sha256=ARzksX0-bOIteOHrO0Bo6nE6JmC5z9fEfdqk_WVZAWU,6027
45
+ miso_client/utils/http_client.py,sha256=DatO10uPBMhSAi-C_Jw5qxJBpRCyGhIohJXmfv_LLJI,20160
46
+ miso_client/utils/http_client_logging.py,sha256=Z38RwhuiBcWj6wyrmz97fqGv25ZnNjDUAgpmuatLcSY,10936
47
+ miso_client/utils/http_client_logging_helpers.py,sha256=C4aE92nmvaM897ohmJH5tSVrkSCW4UifzCH-jWQLwag,5404
48
+ miso_client/utils/http_client_query_helpers.py,sha256=JFKcw8_2NqOyjrpmYZPjwSK8t-QU3qMUe28B4VB0j-M,3960
49
+ miso_client/utils/http_error_handler.py,sha256=fd0lG8WHnl_cux4nxov-J8Zg9zDsAHihSkd9lD5zCYk,2761
50
+ miso_client/utils/http_log_formatter.py,sha256=4mhd4eRXxC3QdDEz2CeXWUqdbHwf7LIEYqsTRm-x9SQ,3293
51
+ miso_client/utils/http_log_masker.py,sha256=3juFpEMJ7rEeM2Rm5d6zS3XkwN978tYjbwZj3QRCROE,6168
52
+ miso_client/utils/internal_http_client.py,sha256=9PvVKWdwDmIMju6FF7NTc6JdO2HmQTCBtoGF8o9h54o,15614
53
+ miso_client/utils/jwt_tools.py,sha256=-NI_vQ-7mAoPdLVDfV9qQIWjdQbcZMESH_72RzM7Zbs,5707
54
+ miso_client/utils/logger_helpers.py,sha256=LBBZj5IIwLO_Irg316oSL0EscpaBSmHgUaDN4y56-EU,7661
55
+ miso_client/utils/logging_helpers.py,sha256=SWz8OMqcnvwCpezGoyWfbHiwsChfI2wV5SYjz6ZyQo8,2039
56
+ miso_client/utils/origin_validator.py,sha256=W3NvIiqaVwaGCdIpD_GKghZdcUBDsnRX3xxIXWBN-vQ,5141
57
+ miso_client/utils/pagination.py,sha256=QLg9d5EfIxMpGNAm-Y31stkrY0uKOO4p9WHdWAqVZfo,7852
58
+ miso_client/utils/request_context.py,sha256=2BFU4cnQAZ_4hoWargn2pnapGUV6kNLwVUWp3oQ5iaI,8256
59
+ miso_client/utils/sensitive_fields_loader.py,sha256=EHODxyM1Gw7hgKXCvJ1B4Hf4LZqcEqWEXu4q5CPFaic,3667
60
+ miso_client/utils/sort.py,sha256=lVZwYuqSrZ7I4xtHOVMsfwDzT4vwakT02Hbg2cF5_lk,3483
61
+ miso_client/utils/token_utils.py,sha256=SSKI7z_Va6hn_ejub3b_7kdA2-reZZseWELIRa2mvME,3552
62
+ miso_client/utils/url_validator.py,sha256=n6JreUOCMlK80LvoIDReyE_OErAGQpWqJEJfd9PuPSA,1730
63
+ miso_client/utils/user_token_refresh.py,sha256=BpI9jcVTolRXDZQZHe8eJZs14YHUtEe5ew0lt9jxZwI,9926
64
+ miso_client-3.7.2.dist-info/licenses/LICENSE,sha256=3hoU8LdT9_EIFIx6FjMk5sQnVCBMX3FRIOzqqy5im4c,1076
65
+ miso_client-3.7.2.dist-info/METADATA,sha256=qzmcPDGGvYyLJCTP295dJHR0nMU8ELA9nJOGDAURHb4,33274
66
+ miso_client-3.7.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
67
+ miso_client-3.7.2.dist-info/top_level.txt,sha256=8i_FNeRn8PRy6scnXOpVr-IJYsArkqIvxRMTZPtik9E,12
68
+ miso_client-3.7.2.dist-info/RECORD,,
@@ -1,551 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: miso-client
3
- Version: 0.1.0
4
- Summary: Python client SDK for AI Fabrix authentication, authorization, and logging
5
- Home-page: https://github.com/aifabrix/miso-client-python
6
- Author: AI Fabrix Team
7
- Author-email: AI Fabrix Team <team@aifabrix.ai>
8
- Maintainer-email: AI Fabrix Team <team@aifabrix.ai>
9
- License-Expression: MIT
10
- Project-URL: Homepage, https://github.com/aifabrix/miso-client-python
11
- Project-URL: Documentation, https://docs.aifabrix.ai/miso-client-python
12
- Project-URL: Repository, https://github.com/aifabrix/miso-client-python
13
- Project-URL: Issues, https://github.com/aifabrix/miso-client-python/issues
14
- Keywords: authentication,authorization,rbac,jwt,redis,logging,aifabrix,miso
15
- Classifier: Development Status :: 4 - Beta
16
- Classifier: Intended Audience :: Developers
17
- Classifier: Operating System :: OS Independent
18
- Classifier: Programming Language :: Python :: 3
19
- Classifier: Programming Language :: Python :: 3.8
20
- Classifier: Programming Language :: Python :: 3.9
21
- Classifier: Programming Language :: Python :: 3.10
22
- Classifier: Programming Language :: Python :: 3.11
23
- Classifier: Programming Language :: Python :: 3.12
24
- Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
- Classifier: Topic :: Security
26
- Classifier: Topic :: System :: Logging
27
- Requires-Python: >=3.8
28
- Description-Content-Type: text/markdown
29
- License-File: LICENSE
30
- Requires-Dist: pydantic>=2.0.0
31
- Requires-Dist: httpx>=0.25.0
32
- Requires-Dist: redis[hiredis]>=5.0.0
33
- Requires-Dist: PyJWT>=2.8.0
34
- Requires-Dist: cryptography>=41.0.0
35
- Requires-Dist: python-dotenv>=1.0.0
36
- Provides-Extra: dev
37
- Requires-Dist: pytest>=7.4.3; extra == "dev"
38
- Requires-Dist: pytest-asyncio>=0.21.1; extra == "dev"
39
- Requires-Dist: pytest-mock>=3.12.0; extra == "dev"
40
- Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
41
- Requires-Dist: black>=23.0.0; extra == "dev"
42
- Requires-Dist: isort>=5.12.0; extra == "dev"
43
- Requires-Dist: mypy>=1.5.0; extra == "dev"
44
- Requires-Dist: ruff>=0.1.0; extra == "dev"
45
- Dynamic: author
46
- Dynamic: home-page
47
- Dynamic: license-file
48
- Dynamic: requires-python
49
-
50
- # AI Fabrix Miso Client SDK (Python)
51
-
52
- [![PyPI version](https://badge.fury.io/py/miso-client.svg)](https://badge.fury.io/py/miso-client)
53
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
54
-
55
- The **AI Fabrix Miso Client SDK** provides authentication, authorization, and logging for Python applications integrated with the AI Fabrix platform.
56
-
57
- ## ✨ Benefits
58
-
59
- ### 🔐 Enterprise Security
60
-
61
- **SSO and Federated Identity**
62
- - Single Sign-On (SSO) with Keycloak
63
- - OAuth 2.0 and OpenID Connect (OIDC) support
64
- - Multi-factor authentication (MFA) ready
65
- - Social login integration (Google, Microsoft, etc.)
66
-
67
- **Centralized Access Control**
68
- - Role-based access control (RBAC)
69
- - Fine-grained permissions
70
- - Dynamic policy enforcement
71
- - Attribute-based access control (ABAC)
72
-
73
- **API Security**
74
- - JWT token validation
75
- - API key authentication
76
- - Token revocation support
77
- - Secure token storage
78
- - Data encryption/decryption (AES-256-GCM)
79
-
80
- ### 📊 Compliance & Audit
81
-
82
- **ISO 27001 Compliance**
83
- - Comprehensive audit trails for all user actions
84
- - Data access logging and monitoring
85
- - Security event tracking
86
- - Accountability and non-repudiation
87
-
88
- **Regulatory Compliance**
89
- - GDPR-ready data protection
90
- - HIPAA-compliant audit logging
91
- - SOC 2 audit trail requirements
92
- - Industry-standard security controls
93
-
94
- **Audit Capabilities**
95
- - Real-time audit event logging
96
- - Immutable audit records
97
- - Forensic analysis support
98
- - Compliance reporting automation
99
-
100
- ### ⚡ Performance & Scalability
101
-
102
- **Intelligent Caching**
103
- - Redis-based role and permission caching
104
- - Generic cache service with Redis and in-memory fallback
105
- - Configurable cache TTL (default: 15 minutes)
106
- - Automatic cache invalidation
107
- - Fallback to controller when Redis unavailable
108
-
109
- **High Availability**
110
- - Automatic failover to controller
111
- - Redundant infrastructure support
112
- - Load balancing compatible
113
- - Zero-downtime deployments
114
-
115
- **Optimized Network**
116
- - Efficient API calls with caching
117
- - Batch operations support
118
- - Connection pooling
119
- - Minimal latency
120
-
121
- ### 🛠️ Developer Experience
122
-
123
- **Easy Integration**
124
- - Progressive activation (6-step setup)
125
- - Works with any framework (FastAPI, Django, Flask, Starlette)
126
- - Python 3.8+ support with full type hints
127
- - Async/await support throughout
128
-
129
- **Flexible Configuration**
130
- - Environment-based configuration
131
- - Support for dev, test, and production environments
132
- - Docker and Kubernetes ready
133
- - CI/CD friendly
134
-
135
- **Observability**
136
- - Centralized logging with correlation IDs
137
- - Performance tracking and metrics
138
- - Error tracking and debugging
139
- - Health monitoring
140
-
141
- ---
142
-
143
- ## 🚀 Quick Start
144
-
145
- Get your application secured in 30 seconds.
146
-
147
- ### Step 1: Install
148
-
149
- ```bash
150
- pip install miso-client
151
- ```
152
-
153
- ### Step 2: Create `.env`
154
-
155
- ```bash
156
- MISO_CLIENTID=ctrl-dev-my-app
157
- MISO_CLIENTSECRET=your-secret
158
- MISO_CONTROLLER_URL=http://localhost:3000
159
- REDIS_HOST=localhost
160
- ```
161
-
162
- ### Step 3: Use It
163
-
164
- ```python
165
- from miso_client import MisoClient, load_config
166
-
167
- client = MisoClient(load_config())
168
- await client.initialize()
169
-
170
- is_valid = await client.validate_token(token)
171
- ```
172
-
173
- **That's it!** You now have authentication, roles, and logging.
174
-
175
- → [Full Getting Started Guide](docs/getting-started.md)
176
-
177
- ---
178
-
179
- ### Infrastructure Setup
180
-
181
- **First time?** You'll need Keycloak and Miso Controller running.
182
-
183
- Use the [AI Fabrix Builder](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/QUICK-START.md):
184
-
185
- ```bash
186
- # Start infrastructure (Postgres, Redis)
187
- aifabrix up
188
-
189
- # Install Keycloak for authentication
190
- aifabrix create keycloak --port 8082 --database --template platform
191
- aifabrix build keycloak
192
- aifabrix run keycloak
193
-
194
- # Install Miso Controller
195
- aifabrix create miso-controller --port 3000 --database --redis --template platform
196
- aifabrix build miso-controller
197
- aifabrix run miso-controller
198
- ```
199
-
200
- → [Infrastructure Guide](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/INFRASTRUCTURE.md)
201
-
202
- **Already have Keycloak and Controller?** Use the Quick Start above.
203
-
204
- ---
205
-
206
- ## 📚 Documentation
207
-
208
- **What happens:** Your app validates user tokens from Keycloak.
209
-
210
- ```python
211
- from miso_client import MisoClient, load_config
212
-
213
- # Create client (loads from .env automatically)
214
- client = MisoClient(load_config())
215
- await client.initialize()
216
-
217
- # Get token from request (helper method)
218
- token = client.get_token(req)
219
-
220
- if token:
221
- is_valid = await client.validate_token(token)
222
- if is_valid:
223
- user = await client.get_user(token)
224
- print('User:', user)
225
- ```
226
-
227
- **Where to get tokens?** Users authenticate via Keycloak, then your app receives JWTs in the `Authorization` header.
228
-
229
- → [Complete authentication example](examples/step-3-authentication.py)
230
-
231
- ---
232
-
233
- ### Step 4: Activate RBAC (Roles)
234
-
235
- **What happens:** Check user roles to control access. Roles are cached in Redis for performance.
236
-
237
- ```python
238
- from miso_client import MisoClient, load_config
239
-
240
- # Build on Step 3 - add Redis in .env file
241
- client = MisoClient(load_config())
242
- await client.initialize()
243
-
244
- token = client.get_token(req)
245
-
246
- # Check if user has role
247
- is_admin = await client.has_role(token, 'admin')
248
- roles = await client.get_roles(token)
249
-
250
- # Gate features by role
251
- if is_admin:
252
- # Show admin panel
253
- pass
254
- ```
255
-
256
- **Pro tip:** Without Redis, checks go to the controller. Add Redis to cache role lookups (15-minute default TTL).
257
-
258
- → [Complete RBAC example](examples/step-4-rbac.py)
259
- → [AI Fabrix Builder Quick Start](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/QUICK-START.md)
260
-
261
- ---
262
-
263
- ### Step 5: Activate Logging
264
-
265
- **What happens:** Application logs are sent to the Miso Controller with client token authentication.
266
-
267
- ```python
268
- from miso_client import MisoClient, load_config
269
-
270
- # Client token is automatically managed - no API key needed
271
- client = MisoClient(load_config())
272
- await client.initialize()
273
-
274
- token = client.get_token(req)
275
- user = await client.get_user(token)
276
-
277
- # Log messages
278
- await client.log.info('User accessed dashboard', {'userId': user.id if user else None})
279
- await client.log.error('Operation failed', {'error': str(err)})
280
- await client.log.warn('Unusual activity', {'details': '...'})
281
- ```
282
-
283
- **What happens to logs?** They're sent to the Miso Controller for centralized monitoring and analysis. Client token is automatically included.
284
-
285
- → [Complete logging example](examples/step-5-logging.py)
286
- → [Logging Reference](docs/api-reference.md#logger-service)
287
-
288
- ---
289
-
290
- ### Step 6: Activate Audit
291
-
292
- **What happens:** Create audit trails for compliance and security monitoring.
293
-
294
- ```python
295
- from miso_client import MisoClient, load_config
296
-
297
- # Complete configuration (all in .env)
298
- client = MisoClient(load_config())
299
- await client.initialize()
300
-
301
- token = client.get_token(req)
302
- is_valid = await client.validate_token(token)
303
- can_edit = await client.has_permission(token, 'edit:content')
304
- user = await client.get_user(token)
305
-
306
- # Audit: User actions
307
- await client.log.audit('user.login', 'authentication', {
308
- 'userId': user.id if user else None,
309
- 'ip': req.get('ip', ''),
310
- 'userAgent': req.get('headers', {}).get('user-agent', ''),
311
- })
312
-
313
- # Audit: Content changes
314
- await client.log.audit('post.created', 'content', {
315
- 'userId': user.id if user else None,
316
- 'postId': 'post-123',
317
- 'postTitle': req.get('body', {}).get('title', ''),
318
- })
319
-
320
- # Audit: Permission checks
321
- await client.log.audit('access.denied', 'authorization', {
322
- 'userId': user.id if user else None,
323
- 'requiredPermission': 'edit:content',
324
- 'resource': 'posts',
325
- })
326
- ```
327
-
328
- **What to audit:** Login/logout, permission checks, content creation/deletion, role changes, sensitive operations.
329
-
330
- → [Complete audit example](examples/step-6-audit.py)
331
- → [Best Practices](docs/getting-started.md#common-patterns)
332
-
333
- ---
334
-
335
- ### Encryption and Caching
336
-
337
- **What happens:** Use encryption for sensitive data and generic caching for improved performance.
338
-
339
- ```python
340
- from miso_client import MisoClient, load_config
341
-
342
- client = MisoClient(load_config())
343
- await client.initialize()
344
-
345
- # Encryption (requires ENCRYPTION_KEY in .env)
346
- encrypted = client.encrypt('sensitive-data')
347
- decrypted = client.decrypt(encrypted)
348
- print('Decrypted:', decrypted)
349
-
350
- # Generic caching (automatically uses Redis if available, falls back to memory)
351
- await client.cache_set('user:123', {'name': 'John', 'age': 30}, 600) # 10 minutes TTL
352
- user = await client.cache_get('user:123')
353
- if user:
354
- print('Cached user:', user)
355
- ```
356
-
357
- **Configuration:**
358
-
359
- ```bash
360
- # Add to .env
361
- ENCRYPTION_KEY=your-32-byte-encryption-key
362
- ```
363
-
364
- → [API Reference](docs/api-reference.md#encryption-methods)
365
- → [Cache Methods](docs/api-reference.md#cache-methods)
366
-
367
- ---
368
-
369
- ## 🔧 Configuration
370
-
371
- ```python
372
- from miso_client import MisoClientConfig, RedisConfig
373
-
374
- config = MisoClientConfig(
375
- controller_url="http://localhost:3000", # Required: Controller URL
376
- client_id="ctrl-dev-my-app", # Required: Client ID
377
- client_secret="your-secret", # Required: Client secret
378
- redis=RedisConfig( # Optional: For caching
379
- host="localhost",
380
- port=6379,
381
- ),
382
- log_level="info", # Optional: 'debug' | 'info' | 'warn' | 'error'
383
- cache={ # Optional: Cache TTL settings
384
- "role_ttl": 900, # Role cache TTL (default: 900s)
385
- "permission_ttl": 900, # Permission cache TTL (default: 900s)
386
- }
387
- )
388
- ```
389
-
390
- **Recommended:** Use `load_config()` to load from `.env` file automatically.
391
-
392
- → [Complete Configuration Reference](docs/configuration.md)
393
-
394
- ---
395
-
396
- ## 📚 Documentation
397
-
398
- - **[Getting Started](docs/getting-started.md)** - Detailed setup guide
399
- - **[API Reference](docs/api-reference.md)** - Complete API documentation
400
- - **[Configuration](docs/configuration.md)** - Configuration options
401
- - **[Examples](docs/examples.md)** - Framework-specific examples
402
- - **[Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions
403
-
404
- ---
405
-
406
- ## 🏗️ Architecture
407
-
408
- The SDK consists of five core services:
409
-
410
- - **AuthService** - Token validation and user authentication
411
- - **RoleService** - Role management with Redis caching
412
- - **PermissionService** - Fine-grained permissions
413
- - **LoggerService** - Centralized logging with API key authentication
414
- - **RedisService** - Caching and queue management (optional)
415
-
416
- → [Architecture Details](docs/api-reference.md#architecture)
417
-
418
- ---
419
-
420
- ## 🌐 Setup Your Application
421
-
422
- **First time setup?** Use the AI Fabrix Builder:
423
-
424
- 1. **Create your app:**
425
- ```bash
426
- aifabrix create myapp --port 3000 --database --language python
427
- ```
428
-
429
- 2. **Login to controller:**
430
- ```bash
431
- aifabrix login
432
- ```
433
-
434
- 3. **Register your application:**
435
- ```bash
436
- aifabrix app register myapp --environment dev
437
- ```
438
-
439
- 4. **Start development** and then deploy to Docker or Azure.
440
-
441
- → [Full Quick Start Guide](https://github.com/esystemsdev/aifabrix-builder/blob/main/docs/QUICK-START.md)
442
-
443
- ---
444
-
445
- ## 💡 Next Steps
446
-
447
- ### Learn More
448
- - [FastAPI Integration](docs/examples.md#fastapi-integration) - Protect API routes
449
- - [Django Middleware](docs/examples.md#django-middleware) - Django integration
450
- - [Flask Decorators](docs/examples.md#flask-decorators) - Decorator-based auth
451
- - [Error Handling](docs/examples.md#error-handling) - Best practices
452
-
453
- ### Common Tasks
454
-
455
- **Add authentication middleware (FastAPI):**
456
- ```python
457
- from fastapi import Depends, HTTPException, Security
458
- from fastapi.security import HTTPBearer
459
- from miso_client import MisoClient
460
-
461
- security = HTTPBearer()
462
- client = MisoClient(load_config())
463
-
464
- async def get_current_user(credentials = Security(security)):
465
- token = credentials.credentials
466
- is_valid = await client.validate_token(token)
467
- if not is_valid:
468
- raise HTTPException(status_code=401, detail="Invalid token")
469
- return await client.get_user(token)
470
- ```
471
-
472
- **Protect routes by role (FastAPI):**
473
- ```python
474
- @app.get('/admin')
475
- async def admin_panel(user = Depends(get_current_user), credentials = Security(security)):
476
- token = credentials.credentials
477
- is_admin = await client.has_role(token, 'admin')
478
- if not is_admin:
479
- raise HTTPException(status_code=403, detail="Forbidden")
480
-
481
- # Admin only code
482
- return {"message": "Admin panel"}
483
- ```
484
-
485
- **Use environment variables:**
486
- ```bash
487
- MISO_CLIENTID=ctrl-dev-my-app
488
- MISO_CLIENTSECRET=your-secret
489
- MISO_CONTROLLER_URL=http://localhost:3000
490
- REDIS_HOST=localhost
491
- REDIS_PORT=6379
492
- MISO_LOG_LEVEL=info
493
- ```
494
-
495
- ---
496
-
497
- ## 🐛 Troubleshooting
498
-
499
- **"Cannot connect to controller"**
500
- → Verify `controllerUrl` is correct and accessible
501
- → Check network connectivity
502
-
503
- **"Redis connection failed"**
504
- → SDK falls back to controller-only mode (slower but works)
505
- → Fix: `aifabrix up` to start Redis
506
-
507
- **"Client token fetch failed"**
508
- → Check `MISO_CLIENTID` and `MISO_CLIENTSECRET` are correct
509
- → Verify credentials are configured in controller
510
- → Ensure `ENCRYPTION_KEY` environment variable is set (required for encryption service)
511
-
512
- **"Token validation fails"**
513
- → Ensure Keycloak is running and configured correctly
514
- → Verify token is from correct Keycloak instance
515
- → Check that `python-dotenv` is installed if using `.env` files
516
-
517
- → [More Help](docs/troubleshooting.md)
518
-
519
- ---
520
-
521
- ## 📦 Installation
522
-
523
- ```bash
524
- # pip
525
- pip install miso-client
526
-
527
- # Development mode
528
- pip install -e .
529
-
530
- # With dev dependencies
531
- pip install "miso-client[dev]"
532
- ```
533
-
534
- ---
535
-
536
- ## 🔗 Links
537
-
538
- - **GitHub Repository**: [https://github.com/esystemsdev/aifabrix-miso-client-python](https://github.com/esystemsdev/aifabrix-miso-client-python)
539
- - **PyPI Package**: [https://pypi.org/project/miso-client/](https://pypi.org/project/miso-client/)
540
- - **Builder Documentation**: [https://github.com/esystemsdev/aifabrix-builder](https://github.com/esystemsdev/aifabrix-builder)
541
- - **Issues**: [https://github.com/esystemsdev/aifabrix-miso-client-python/issues](https://github.com/esystemsdev/aifabrix-miso-client-python/issues)
542
-
543
- ---
544
-
545
- ## 📄 License
546
-
547
- This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details.
548
-
549
- ---
550
-
551
- **Made with ❤️ by eSystems Nordic Ltd.**
@@ -1,23 +0,0 @@
1
- miso_client/__init__.py,sha256=lL254-VN8Q8SV4nJwiTMYEWrYUpBzzG_uxNlNlQKuog,14205
2
- miso_client/errors.py,sha256=XEa0bbYoP4mH6n8GuTquf-qD4tkCr-Ca3QIWOKZJtxQ,1143
3
- miso_client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
- miso_client/models/__init__.py,sha256=Oy03VQKAqg0FGZiWfcNdSgOA-PzfbdQDX_1sqfv_r-U,67
5
- miso_client/models/config.py,sha256=PFiIp8fouoGGBUAu9ODwsVwhuW78v-iqEvDPBQ0YK5Q,7759
6
- miso_client/services/__init__.py,sha256=DfiZJ45MWQvVqwp0kyxjuK9ngiO3nW8zcdBqd7VOD7Y,488
7
- miso_client/services/auth.py,sha256=NrVX5MXaLqWinoWB7bAvEurTONkjVm2HlvDJPnmOkKU,4863
8
- miso_client/services/cache.py,sha256=gu5Ykbh43vrBb9hLvl6OXstGKFZpUUyIAa4fifj6KW8,6786
9
- miso_client/services/encryption.py,sha256=kQsES7oCs1l8vTmy1G9mI6eXXvrfdNuXMpZzG_xUX0M,3145
10
- miso_client/services/logger.py,sha256=tpj-N3Rq4dfkJteNu7rt_KniOFkf5eyhuTbFcapM-Nk,16789
11
- miso_client/services/permission.py,sha256=6vT9BV_NX9dJ7moSN5CBILjEn9u6do9IAeR4k3Fp9Q8,7210
12
- miso_client/services/redis.py,sha256=4ov5Pu1xKDqSUNMDx9rTvbsTuM4jwaRUrpSiLAzIU_I,5478
13
- miso_client/services/role.py,sha256=j4qCyYBXinubEpa0Yy_XPqFANuQHSQl0BILugRXM5WY,5896
14
- miso_client/utils/__init__.py,sha256=YErXOQ6cqaxflEC7JCQuV_XbPU4NTAdBhbe4L5tv73o,365
15
- miso_client/utils/config_loader.py,sha256=a2Jj8sd_IN8EhCjk3mtdMK1Z3MAG0P8IYThCd66dk3k,2912
16
- miso_client/utils/data_masker.py,sha256=PJ-8ro2zuzS_XkjB5aV_DjY9NAjnlynJhsy41nFr408,4570
17
- miso_client/utils/http_client.py,sha256=L9004iavGVM67BIJTl9_aI0rzV6fMSi0WPZi1h-CgTY,13347
18
- miso_client/utils/jwt_tools.py,sha256=W1WFA_J1YU1Ng-IcsA9KdUTPda4pqIy7TF7nvXl2KLk,2061
19
- miso_client-0.1.0.dist-info/licenses/LICENSE,sha256=3hoU8LdT9_EIFIx6FjMk5sQnVCBMX3FRIOzqqy5im4c,1076
20
- miso_client-0.1.0.dist-info/METADATA,sha256=ocOKMvNYl5VKFXr5NbD7FtdwWfMM947h0Rt4lgLRJR0,16006
21
- miso_client-0.1.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
22
- miso_client-0.1.0.dist-info/top_level.txt,sha256=8i_FNeRn8PRy6scnXOpVr-IJYsArkqIvxRMTZPtik9E,12
23
- miso_client-0.1.0.dist-info/RECORD,,