Skip to content

Commit

Permalink
fix: cache token authentication lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
rwxd committed Nov 10, 2023
1 parent c0fffbd commit 1dede92
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions powerdns_api_proxy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def load_config(path: Optional[Path] = None) -> ProxyConfig:
return config


@lru_cache(maxsize=1000)
def token_defined(config: ProxyConfig, token: str) -> bool:
sha512 = hashlib.sha512()
sha512.update(token.encode())
Expand All @@ -57,6 +58,7 @@ def dependency_check_token_defined(
check_token_defined(load_config(), X_API_Key)


@lru_cache(maxsize=1000)
def get_environment_for_token(
config: ProxyConfig, token: str
) -> ProxyConfigEnvironment:
Expand Down
8 changes: 8 additions & 0 deletions powerdns_api_proxy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ def api_token_defined(cls, v):
raise ValueError('pdns_api_token must a non-empty string')
return v

def __hash__(self):
return hash(
self.pdns_api_url
+ self.pdns_api_token
+ str(self.pdns_api_verify_ssl)
+ str(self.environments)
)


class ResponseAllowed(BaseModel):
zones: list[ProxyConfigZone]
Expand Down

0 comments on commit 1dede92

Please sign in to comment.