MCPcopy Create free account
hub / github.com/dobin/SuperMega / Config

Class Config

config.py:11–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9CONFIG_FILE = os.path.join(os.path.dirname(__file__), "config.yaml")
10
11class Config(object):
12 def __init__(self):
13 self.data = {}
14 self.ShowCommandOutput: bool = False
15 self.debug: bool = False
16 self.has_r2: bool = False
17 self.catch_exception: bool = True
18
19 self.data_fixups = None
20 self.data_fixup_entries = None
21
22 # Default keys
23 self.xor_key: int = 0x42
24 self.xor_key2: bytes = b"\x13\x37"
25
26
27 def load(self):
28 with open(CONFIG_FILE) as jsonfile:
29 try:
30 self.data = yaml.safe_load(jsonfile)
31 except yaml.YAMLError as e:
32 print('Decoding {} as failed with: {}'.format(CONFIG_FILE, e))
33 quit()
34
35 if 'server' in os.environ:
36 server = os.environ["server"]
37 self.data["server"] = { "server": server }
38 print("Using ENV: server={}, overwriting all others from config.yaml".format(
39 server))
40
41
42 def make_encryption_keys(self):
43 # keys
44 if self.data["xor_key"] == "":
45 self.xor_key = random.randint(0, 255)
46 else:
47 self.xor_key = self.data["xor_key"]
48
49 if self.data["xor_key2"] == "":
50 self.xor_key2 = os.urandom(2)
51 else:
52 self.xor_key2 = self.data["xor_key2"]
53
54 logger.debug("-( Payload encryption keys: XOR: {} XOR2: {}".format(
55 self.xor_key, self.xor_key2
56 ))
57
58
59 def getConfigPath(self):
60 return CONFIG_FILE
61
62
63 def getConfig(self):
64 return self.data
65
66 def get(self, value) -> str:
67 return self.data.get(value, "")
68

Callers 1

config.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected