mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-06-15 23:02:16 +03:00
Added support for comments in kill switches
This commit is contained in:
parent
f10cd9d70f
commit
d5b62d957b
@ -6,18 +6,18 @@ EDMarketConnector implements a Kill Switch system that allows us to disable feat
|
|||||||
|
|
||||||
Killswitches are stored in a JSON file that is queried by EDMC on startup. The format is as follows:
|
Killswitches are stored in a JSON file that is queried by EDMC on startup. The format is as follows:
|
||||||
|
|
||||||
| Key | Type | Description |
|
| Key | Type | Description |
|
||||||
| --------------: | :-----: | :------------------------------------------------------------ |
|
| --------------: | :------: | :------------------------------------------------------------ |
|
||||||
| `version` | integer | the version of the Kill Switch JSON file, always 1 |
|
| `version` | `int` | the version of the Kill Switch JSON file, always 1 |
|
||||||
| `last_updated` | string | When last the kill switches were updated (for human use only) |
|
| `last_updated` | `string` | When last the kill switches were updated (for human use only) |
|
||||||
| `kill_switches` | array | The kill switches this file contains (expanded below) |
|
| `kill_switches` | `array` | The kill switches this file contains (expanded below) |
|
||||||
|
|
||||||
The `kill_switches` array contains kill switch objects. Each contains two fields:
|
The `kill_switches` array contains kill switch objects. Each contains two fields:
|
||||||
|
|
||||||
| Key | Type | Description |
|
| Key | Type | Description |
|
||||||
| --------: | :----------------: | :---------------------------------------------------------------------- |
|
| --------: | :----------------: | :---------------------------------------------------------------------- |
|
||||||
| `version` | `semantic version` | The version of EDMC these kill switches apply to (Must be valid semver) |
|
| `version` | `semantic version` | The version of EDMC these kill switches apply to (Must be valid semver) |
|
||||||
| `kills` | array of strings | The different keys to disable |
|
| `kills` | `Dict[str, str]` | The different keys to disable, and the reason for the disable |
|
||||||
An example follows:
|
An example follows:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
@ -27,7 +27,9 @@ An example follows:
|
|||||||
"kill_switches": [
|
"kill_switches": [
|
||||||
{
|
{
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"kills": ["plugins.eddn.send"]
|
"kills": {
|
||||||
|
"plugins.eddn.send": "some reason"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""Fetch kill switches from EDMC Repo."""
|
"""Fetch kill switches from EDMC Repo."""
|
||||||
from typing import Dict, List, NamedTuple, Optional, Union, cast
|
from typing import Dict, List, NamedTuple, Optional, Tuple, Union, cast
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import semantic_version
|
import semantic_version
|
||||||
@ -19,7 +19,14 @@ class KillSwitch(NamedTuple):
|
|||||||
"""One version's set of kill switches."""
|
"""One version's set of kill switches."""
|
||||||
|
|
||||||
version: semantic_version.Version
|
version: semantic_version.Version
|
||||||
kills: List[str]
|
kills: Dict[str, str]
|
||||||
|
|
||||||
|
|
||||||
|
class DisabledResult(NamedTuple):
|
||||||
|
"""DisabledResult is the result returned from various is_disabled calls."""
|
||||||
|
|
||||||
|
disbled: bool
|
||||||
|
reason: str
|
||||||
|
|
||||||
|
|
||||||
class KillSwitchSet:
|
class KillSwitchSet:
|
||||||
@ -28,7 +35,7 @@ class KillSwitchSet:
|
|||||||
def __init__(self, kill_switches: List[KillSwitch]) -> None:
|
def __init__(self, kill_switches: List[KillSwitch]) -> None:
|
||||||
self.kill_switches = kill_switches
|
self.kill_switches = kill_switches
|
||||||
|
|
||||||
def is_disabled(self, id: str, *, version=_current_version) -> bool:
|
def is_disabled(self, id: str, *, version=_current_version) -> DisabledResult:
|
||||||
"""
|
"""
|
||||||
Return whether or not the given feature ID is disabled by a killswitch for the given version.
|
Return whether or not the given feature ID is disabled by a killswitch for the given version.
|
||||||
|
|
||||||
@ -40,9 +47,9 @@ class KillSwitchSet:
|
|||||||
if version != ks.version:
|
if version != ks.version:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
return id in ks.kills
|
return DisabledResult(id in ks.kills, ks.kills.get(id, ""))
|
||||||
|
|
||||||
return False
|
return DisabledResult(False, "")
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
"""Return a string representation of KillSwitchSet."""
|
"""Return a string representation of KillSwitchSet."""
|
||||||
@ -111,7 +118,7 @@ def parse_kill_switches(data: KILL_SWITCH_JSON_DICT) -> List[KillSwitch]:
|
|||||||
logger.warning(f'could not parse killswitch idx {idx}: {e}')
|
logger.warning(f'could not parse killswitch idx {idx}: {e}')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ks = KillSwitch(version=ver, kills=cast(List[str], ks_data['kills']))
|
ks = KillSwitch(version=ver, kills=cast(Dict[str, str], ks_data['kills']))
|
||||||
out.append(ks)
|
out.append(ks)
|
||||||
|
|
||||||
return out
|
return out
|
||||||
@ -148,7 +155,7 @@ def setup_main_list():
|
|||||||
active = KillSwitchSet(parse_kill_switches(data))
|
active = KillSwitchSet(parse_kill_switches(data))
|
||||||
|
|
||||||
|
|
||||||
def is_disabled(id: str, *, version: semantic_version.Version = _current_version) -> bool:
|
def is_disabled(id: str, *, version: semantic_version.Version = _current_version) -> DisabledResult:
|
||||||
"""
|
"""
|
||||||
Query the global KillSwitchSet for whether or not a given ID is disabled.
|
Query the global KillSwitchSet for whether or not a given ID is disabled.
|
||||||
|
|
||||||
|
@ -127,8 +127,8 @@ class EDDN:
|
|||||||
:param cmdr: the CMDR to use as the uploader ID
|
:param cmdr: the CMDR to use as the uploader ID
|
||||||
:param msg: the payload to send
|
:param msg: the payload to send
|
||||||
"""
|
"""
|
||||||
if killswitch.is_disabled('plugins.eddn.send'):
|
if (res := killswitch.is_disabled('plugins.eddn.send')).disbled:
|
||||||
logger.warning("eddn.send has been disabled via killswitch. Returning")
|
logger.warning(f"eddn.send has been disabled via killswitch. Returning. ({res.reason})")
|
||||||
return
|
return
|
||||||
|
|
||||||
uploader_id = cmdr
|
uploader_id = cmdr
|
||||||
|
@ -511,8 +511,10 @@ def worker() -> None:
|
|||||||
|
|
||||||
retrying = 0
|
retrying = 0
|
||||||
while retrying < 3:
|
while retrying < 3:
|
||||||
if killswitch.is_disabled("plugins.edsm.worker"):
|
if (res := killswitch.is_disabled("plugins.edsm.worker")).disbled:
|
||||||
logger.warning('EDSM worker has been disabled via kill switch. Not uploading data.')
|
logger.warning(
|
||||||
|
f'EDSM worker has been disabled via kill switch. Not uploading data. ({res.reason})'
|
||||||
|
)
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -1203,8 +1203,8 @@ def new_worker():
|
|||||||
logger.debug('Starting...')
|
logger.debug('Starting...')
|
||||||
while True:
|
while True:
|
||||||
events = get_events()
|
events = get_events()
|
||||||
if killswitch.is_disabled("plugins.inara.worker"):
|
if (res := killswitch.is_disabled("plugins.inara.worker")).disbled:
|
||||||
logger.warning("Inara worker disabled via killswitch")
|
logger.warning(f"Inara worker disabled via killswitch. ({res.reason})")
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for creds, event_list in events.items():
|
for creds, event_list in events.items():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user