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))}
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 []}}))
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
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 ''
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)}
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))
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 {}
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)
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": []}
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": []}
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
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 "{}")
def get_internal_token(app_setting: AppSetting) -> str: return read_file(app_setting.internal_token_file)