Skip to content

Commit 2983f06

Browse files
authored
Merge pull request #145 from jumpserver/dev
Dev
2 parents 1233b99 + f510d76 commit 2983f06

File tree

11 files changed

+420
-365
lines changed

11 files changed

+420
-365
lines changed

coco/app.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,25 @@ def task_handler(self):
5656
return self._task_handler
5757

5858
@staticmethod
59+
@ignore_error
5960
def load_extra_conf_from_server():
6061
configs = app_service.load_config_from_server()
6162
logger.debug("Loading config from server: {}".format(
6263
json.dumps(configs)
6364
))
6465
config.update(configs)
6566

67+
def keep_load_extra_conf(self):
68+
def func():
69+
while True:
70+
self.load_extra_conf_from_server()
71+
time.sleep(60*10)
72+
thread = threading.Thread(target=func)
73+
thread.start()
74+
6675
def bootstrap(self):
6776
self.load_extra_conf_from_server()
77+
self.keep_load_extra_conf()
6878
self.keep_heartbeat()
6979
self.monitor_sessions()
7080
self.monitor_sessions_replay()

coco/config.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ class Config(dict):
9292
"""
9393

9494
def __init__(self, root_path, defaults=None):
95-
dict.__init__(self, defaults or {})
95+
self.defaults = defaults or {}
9696
self.root_path = root_path
97+
super().__init__({})
9798

9899
def from_envvar(self, variable_name, silent=False):
99100
"""Loads a configuration from an environment variable pointing to
@@ -269,6 +270,21 @@ def get_namespace(self, namespace, lowercase=True, trim_namespace=True):
269270
rv[key] = v
270271
return rv
271272

273+
def __getitem__(self, item):
274+
try:
275+
value = super().__getitem__(item)
276+
except KeyError:
277+
value = None
278+
if value is not None:
279+
return value
280+
value = os.environ.get(item, None)
281+
if value is not None:
282+
return value
283+
return self.defaults.get(item)
284+
285+
def __getattr__(self, item):
286+
return self.__getitem__(item)
287+
272288
def __repr__(self):
273289
return '<%s %s>' % (self.__class__.__name__, dict.__repr__(self))
274290

@@ -302,6 +318,7 @@ def __repr__(self):
302318
'REPLAY_STORAGE': {'TYPE': 'server'},
303319
'LANGUAGE_CODE': 'zh',
304320
'SECURITY_MAX_IDLE_TIME': 60,
321+
'ASSET_LIST_PAGE_SIZE': 'auto',
305322
}
306323

307324
config = Config(root_path, default_config)

0 commit comments

Comments
 (0)