Ejemplo n.º 1
0
 def get(cls):
     service: str = request.args.get('service')
     if not service:
         raise BadDataException("Include ?service as an argument")
     app: InstallableApp = get_app_from_service(service)
     if app.app_type == Types.APT_APP.value:
         return {"data": read_file(app.app_setting.config_file)}
     else:
         filename = 'config.json'
         directory = os.path.join(app.get_global_dir(), 'config')
         file = os.path.join(directory, filename)
         if not os.path.exists(file):
             raise NotFoundException(
                 f'Service {service} does not have {filename}')
         return {"data": json.loads(read_file(file))}
Ejemplo n.º 2
0
def update_plugin_download_state(state: DownloadState, service: str, _version: str = "",
                                 plugins: List[Dict] = None):
    app_setting = current_app.config[AppSetting.FLASK_KEY]
    plugin_download_state = json.loads(read_file(app_setting.plugin_download_status_file) or "{}")
    write_file(app_setting.plugin_download_status_file,
               json.dumps({**plugin_download_state,
                           service: {"state": state.name, "version": _version, "plugins": plugins if plugins else []}}))
Ejemplo n.º 3
0
 def get_app_state(cls) -> AppState:
     app_setting = current_app.config[AppSetting.FLASK_KEY]
     app_state: str = read_file(app_setting.app_state_file)
     app_states: List[str] = list(map(lambda a: a.name, AppState))
     if app_state in app_states:
         return AppState[app_state]
     return AppState.FINISHED
Ejemplo n.º 4
0
 def __handle_secret_key(secret_key_file) -> str:
     if AppSetting.auth:
         existing_secret_key = read_file(secret_key_file)
         if existing_secret_key.strip():
             return existing_secret_key
         secret_key = AppSetting.__create_secret_key()
         write_file(secret_key_file, secret_key)
         return secret_key
     return ''
Ejemplo n.º 5
0
 def get(cls):
     service: str = request.args.get('service')
     if not service:
         raise BadDataException("Include ?service as an argument")
     app: InstallableApp = get_app_from_service(service)
     filename = 'logging.conf'
     directory = os.path.join(app.get_global_dir(), 'config')
     file = os.path.join(directory, filename)
     if not os.path.exists(file):
         raise NotFoundException(
             f'Service {service} does not have {filename}')
     return {"data": read_file(file)}
Ejemplo n.º 6
0
def upgrade_001():
    device_info = json.loads(read_file('/data/rubix-registry/wires-plat.json') or "{}")
    if device_info and not get_device_info():
        put_device_info(DeviceInfoModel(**device_info))
Ejemplo n.º 7
0
 def get_user(cls) -> Dict:
     app_setting = current_app.config[AppSetting.FLASK_KEY]
     user = read_file(app_setting.users_file).split(":")
     if len(user) >= 2:
         return {'username': user[0], 'password': user[1]}
     return {}
Ejemplo n.º 8
0
 def create_user(cls, username='******', password='******'):
     app_setting = current_app.config[AppSetting.FLASK_KEY]
     existing_users = read_file(app_setting.users_file).split()
     if not existing_users:
         UserModel.update_user(username, password)
Ejemplo n.º 9
0
def get_plugin_download_state(service: str):
    app_setting = current_app.config[AppSetting.FLASK_KEY]
    plugin_download_state = json.loads(read_file(app_setting.plugin_download_status_file) or "{}")
    return plugin_download_state.get(service, {}) or {
        "state": DownloadState.CLEARED.name, "version": "", "plugins": []}
Ejemplo n.º 10
0
def get_download_state():
    app_setting = current_app.config[AppSetting.FLASK_KEY]
    return json.loads(read_file(app_setting.download_status_file) or "{}") or {
        "state": DownloadState.CLEARED.name, "services": []}
Ejemplo n.º 11
0
 def get_slaves_by_app_setting(cls, app_setting: AppSetting):
     data_dir: str = app_setting.data_dir
     slaves_file = os.path.join(data_dir, AppSetting.default_slaves_file)
     slaves: Dict[str, Dict] = json.loads(read_file(slaves_file) or "{}")
     return slaves, slaves_file
Ejemplo n.º 12
0
def get_service_restart_jobs() -> dict:
    app_setting: AppSetting = current_app.config[AppSetting.FLASK_KEY]
    return json.loads(read_file(app_setting.service_restart_job_file) or "{}")
Ejemplo n.º 13
0
def get_internal_token(app_setting: AppSetting) -> str:
    return read_file(app_setting.internal_token_file)