lint: reformat python code with black
This commit is contained in:
parent
331beb01b4
commit
a406a7974b
88 changed files with 2579 additions and 1608 deletions
|
@ -24,8 +24,9 @@ class BlockBridgeAutomation(BaseAutomation):
|
|||
self.hashed_fingerprints = []
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def perform_deprecations(self, ids: List[str], bridge_select_func: Callable[[str], Optional[Bridge]]
|
||||
) -> List[Tuple[Optional[str], Any, Any]]:
|
||||
def perform_deprecations(
|
||||
self, ids: List[str], bridge_select_func: Callable[[str], Optional[Bridge]]
|
||||
) -> List[Tuple[Optional[str], Any, Any]]:
|
||||
rotated = []
|
||||
for id_ in ids:
|
||||
bridge = bridge_select_func(id_)
|
||||
|
@ -37,7 +38,13 @@ class BlockBridgeAutomation(BaseAutomation):
|
|||
continue
|
||||
if bridge.deprecate(reason=self.short_name):
|
||||
logging.info("Rotated %s", bridge.hashed_fingerprint)
|
||||
rotated.append((bridge.fingerprint, bridge.cloud_account.provider, bridge.cloud_account.description))
|
||||
rotated.append(
|
||||
(
|
||||
bridge.fingerprint,
|
||||
bridge.cloud_account.provider,
|
||||
bridge.cloud_account.description,
|
||||
)
|
||||
)
|
||||
else:
|
||||
logging.debug("Not rotating a bridge that is already deprecated")
|
||||
return rotated
|
||||
|
@ -50,15 +57,28 @@ class BlockBridgeAutomation(BaseAutomation):
|
|||
rotated = []
|
||||
rotated.extend(self.perform_deprecations(self.ips, get_bridge_by_ip))
|
||||
logging.debug("Blocked by IP")
|
||||
rotated.extend(self.perform_deprecations(self.fingerprints, get_bridge_by_fingerprint))
|
||||
rotated.extend(
|
||||
self.perform_deprecations(self.fingerprints, get_bridge_by_fingerprint)
|
||||
)
|
||||
logging.debug("Blocked by fingerprint")
|
||||
rotated.extend(self.perform_deprecations(self.hashed_fingerprints, get_bridge_by_hashed_fingerprint))
|
||||
rotated.extend(
|
||||
self.perform_deprecations(
|
||||
self.hashed_fingerprints, get_bridge_by_hashed_fingerprint
|
||||
)
|
||||
)
|
||||
logging.debug("Blocked by hashed fingerprint")
|
||||
if rotated:
|
||||
activity = Activity(
|
||||
activity_type="block",
|
||||
text=(f"[{self.short_name}] ♻ Rotated {len(rotated)} bridges: \n"
|
||||
+ "\n".join([f"* {fingerprint} ({provider}: {provider_description})" for fingerprint, provider, provider_description in rotated]))
|
||||
text=(
|
||||
f"[{self.short_name}] ♻ Rotated {len(rotated)} bridges: \n"
|
||||
+ "\n".join(
|
||||
[
|
||||
f"* {fingerprint} ({provider}: {provider_description})"
|
||||
for fingerprint, provider, provider_description in rotated
|
||||
]
|
||||
)
|
||||
),
|
||||
)
|
||||
db.session.add(activity)
|
||||
activity.notify()
|
||||
|
@ -87,7 +107,7 @@ def get_bridge_by_ip(ip: str) -> Optional[Bridge]:
|
|||
return Bridge.query.filter( # type: ignore[no-any-return]
|
||||
Bridge.deprecated.is_(None),
|
||||
Bridge.destroyed.is_(None),
|
||||
Bridge.bridgeline.contains(f" {ip} ")
|
||||
Bridge.bridgeline.contains(f" {ip} "),
|
||||
).first()
|
||||
|
||||
|
||||
|
@ -95,7 +115,7 @@ def get_bridge_by_fingerprint(fingerprint: str) -> Optional[Bridge]:
|
|||
return Bridge.query.filter( # type: ignore[no-any-return]
|
||||
Bridge.deprecated.is_(None),
|
||||
Bridge.destroyed.is_(None),
|
||||
Bridge.fingerprint == fingerprint
|
||||
Bridge.fingerprint == fingerprint,
|
||||
).first()
|
||||
|
||||
|
||||
|
@ -103,5 +123,5 @@ def get_bridge_by_hashed_fingerprint(hashed_fingerprint: str) -> Optional[Bridge
|
|||
return Bridge.query.filter( # type: ignore[no-any-return]
|
||||
Bridge.deprecated.is_(None),
|
||||
Bridge.destroyed.is_(None),
|
||||
Bridge.hashed_fingerprint == hashed_fingerprint
|
||||
Bridge.hashed_fingerprint == hashed_fingerprint,
|
||||
).first()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue