new platform
This commit is contained in:
parent
b662fc49d7
commit
66973cc71e
@ -21,6 +21,7 @@ class PlatformClient:
|
|||||||
self.fetch_url = urllib.parse.urljoin(self.endpoint, 'fetch')
|
self.fetch_url = urllib.parse.urljoin(self.endpoint, 'fetch')
|
||||||
self.config_storage = {}
|
self.config_storage = {}
|
||||||
self.experiment_storage = {}
|
self.experiment_storage = {}
|
||||||
|
self.staff_storage = {}
|
||||||
self.poll_data()
|
self.poll_data()
|
||||||
if need_poll:
|
if need_poll:
|
||||||
self.poll_data_in_thread()
|
self.poll_data_in_thread()
|
||||||
@ -31,7 +32,7 @@ class PlatformClient:
|
|||||||
sleep(30)
|
sleep(30)
|
||||||
self.fetch()
|
self.fetch()
|
||||||
|
|
||||||
Thread(target=inner).start()
|
Thread(target=inner, daemon=True).start()
|
||||||
|
|
||||||
def poll_data(self):
|
def poll_data(self):
|
||||||
self.fetch(with_exception=True)
|
self.fetch(with_exception=True)
|
||||||
@ -62,6 +63,10 @@ class PlatformClient:
|
|||||||
local_platform = json.loads(open('local_platform.json', 'r').read())
|
local_platform = json.loads(open('local_platform.json', 'r').read())
|
||||||
self.config_storage = local_platform['configs']
|
self.config_storage = local_platform['configs']
|
||||||
self.experiment_storage = local_platform['experiments']
|
self.experiment_storage = local_platform['experiments']
|
||||||
|
self.staff_storage = {
|
||||||
|
key: set(value)
|
||||||
|
for key, value in local_platform['platform_staff'].items()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
response_data = self.request_with_retries(self.fetch_url, {
|
response_data = self.request_with_retries(self.fetch_url, {
|
||||||
'project': self.app_name,
|
'project': self.app_name,
|
||||||
@ -69,6 +74,10 @@ class PlatformClient:
|
|||||||
}, with_exception)
|
}, with_exception)
|
||||||
self.config_storage = response_data['configs']
|
self.config_storage = response_data['configs']
|
||||||
self.experiment_storage = response_data['experiments']
|
self.experiment_storage = response_data['experiments']
|
||||||
|
self.staff_storage = {
|
||||||
|
key: set(value)
|
||||||
|
for key, value in response_data['platform_staff'].items()
|
||||||
|
}
|
||||||
|
|
||||||
def fetch_configs(self, with_exception=False):
|
def fetch_configs(self, with_exception=False):
|
||||||
if self.stage == 'local':
|
if self.stage == 'local':
|
||||||
@ -97,18 +106,10 @@ class PlatformClient:
|
|||||||
self.experiment_storage[experiment] = response_data
|
self.experiment_storage[experiment] = response_data
|
||||||
|
|
||||||
def is_staff(self, **kwargs):
|
def is_staff(self, **kwargs):
|
||||||
if self.stage == 'local':
|
for key, value in kwargs.items():
|
||||||
local_platform = json.loads(open('local_platform.json', 'r').read())
|
if value in self.staff_storage[key]:
|
||||||
local_staff = local_platform['staff']
|
return True
|
||||||
for element in local_staff:
|
return False
|
||||||
for key, value in kwargs.items():
|
|
||||||
if element[key] == value:
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
response_data = self.request_with_retries(self.staff_url, kwargs)
|
|
||||||
if response_data is None:
|
|
||||||
return False
|
|
||||||
return response_data['is_staff']
|
|
||||||
|
|
||||||
def get_config(self, name):
|
def get_config(self, name):
|
||||||
return self.config_storage[name]
|
return self.config_storage[name]
|
||||||
|
Loading…
Reference in New Issue
Block a user