Skip to content

Commit

Permalink
Use get_empty_service_config function
Browse files Browse the repository at this point in the history
  • Loading branch information
bitterpanda63 committed Feb 27, 2025
1 parent 7184ed8 commit 20dfef8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from aikido_zen.helpers.logging import logger
from .update_firewall_lists import update_firewall_lists
from ..api.http_api import ReportingApiHTTP
from ..service_config import ServiceConfig
from ..service_config import ServiceConfig, get_empty_service_config
from ..users import Users
from ..hostnames import Hostnames
from ..realtime.start_polling_for_changes import start_polling_for_changes
Expand All @@ -36,14 +36,7 @@ def __init__(self, block, api, token, serverless):
self.token = token # Should be instance of the Token class!
self.routes = Routes(200)
self.hostnames = Hostnames(200)
self.conf = ServiceConfig(
endpoints=[],
last_updated_at=-1, # Has not been updated yet
blocked_uids=[],
bypassed_ips=[],
received_any_stats=True,
blocked_ips=[],
)
self.conf = get_empty_service_config()
self.rate_limiter = RateLimiter(
max_items=5000, time_to_live_in_ms=120 * 60 * 1000 # 120 minutes
)
Expand Down
11 changes: 11 additions & 0 deletions aikido_zen/background_process/service_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,14 @@ def is_blocked_ip(self, ip):
if entry["blocklist"].matches(ip):
return entry["description"]
return False


def get_empty_service_config() -> ServiceConfig:
return ServiceConfig(
endpoints=[],
blocked_uids=set(),
bypassed_ips=[],
blocked_ips=[],
last_updated_at=-1,
received_any_stats=False,
)
14 changes: 5 additions & 9 deletions aikido_zen/thread/thread_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import aikido_zen.helpers.get_current_unixtime_ms as t
from aikido_zen.context import get_current_context
from aikido_zen.background_process.routes import Routes
from aikido_zen.background_process.service_config import ServiceConfig
from aikido_zen.background_process.service_config import (
get_empty_service_config,
ServiceConfig,
)
from aikido_zen.helpers.logging import logger

THREAD_CONFIG_TTL_MS = 60 * 1000 # Time-To-Live is 60 seconds for the thread cache
Expand Down Expand Up @@ -57,14 +60,7 @@ def get_endpoints(self):
def reset(self):
"""Empties out all values of the cache"""
self.routes = Routes(max_size=1000)
self.config = ServiceConfig(
endpoints=[],
blocked_uids=set(),
bypassed_ips=[],
blocked_ips=[],
last_updated_at=-1,
received_any_stats=False,
)
self.config = get_empty_service_config()
self.reqs = 0
self.last_renewal = 0
self.middleware_installed = False
Expand Down

0 comments on commit 20dfef8

Please sign in to comment.