kiba-core 0.5.3.dev101__tar.gz → 0.5.3.dev103__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 (176) hide show
  1. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/CHANGELOG.md +1 -0
  2. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/Dockerfile +2 -0
  3. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/PKG-INFO +1 -1
  4. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/rate_limit.py +16 -1
  5. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/route.py +3 -1
  6. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/route_metadata.py +1 -0
  7. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/kiba_core.egg-info/PKG-INFO +1 -1
  8. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/pyproject.toml +1 -1
  9. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_rate_limit.py +39 -2
  10. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_route.py +14 -1
  11. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.github/pull_request_template.md +0 -0
  12. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.github/workflows/deploy.yml +0 -0
  13. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.github/workflows/publish.yml +0 -0
  14. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.github/workflows/pull-request.yml +0 -0
  15. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.github/workflows/release.yml +0 -0
  16. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.gitignore +0 -0
  17. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/README.md +0 -0
  18. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/__init__.py +0 -0
  19. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/__init__.py +0 -0
  20. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/api_request.py +0 -0
  21. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/api_response.py +0 -0
  22. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/authorizer.py +0 -0
  23. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/default_routes.py +0 -0
  24. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/health.py +0 -0
  25. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/json_route.py +0 -0
  26. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/__init__.py +0 -0
  27. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/blocked_ip_middleware.py +0 -0
  28. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/database_connection_middleware.py +0 -0
  29. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/exception_handling_middleware.py +0 -0
  30. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/gzip_middleware.py +0 -0
  31. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/logging_middleware.py +0 -0
  32. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/origin_ip_middleware.py +0 -0
  33. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/public_cors_middleware.py +0 -0
  34. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/security_headers_middleware.py +0 -0
  35. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/server_headers_middleware.py +0 -0
  36. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/openapi.py +0 -0
  37. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/request_body.py +0 -0
  38. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/request_context.py +0 -0
  39. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/route_auth.py +0 -0
  40. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/streaming_json_route.py +0 -0
  41. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/uploaded_file.py +0 -0
  42. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/auth_tokens/__init__.py +0 -0
  43. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/auth_tokens/auth_token_invalidation_store.py +0 -0
  44. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/auth_tokens/dict_auth_token_invalidation_store.py +0 -0
  45. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/auth_tokens/sql_auth_token_invalidation_store.py +0 -0
  46. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/aws_requester.py +0 -0
  47. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/caching/__init__.py +0 -0
  48. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/caching/cache.py +0 -0
  49. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/caching/dict_cache.py +0 -0
  50. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/caching/file_cache.py +0 -0
  51. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/__init__.py +0 -0
  52. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/api_request_cron_job_processor.py +0 -0
  53. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/cron_executor.py +0 -0
  54. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/cron_job_processor.py +0 -0
  55. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/model.py +0 -0
  56. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/exceptions.py +0 -0
  57. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/http/__init__.py +0 -0
  58. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/http/basic_authentication.py +0 -0
  59. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/http/jwt.py +0 -0
  60. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/http/rest_method.py +0 -0
  61. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/http/signed_token_manager.py +0 -0
  62. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/locks/__init__.py +0 -0
  63. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/locks/lock.py +0 -0
  64. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/locks/model.py +0 -0
  65. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/locks/sql.py +0 -0
  66. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/logging.py +0 -0
  67. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/__init__.py +0 -0
  68. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/mcp_identity_provider.py +0 -0
  69. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/mcp_oauth_server.py +0 -0
  70. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/mcp_routes.py +0 -0
  71. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/mcp_server.py +0 -0
  72. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/model.py +0 -0
  73. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/notifications/__init__.py +0 -0
  74. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/notifications/discord_client.py +0 -0
  75. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/notifications/notification_client.py +0 -0
  76. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/notifications/slack_client.py +0 -0
  77. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/py.typed +0 -0
  78. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/__init__.py +0 -0
  79. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/aqs.py +0 -0
  80. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/cosmos.py +0 -0
  81. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/message_queue.py +0 -0
  82. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/message_queue_processor.py +0 -0
  83. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/model.py +0 -0
  84. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/sql.py +0 -0
  85. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/sqs.py +0 -0
  86. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/requester/__init__.py +0 -0
  87. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/requester/requester.py +0 -0
  88. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/s3_manager.py +0 -0
  89. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/service_client.py +0 -0
  90. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/store/__init__.py +0 -0
  91. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/store/database.py +0 -0
  92. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/store/entity_repository.py +0 -0
  93. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/store/retriever.py +0 -0
  94. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/store/saver.py +0 -0
  95. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/__init__.py +0 -0
  96. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/async_util.py +0 -0
  97. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/chain_util.py +0 -0
  98. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/date_util.py +0 -0
  99. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/dict_util.py +0 -0
  100. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/file_util.py +0 -0
  101. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/hashing_util.py +0 -0
  102. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/http_util.py +0 -0
  103. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/json_util.py +0 -0
  104. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/list_util.py +0 -0
  105. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/number_util.py +0 -0
  106. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/process_util.py +0 -0
  107. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/string_util.py +0 -0
  108. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/typing_util.py +0 -0
  109. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/url_util.py +0 -0
  110. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/value_holder.py +0 -0
  111. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/__init__.py +0 -0
  112. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/erc20.py +0 -0
  113. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/erc4626.py +0 -0
  114. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/eth_client.py +0 -0
  115. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/eth_client_registry.py +0 -0
  116. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/multicall3.py +0 -0
  117. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/kiba_core.egg-info/SOURCES.txt +0 -0
  118. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/kiba_core.egg-info/dependency_links.txt +0 -0
  119. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/kiba_core.egg-info/requires.txt +0 -0
  120. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/kiba_core.egg-info/top_level.txt +0 -0
  121. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/makefile +0 -0
  122. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/setup.cfg +0 -0
  123. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/__init__.py +0 -0
  124. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_api_response.py +0 -0
  125. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_authorizer.py +0 -0
  126. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_blocked_ip_middleware.py +0 -0
  127. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_database_connection_middleware.py +0 -0
  128. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_exception_handling_middleware.py +0 -0
  129. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_gzip_middleware.py +0 -0
  130. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_json_route.py +0 -0
  131. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_openapi.py +0 -0
  132. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_origin_ip_middleware.py +0 -0
  133. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_public_cors_middleware.py +0 -0
  134. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_request_context.py +0 -0
  135. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_streaming_json_route.py +0 -0
  136. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/auth_tokens/__init__.py +0 -0
  137. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/auth_tokens/test_auth_token_invalidation_store.py +0 -0
  138. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/caching/test_dict_cache.py +0 -0
  139. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/caching/test_file_cache.py +0 -0
  140. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/cron/__init__.py +0 -0
  141. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/cron/test_cron_executor.py +0 -0
  142. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/http/__init__.py +0 -0
  143. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/http/test_signed_token_manager.py +0 -0
  144. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/locks/test_sql_lock.py +0 -0
  145. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/mcp/__init__.py +0 -0
  146. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/mcp/conftest.py +0 -0
  147. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/mcp/test_mcp_oauth.py +0 -0
  148. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/mcp/test_mcp_server.py +0 -0
  149. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/conftest.py +0 -0
  150. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_aqs_queue.py +0 -0
  151. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_cosmos_queue.py +0 -0
  152. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_message_queue_processor.py +0 -0
  153. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_sql_queue.py +0 -0
  154. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_sqs_queue.py +0 -0
  155. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/requester/__init__.py +0 -0
  156. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/requester/test_requester.py +0 -0
  157. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/test_database.py +0 -0
  158. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/test_entity_repository.py +0 -0
  159. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/test_exceptions.py +0 -0
  160. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/test_logging.py +0 -0
  161. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/__init__.py +0 -0
  162. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_async_util.py +0 -0
  163. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_chain_util.py +0 -0
  164. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_date_util.py +0 -0
  165. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_dict_util.py +0 -0
  166. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_file_util.py +0 -0
  167. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_json_util.py +0 -0
  168. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_list_util.py +0 -0
  169. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_number_util.py +0 -0
  170. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_process_util.py +0 -0
  171. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_string_util.py +0 -0
  172. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_url_util.py +0 -0
  173. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/web3/__init__.py +0 -0
  174. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/web3/test_eth_client_registry.py +0 -0
  175. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/web3/test_rest_eth_client.py +0 -0
  176. {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/uv.lock +0 -0
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
8
8
  ## [Unreleased]
9
9
 
10
10
  ### Added
11
+ - [MINOR] Added rate limit exemptions: a `RateLimitConfig` can name an `exemption`, and `route` (`rateLimitExemptionResolver`) and `rate_limit` (`exemptionResolver`) skip the limit for requests the `RateLimitExemptionResolver` says are exempt (asked after authentication, so it can use what auth set). Exempt requests aren't counted. Naming an exemption without a resolver raises a `ValueError`
11
12
  - [MINOR] Added `core.api.middleware.blocked_ip_middleware.BlockedIpMiddleware` to answer 403 to requests from `blockedNetworks` (CIDRs) or a loaded `TorExitList`, checking every hop in `trustedProxyHeaders` and the socket peer
12
13
  - [MINOR] Added `core.api.middleware.public_cors_middleware.PublicCorsMiddleware` to let any origin call the given `paths` (add it after starlette's `CORSMiddleware` so it answers their preflights first)
13
14
  - [MINOR] Added `core.api.middleware.security_headers_middleware.SecurityHeadersMiddleware` to add fixed headers to every response
@@ -10,3 +10,5 @@ COPY uv.lock .
10
10
  RUN make install
11
11
 
12
12
  COPY . .
13
+ # NOTE(krishan711): make install ran before core/ was copied in, so reinstall the package itself to make it importable
14
+ RUN uv sync --all-extras --reinstall-package kiba-core
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kiba-core
3
- Version: 0.5.3.dev101
3
+ Version: 0.5.3.dev103
4
4
  Summary: Kiba Labs' python utilities
5
5
  Project-URL: repository, https://github.com/kibalabs/core-py
6
6
  Requires-Python: <4,>=3.12
@@ -20,6 +20,10 @@ class _WindowConfig(typing.NamedTuple):
20
20
  windowSeconds: int
21
21
 
22
22
 
23
+ class RateLimitExemptionResolver(typing.Protocol):
24
+ async def is_rate_limit_exempt(self, *, exemption: str, request: KibaApiRequest[typing.Any]) -> bool: ... # type: ignore[explicit-any]
25
+
26
+
23
27
  class _WindowState:
24
28
  __slots__ = ('count', 'windowStart')
25
29
 
@@ -92,14 +96,25 @@ def check_rate_limit(*, request: KibaApiRequest[typing.Any], routeKey: str, rate
92
96
 
93
97
  def rate_limit( # type: ignore[explicit-any]
94
98
  rateLimit: RateLimitConfig,
99
+ exemptionResolver: RateLimitExemptionResolver | None = None,
95
100
  ) -> typing.Callable[[typing.Callable[[KibaApiRequest[typing.Any]], _AnyReturn]], typing.Callable[[KibaApiRequest[typing.Any]], typing.Any]]:
101
+ exemption = rateLimit.get('exemption')
102
+ if exemption is not None and exemptionResolver is None:
103
+ raise ValueError(f'Rate limit exemption {exemption} requires an exemptionResolver')
104
+
105
+ async def is_exempt(request: KibaApiRequest[typing.Any]) -> bool: # type: ignore[explicit-any]
106
+ if exemption is None or exemptionResolver is None:
107
+ return False
108
+ return await exemptionResolver.is_rate_limit_exempt(exemption=exemption, request=request)
109
+
96
110
  def decorator(func: typing.Callable[[KibaApiRequest[typing.Any]], _AnyReturn]) -> typing.Callable[[KibaApiRequest[typing.Any]], typing.Any]: # type: ignore[explicit-any]
97
111
  update_route_metadata(func, {'rateLimit': rateLimit})
98
112
  routeKey = getattr(func, '__qualname__', type(func).__name__)
99
113
 
100
114
  @functools.wraps(func)
101
115
  async def async_wrapper(request: KibaApiRequest[typing.Any]) -> typing.Any: # type: ignore[explicit-any, misc]
102
- check_rate_limit(request=request, routeKey=routeKey, rateLimit=rateLimit)
116
+ if not await is_exempt(request=request):
117
+ check_rate_limit(request=request, routeKey=routeKey, rateLimit=rateLimit)
103
118
  result = func(request)
104
119
  if hasattr(result, '__aiter__'):
105
120
  return result
@@ -10,6 +10,7 @@ from starlette.responses import StreamingResponse
10
10
  from core.api.api_request import KibaApiRequest
11
11
  from core.api.api_response import KibaJSONResponse
12
12
  from core.api.json_route import json_route
13
+ from core.api.rate_limit import RateLimitExemptionResolver
13
14
  from core.api.rate_limit import rate_limit
14
15
  from core.api.route_auth import RouteAuthResolver
15
16
  from core.api.route_metadata import RateLimitConfig
@@ -50,12 +51,13 @@ def route[ApiRequest: BaseModel, ApiResponse: BaseModel]( # type: ignore[explic
50
51
  tags: list[str] | None = None,
51
52
  auth: str | None = None,
52
53
  rateLimit: RateLimitConfig | None = None,
54
+ rateLimitExemptionResolver: RateLimitExemptionResolver | None = None,
53
55
  extensions: Mapping[str, object] | None = None,
54
56
  ) -> typing.Callable[[typing.Callable[[KibaApiRequest[ApiRequest]], _AnyReturn]], typing.Callable[[Request], typing.Awaitable[KibaJSONResponse | StreamingResponse]]]:
55
57
  def decorator(func: typing.Callable[[KibaApiRequest[ApiRequest]], _AnyReturn]) -> typing.Callable[[Request], typing.Awaitable[KibaJSONResponse | StreamingResponse]]: # type: ignore[explicit-any]
56
58
  handler: typing.Callable[[KibaApiRequest[ApiRequest]], _AnyReturn] = func
57
59
  if rateLimit is not None:
58
- handler = rate_limit(rateLimit)(handler)
60
+ handler = rate_limit(rateLimit, exemptionResolver=rateLimitExemptionResolver)(handler)
59
61
  securitySchemeNames: list[str] = []
60
62
  if auth is not None:
61
63
  if authResolver is None:
@@ -11,6 +11,7 @@ class RateLimitConfig(typing.TypedDict, total=False):
11
11
  perHour: int
12
12
  perDay: int
13
13
  keyBy: typing.Literal['user', 'ip']
14
+ exemption: str
14
15
 
15
16
 
16
17
  OpenApiSecurity = list[dict[str, list[str]]]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: kiba-core
3
- Version: 0.5.3.dev101
3
+ Version: 0.5.3.dev103
4
4
  Summary: Kiba Labs' python utilities
5
5
  Project-URL: repository, https://github.com/kibalabs/core-py
6
6
  Requires-Python: <4,>=3.12
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "kiba-core"
3
- version = "0.5.3.dev101"
3
+ version = "0.5.3.dev103"
4
4
  description = "Kiba Labs' python utilities"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12, <4"
@@ -1,3 +1,5 @@
1
+ import typing
2
+
1
3
  import pytest
2
4
  from pydantic import BaseModel
3
5
  from starlette.applications import Starlette
@@ -31,12 +33,21 @@ async def _send(message: dict[str, object]) -> None:
31
33
  del message
32
34
 
33
35
 
34
- def _request() -> KibaApiRequest[ExampleRequest]:
35
- request = KibaApiRequest(scope={'type': 'http', 'headers': []}, receive=_receive, send=_send)
36
+ def _request(headers: list[tuple[bytes, bytes]] | None = None) -> KibaApiRequest[ExampleRequest]:
37
+ request = KibaApiRequest(scope={'type': 'http', 'headers': headers or []}, receive=_receive, send=_send)
36
38
  request.data = ExampleRequest(value='value')
37
39
  return request
38
40
 
39
41
 
42
+ class _ApiKeyExemptionResolver:
43
+ def __init__(self) -> None:
44
+ self.exemptions: list[str] = []
45
+
46
+ async def is_rate_limit_exempt(self, *, exemption: str, request: KibaApiRequest[typing.Any]) -> bool: # type: ignore[explicit-any]
47
+ self.exemptions.append(exemption)
48
+ return request.headers.get('x-api-key') is not None
49
+
50
+
40
51
  def test_rate_limit_publishes_metadata_on_the_route() -> None:
41
52
  @rate_limit({'perMinute': 3, 'perHour': 30})
42
53
  async def endpoint(request: KibaApiRequest[ExampleRequest]) -> ExampleResponse:
@@ -127,6 +138,32 @@ async def test_rate_limit_ip_key_without_origin_ip_raises_internal_error() -> No
127
138
  await endpoint(_request())
128
139
 
129
140
 
141
+ @pytest.mark.asyncio
142
+ async def test_rate_limit_skips_and_does_not_count_exempt_requests() -> None:
143
+ resolver = _ApiKeyExemptionResolver()
144
+
145
+ @rate_limit({'perMinute': 1, 'keyBy': 'ip', 'exemption': 'integrator'}, exemptionResolver=resolver)
146
+ async def endpoint(request: KibaApiRequest[ExampleRequest]) -> ExampleResponse:
147
+ return ExampleResponse(result=request.data.value)
148
+
149
+ exemptRequests = [_request(headers=[(b'x-api-key', b'key')]) for _ in range(2)]
150
+ directRequests = [_request() for _ in range(2)]
151
+ for request in [*exemptRequests, *directRequests]:
152
+ request.originIp = '1.2.3.4'
153
+
154
+ for request in exemptRequests:
155
+ assert (await endpoint(request)).result == 'value'
156
+ assert (await endpoint(directRequests[0])).result == 'value'
157
+ with pytest.raises(Exception, match='RATE_LIMITED'):
158
+ await endpoint(directRequests[1])
159
+ assert resolver.exemptions == ['integrator'] * 4
160
+
161
+
162
+ def test_rate_limit_with_an_exemption_requires_an_exemption_resolver() -> None:
163
+ with pytest.raises(ValueError, match='exemptionResolver'):
164
+ rate_limit({'perMinute': 1, 'exemption': 'integrator'})
165
+
166
+
130
167
  def test_rate_limit_ip_key_through_origin_ip_middleware_trusts_configured_header() -> None:
131
168
  @json_route(requestType=ExampleRequest, responseType=ExampleResponse)
132
169
  @rate_limit({'perMinute': 1, 'keyBy': 'ip'})
@@ -57,6 +57,11 @@ class ExampleRouteAuthResolver(RouteAuthResolver):
57
57
  raise ValueError(f'Unknown auth policy: {auth}')
58
58
 
59
59
 
60
+ class SignedInExemptionResolver:
61
+ async def is_rate_limit_exempt(self, *, exemption: str, request: KibaApiRequest[BaseModel]) -> bool:
62
+ return exemption == 'signed_in' and request.authBasic is not None
63
+
64
+
60
65
  def _build_client(
61
66
  *,
62
67
  isStreaming: bool,
@@ -64,7 +69,7 @@ def _build_client(
64
69
  auth: str | None = None,
65
70
  endpointCalls: list[str] | None = None,
66
71
  ) -> TestClient:
67
- route = functools.partial(api_route, authResolver=ExampleRouteAuthResolver())
72
+ route = functools.partial(api_route, authResolver=ExampleRouteAuthResolver(), rateLimitExemptionResolver=SignedInExemptionResolver())
68
73
  if isStreaming:
69
74
 
70
75
  @route(requestType=ExampleRequest, responseType=ExampleResponse, isStreaming=True, operationId='streamExample', tags=['Examples'], auth=auth, rateLimit=rateLimit)
@@ -132,6 +137,14 @@ def test_route_authenticates_before_rate_limiting() -> None:
132
137
  assert second.status_code == 429
133
138
 
134
139
 
140
+ def test_route_checks_rate_limit_exemptions_after_authenticating() -> None:
141
+ client = _build_client(isStreaming=False, auth='signature', rateLimit={'perMinute': 1, 'exemption': 'signed_in'})
142
+
143
+ responses = [client.post('/example', json={'value': 'x'}, headers={'Authorization': f'Signature {VALID_SIGNATURE}'}) for _ in range(3)]
144
+
145
+ assert [response.status_code for response in responses] == [200, 200, 200]
146
+
147
+
135
148
  def test_route_rejects_unauthenticated_requests_before_calling_endpoint() -> None:
136
149
  endpointCalls: list[str] = []
137
150
  client = _build_client(isStreaming=False, auth='signature', endpointCalls=endpointCalls)