mirror of
https://github.com/fuckpiracyshield/api.git
synced 2026-01-24 00:10:51 +01:00
Added requests interceptors support. IP addresses can now be banned.
This commit is contained in:
parent
f3ed518b65
commit
183fa3e27a
14 changed files with 196 additions and 208 deletions
34
interceptors/security/blacklist.py
Normal file
34
interceptors/security/blacklist.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
from piracyshield_service.security.blacklist.exists_by_ip_address import SecurityBlacklistExistsByIPAddressService
|
||||
|
||||
from ioutils.errors import ErrorCode, ErrorMessage
|
||||
|
||||
class BlacklistInterceptor:
|
||||
|
||||
"""
|
||||
Applies bans.
|
||||
"""
|
||||
|
||||
security_blacklist_exists_by_ip_address_service = None
|
||||
|
||||
async def execute(self, r):
|
||||
await self._prepare_modules()
|
||||
|
||||
if self.security_blacklist_exists_by_ip_address_service.execute(
|
||||
ip_address = r.request.remote_ip
|
||||
) == True:
|
||||
raise BlacklistInterceptorException()
|
||||
|
||||
async def _prepare_modules(self):
|
||||
self.security_blacklist_exists_by_ip_address_service = SecurityBlacklistExistsByIPAddressService()
|
||||
|
||||
class BlacklistInterceptorException(Exception):
|
||||
|
||||
"""
|
||||
The IP address is temporary banned.
|
||||
"""
|
||||
|
||||
status_code = 403
|
||||
|
||||
error_code = ErrorCode.IP_ADDRESS_BLACKLISTED
|
||||
|
||||
error_message = ErrorMessage.IP_ADDRESS_BLACKLISTED
|
||||
Loading…
Add table
Add a link
Reference in a new issue