-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInmemoryChallengeSolver.py
More file actions
36 lines (25 loc) · 968 Bytes
/
InmemoryChallengeSolver.py
File metadata and controls
36 lines (25 loc) · 968 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from typing import Literal
from .ChallengeSolver import ChallengeSolver
class InMemoryChallengeSolver(ChallengeSolver):
"""
In-memory implementation of the ChallengeSolver.
"""
def __init__(self):
self.challenges = {}
def supported_challenge_type(self) -> Literal["http-01"]:
return "http-01"
def supports_domain(self, domain: str) -> bool:
return "*" not in domain
def save_challenge(self, key: str, value: str, domain: str = None):
self.challenges[key] = value
def get_challenge(self, key: str, domain: str = None) -> str:
return self.challenges.get(key, "")
def delete_challenge(self, key: str, domain: str = None):
if key in self.challenges:
del self.challenges[key]
def cleanup_old_challenges(self):
self.challenges.clear()
def __iter__(self):
return iter(self.challenges)
def __len__(self):
return len(self.challenges)