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.
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/CHANGELOG.md +1 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/Dockerfile +2 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/PKG-INFO +1 -1
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/rate_limit.py +16 -1
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/route.py +3 -1
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/route_metadata.py +1 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/kiba_core.egg-info/PKG-INFO +1 -1
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/pyproject.toml +1 -1
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_rate_limit.py +39 -2
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_route.py +14 -1
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.github/pull_request_template.md +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.github/workflows/deploy.yml +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.github/workflows/publish.yml +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.github/workflows/pull-request.yml +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.github/workflows/release.yml +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/.gitignore +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/README.md +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/api_request.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/api_response.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/authorizer.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/default_routes.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/health.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/json_route.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/blocked_ip_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/database_connection_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/exception_handling_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/gzip_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/logging_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/origin_ip_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/public_cors_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/security_headers_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/server_headers_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/openapi.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/request_body.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/request_context.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/route_auth.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/streaming_json_route.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/uploaded_file.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/auth_tokens/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/auth_tokens/auth_token_invalidation_store.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/auth_tokens/dict_auth_token_invalidation_store.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/auth_tokens/sql_auth_token_invalidation_store.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/aws_requester.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/caching/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/caching/cache.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/caching/dict_cache.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/caching/file_cache.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/api_request_cron_job_processor.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/cron_executor.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/cron_job_processor.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/model.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/exceptions.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/http/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/http/basic_authentication.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/http/jwt.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/http/rest_method.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/http/signed_token_manager.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/locks/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/locks/lock.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/locks/model.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/locks/sql.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/logging.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/mcp_identity_provider.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/mcp_oauth_server.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/mcp_routes.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/mcp_server.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/mcp/model.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/notifications/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/notifications/discord_client.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/notifications/notification_client.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/notifications/slack_client.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/py.typed +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/aqs.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/cosmos.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/message_queue.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/message_queue_processor.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/model.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/sql.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/queues/sqs.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/requester/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/requester/requester.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/s3_manager.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/service_client.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/store/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/store/database.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/store/entity_repository.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/store/retriever.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/store/saver.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/async_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/chain_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/date_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/dict_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/file_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/hashing_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/http_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/json_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/list_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/number_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/process_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/string_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/typing_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/url_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/util/value_holder.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/erc20.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/erc4626.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/eth_client.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/eth_client_registry.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/web3/multicall3.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/kiba_core.egg-info/SOURCES.txt +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/kiba_core.egg-info/dependency_links.txt +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/kiba_core.egg-info/requires.txt +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/kiba_core.egg-info/top_level.txt +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/makefile +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/setup.cfg +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_api_response.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_authorizer.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_blocked_ip_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_database_connection_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_exception_handling_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_gzip_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_json_route.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_openapi.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_origin_ip_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_public_cors_middleware.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_request_context.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_streaming_json_route.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/auth_tokens/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/auth_tokens/test_auth_token_invalidation_store.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/caching/test_dict_cache.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/caching/test_file_cache.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/cron/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/cron/test_cron_executor.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/http/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/http/test_signed_token_manager.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/locks/test_sql_lock.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/mcp/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/mcp/conftest.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/mcp/test_mcp_oauth.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/mcp/test_mcp_server.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/conftest.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_aqs_queue.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_cosmos_queue.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_message_queue_processor.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_sql_queue.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_sqs_queue.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/requester/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/requester/test_requester.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/test_database.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/test_entity_repository.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/test_exceptions.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/test_logging.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_async_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_chain_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_date_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_dict_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_file_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_json_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_list_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_number_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_process_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_string_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/util/test_url_util.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/web3/__init__.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/web3/test_eth_client_registry.py +0 -0
- {kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/web3/test_rest_eth_client.py +0 -0
- {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
|
|
@@ -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
|
-
|
|
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:
|
|
@@ -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)
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/blocked_ip_middleware.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/origin_ip_middleware.py
RENAMED
|
File without changes
|
{kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/public_cors_middleware.py
RENAMED
|
File without changes
|
{kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/security_headers_middleware.py
RENAMED
|
File without changes
|
{kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/api/middleware/server_headers_middleware.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
|
{kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/auth_tokens/auth_token_invalidation_store.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
|
{kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/core/cron/api_request_cron_job_processor.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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
{kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_database_connection_middleware.py
RENAMED
|
File without changes
|
{kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/api/test_exception_handling_middleware.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
|
|
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
|
|
File without changes
|
|
File without changes
|
{kiba_core-0.5.3.dev101 → kiba_core-0.5.3.dev103}/tests/queues/test_message_queue_processor.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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|