Exemplo n.º 1
0
 def post(cls):
     args = request.get_json()
     if not validate_args(args, delete_data_attributes):
         raise BadDataException('Invalid request')
     delete_data_res = []
     for arg in args:
         service: str = arg['service'].upper()
         app: InstallableApp = get_app_from_service(service)
         try:
             res = {
                 'service': service,
                 'deletion': False,
                 'backup_data': False,
                 'stop': False,
                 'error': ''
             }
             stop: bool = app.stop()
             backup_data: bool = app.backup_data()
             deletion: bool = delete_existing_folder(app.get_data_dir())
             res = {
                 **res, 'deletion': deletion,
                 'backup_data': backup_data,
                 'stop': stop
             }
         except Exception as e:
             res = {'error': str(e)}
         delete_data_res.append(res)
     return delete_data_res
Exemplo n.º 2
0
    def get(cls, service):
        if service == OPEN_VPN_CLIENT:
            return ["v0.0.0"]
        token: str = get_github_token()
        headers = {}
        if token:
            headers['Authorization'] = f'Bearer {token}'
        app = get_app_from_service(service)
        resp = requests.get(app.get_releases_link(), headers=headers)
        data = json.loads(resp.content)
        releases = []
        try:
            all_releases: bool = False
            if 'all' in request.args:
                all_releases = bool(strtobool(request.args['all']))
        except Exception:
            raise BadDataException('Invalid query string')

        for row in data:
            if isinstance(row, str):
                raise PreConditionException(data)
            if all_releases:
                releases.append(row.get('tag_name'))
            elif version.parse(app.min_support_version) <= version.parse(row.get('tag_name')):
                releases.append(row.get('tag_name'))
        if not releases:
            raise NotFoundException(f'No version found, check your repo with version >= {app.min_support_version}')
        return releases
Exemplo n.º 3
0
 def get(cls, service):
     service = service.upper()
     token: str = get_github_token()
     app: InstallableApp = get_app_from_service(service)
     _version: str = app.get_installed_version()
     if not _version:
         return {"message": f"Please install service {service} first"}
     app.set_version(_version)
     return app.get_plugin_list(token)
Exemplo n.º 4
0
 def delete(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('service', type=str, required=True)
     args = parser.parse_args()
     service = args['service'].upper()
     app: InstallableApp = get_app_from_service(service)
     delete = app.delete_env_file()
     app_details = get_installed_app_details(app) or {}
     return {'service': service, 'delete': delete, **app_details}
Exemplo n.º 5
0
 def put(cls):
     args = request.get_json()
     if args is None:
         raise BadDataException("Invalid request")
     service = args.get('service', '').upper()
     data = args.get('data', None)
     app: InstallableApp = get_app_from_service(service)
     update = app.update_config_file(data)
     app_details = get_installed_app_details(app) or {}
     return {'service': service, 'update': update, **app_details}
Exemplo n.º 6
0
 def put(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('service', type=str, required=True)
     parser.add_argument('data', type=str, required=True)
     args = parser.parse_args()
     service = args['service'].upper()
     data: str = args['data']
     app: InstallableApp = get_app_from_service(service)
     update = app.update_logging_file(data)
     app_details = get_installed_app_details(app) or {}
     return {'service': service, 'update': update, **app_details}
Exemplo n.º 7
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)}
Exemplo n.º 8
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 not is_dir_exist(app.get_data_dir()):
         raise NotFoundException(f'Service {service} does not have any data to download')
     file = app.download_data()
     if request.args.get('bridge'):
         raise NotImplementedException("We don't have the application/zip download support yet!")
     return send_file(file,
                      mimetype='application/zip',
                      attachment_filename=f'{service}_DATA_{datetime.now().strftime("%Y%m%d%H%M%S")}.zip',
                      as_attachment=True)
Exemplo n.º 9
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))}
Exemplo n.º 10
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('service', type=str, required=True)
     args = parser.parse_args()
     service: str = args['service'].upper()
     app: InstallableApp = get_app_from_service(service)
     version: str = app.get_installed_version()
     if not version:
         raise NotFoundException(f'service {service} is not running')
     app.set_version(version)
     deletion: bool = app.uninstall()
     existing_apps_deletion: bool = delete_existing_folder(
         app.get_installation_dir())
     return {
         'service': service,
         'deletion': deletion,
         'existing_apps_deletion': existing_apps_deletion
     }
Exemplo n.º 11
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('service', type=str, required=True)
     parser.add_argument('version', type=str, required=True)
     parser.add_argument('file',
                         type=FileStorage,
                         location='files',
                         required=True)
     args = parser.parse_args()
     service = args['service'].upper()
     version = args['version']
     file = args['file']
     match: bool = Version._regex.search(version)
     if not match:
         raise BadDataException(
             f'Invalid version, version needs to be like v1.0.0, v1.1.0')
     app: InstallableApp = get_app_from_service(service, version)
     return app.upload(file)
Exemplo n.º 12
0
 def post(cls, service):
     service = service.upper()
     args = request.get_json()
     if not validate_args(args, install_plugin_attributes):
         raise BadDataException('Invalid request')
     uninstall_res = []
     try:
         app: InstallableApp = get_app_from_service(service)
         for arg in args:
             plugin: str = arg["plugin"].lower()
             installation = app.uninstall_plugin(plugin)
             uninstall_res.append({
                 'plugin': plugin,
                 'uninstall': installation,
                 'error': ''
             })
     except (Exception, NotFoundException) as e:
         raise NotFoundException(str(e))
     return uninstall_res
Exemplo n.º 13
0
 def post(cls, service):
     service = service.upper()
     args = request.get_json()
     if not validate_args(args, download_plugin_attributes):
         raise BadDataException('Invalid request')
     download_state: str = get_plugin_download_state(service).get('state')
     if download_state == DownloadState.DOWNLOADING.name:
         raise PreConditionException('Download is in progress')
     elif download_state == DownloadState.DOWNLOADED.name:
         raise PreConditionException('Download state is not cleared')
     app: InstallableApp = get_app_from_service(service)
     _version: str = app.get_installed_version()
     if not _version:
         return {"message": f"Please install service {service} first"}
     app.set_version(_version)
     update_plugin_download_state(DownloadState.DOWNLOADING, service,
                                  _version)
     gevent.spawn(download_plugins_async,
                  current_app._get_current_object().app_context, app, args)
     return {"message": "Download started"}
Exemplo n.º 14
0
 def delete(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('service', type=str, required=True)
     args = parser.parse_args()
     service = args['service'].upper()
     res = {
         'service': service,
         'delete': False,
         'update': False,
         'state': '',
         'error': ''
     }
     try:
         app: InstallableApp = get_app_from_service(service)
         delete = app.delete_config_file()
         app_details = get_installed_app_details(app) or {}
         res = {**res, 'delete': delete, **app_details}
     except Exception as e:
         res = {**res, 'error': str(e)}
     return res
Exemplo n.º 15
0
 def post(cls, service):
     service = service.upper()
     args = request.get_json()
     if not validate_args(args, install_plugin_attributes):
         raise BadDataException('Invalid request')
     install_res = []
     try:
         app: InstallableApp = get_app_from_service(service)
         _version: str = app.get_installed_version()
         if not _version:
             return {"message": f"Please install service {service} first"}
         for arg in args:
             plugin: str = arg["plugin"].lower()
             installation = app.install_plugin(plugin)
             install_res.append({
                 'plugin': plugin,
                 'installation': installation,
                 'error': ''
             })
     except (Exception, NotFoundException) as e:
         raise NotFoundException(str(e))
     return install_res
Exemplo n.º 16
0
 def get_installed_app_stat(cls, app: InstallableApp,
                            get_browser_download_url: bool) -> dict:
     details: dict = {}
     is_installed: bool = False
     _browser_download_url = {}
     if systemctl_installed(app.service_file_name):
         details = get_installed_app_details(app)
         if details:
             is_installed = True
             app: InstallableApp = get_app_from_service(details['service'])
             app.set_version(details['version'])
             if get_browser_download_url:
                 try:
                     _browser_download_url = app.get_download_link(
                         get_github_token(), True)
                 except Exception as e:
                     logger.error(str(e))
     return {
         **(details if details else app.to_property_dict()),
         **_browser_download_url,
         'service': app.service,
         'is_installed': is_installed,
     }
Exemplo n.º 17
0
 def delete(cls, service):
     service = service.upper()
     get_app_from_service(service)
     update_plugin_download_state(DownloadState.CLEARED, service)
     return {'message': 'Download state is cleared'}
Exemplo n.º 18
0
 def get(cls, service):
     service = service.upper()
     get_app_from_service(service)
     return get_plugin_download_state(service)