Exemple #1
0
def get_app_from_service(service, version_='') -> InstallableApp:
    try:
        if version_.upper() == 'LATEST':
            app: InstallableApp = InstallableApp.get_app(service, '')
            app.set_version(app.get_latest_release(get_github_token()))
        else:
            app: InstallableApp = InstallableApp.get_app(service, version_)
        if not version_ or version.parse(app.min_support_version) <= version.parse(app.version):
            return app
        raise NotFoundException(f'Your version need to be version >= {app.min_support_version}')
    except ModuleNotFoundError as e:
        raise NotFoundException(str(e))
Exemple #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
Exemple #3
0
 def validate_and_create_service_cmd(cls, action: str, service: str) -> str:
     try:
         app: InstallableApp = InstallableApp.get_app(service, "")
         return create_service_cmd(action, app.service_file_name)
     except ModuleNotFoundError:
         raise NotFoundException(
             f'App service {service} does not exist in our system')
Exemple #4
0
    def patch(cls, **kwargs):
        data = cls.parser_patch.parse_args()
        point: BACnetPointModel = copy.deepcopy(cls.get_point(**kwargs))
        if point is None:
            raise NotFoundException(f"Does not exist with {kwargs}")
        use_next_available_address: bool = data.get(
            'use_next_available_address')
        address: str = data.get('address')
        if use_next_available_address is not None or address is not None:
            if use_next_available_address is None:
                use_next_available_address = point.use_next_available_address
            if use_next_available_address and address:
                raise BadDataException(
                    "address needs to be null when use_next_available_address is true"
                )
            elif not use_next_available_address and not address:
                raise BadDataException(
                    "address cannot be null when use_next_available_address is false"
                )

        priority_array_write = data.pop('priority_array_write')
        non_none_data = {}
        for key in data.keys():
            if data[key] is not None:
                non_none_data[key] = data[key]
        if priority_array_write:
            PriorityArrayModel.filter_by_point_uuid(
                point.uuid).update(priority_array_write)
        BACnetPointModel.filter_by_uuid(point.uuid).update(non_none_data)
        BACServer().remove_point(point)
        point_return = BACnetPointModel.find_by_uuid(point.uuid)
        BACServer().add_point(point_return)
        return point_return
Exemple #5
0
 def patch(cls, **kwargs):
     args = parse_user_update()
     user: UserModel = cls.get_user(**kwargs)
     if user is None:
         raise NotFoundException("User does not exist")
     user.update(**args)
     return user
Exemple #6
0
 def get(cls, uuid):
     user_uuid = get_authorized_user_uuid()
     device: DeviceModel = DeviceModel.find_by_user_uuid_and_uuid(
         user_uuid, uuid)
     if device is None:
         raise NotFoundException('Device not found')
     return device
Exemple #7
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('username',
                         type=str,
                         required=True,
                         store_missing=False)
     parser.add_argument('password',
                         type=str,
                         required=True,
                         store_missing=False)
     parser.add_argument('new_password',
                         type=str,
                         required=True,
                         store_missing=False)
     args = parser.parse_args()
     username = get_authorized_username()
     user: UserModel = UserModel.find_by_username(username)
     if user is None:
         raise NotFoundException("User does not exist")
     if not (args['username'] == username
             and check_password_hash(user.password, args['password'])):
         raise UnauthorizedException("Invalid username or password")
     user.password = encrypt_password(args['new_password'])
     user.commit()
     return {'message': 'Your password has been changed successfully'}
Exemple #8
0
 def patch(cls, uuid):
     args = AdminSitesResourceByUUID.patch_parser.parse_args()
     site: SiteModel = SiteModel.find_by_uuid(uuid)
     if site is None:
         raise NotFoundException("Site not found")
     site.update(**args)
     return site
Exemple #9
0
 def validate_and_create_service_cmd(cls, action: str, service: str) -> str:
     if service in Services.__members__.keys():
         service_file_name = Services[service].value.get(
             'service_file_name')
         return create_service_cmd(action, service_file_name)
     raise NotFoundException(
         f'service {service} does not exist in our system')
Exemple #10
0
 def patch(cls, **kwargs):
     data = cls.patch_parser.parse_args()
     network: NetworkModel = cls.get_network(**kwargs)
     if network is None:
         raise NotFoundException(f"Does not exist {kwargs}")
     network.update(**data)
     return network_marshaller(cls.get_network(**kwargs), request.args)
Exemple #11
0
 def delete(cls):
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     if user is None:
         raise NotFoundException("User does not exist")
     user.delete_from_db()
     return '', 204
Exemple #12
0
 def patch(cls, **kwargs):
     data = cls.patch_parser.parse_args()
     device: DeviceModel = cls.get_device(**kwargs)
     if device is None:
         raise NotFoundException(f"Does not exist {kwargs}")
     device.update(**data)
     return device_marshaller(cls.get_device(**kwargs), request.args)
Exemple #13
0
 def delete(cls, global_uuid):
     slaves, slaves_file = cls.get_slaves()
     if global_uuid not in slaves:
         raise NotFoundException(
             f"global_uuid = {global_uuid} does not exist")
     del slaves[global_uuid]
     write_file(slaves_file, json.dumps(slaves))
     return slaves
Exemple #14
0
 def delete(cls, **kwargs):
     point: PointModel = cls.get_point(**kwargs)
     point.publish_cov(point.point_store, force_clear=True)
     if point is None:
         raise NotFoundException('Generic Point not found')
     point.delete_from_db()
     PointsRegistry().delete_point(point)
     return '', 204
Exemple #15
0
 def get(cls, uuid):
     point: PointModel = PointModel.find_by_uuid(uuid)
     if not point:
         raise NotFoundException('Generic Point not found')
     return {
         'name':
         f'{point.device.network.name}:{point.device.name}:{point.name}'
     }
Exemple #16
0
 def patch(cls):
     uuid = get_authorized_user_uuid()
     user = UserModel.find_by_uuid(uuid)
     if not user:
         raise NotFoundException("User does not exist")
     args = parse_user_update()
     user.update(**args)
     return user
Exemple #17
0
 def patch(cls, uuid):
     data = LPGBPMappingResourceByUUID.parser.parse_args()
     mapping = cls.get_mapping(uuid)
     if not mapping:
         raise NotFoundException(f'Does not exist {uuid}')
     mapping.update(**data)
     sync_point_value(mapping)
     return mapping
Exemple #18
0
 def delete(cls, uuid):
     user_uuid = get_authorized_user_uuid()
     device: DeviceModel = DeviceModel.find_by_user_uuid_and_uuid(
         user_uuid, uuid)
     if device is None:
         raise NotFoundException("Device not found")
     device.delete_from_db()
     return '', 204
Exemple #19
0
    def delete(cls, **kwargs):
        point: BACnetPointModel = cls.get_point(**kwargs)
        if not point:
            raise NotFoundException(f'Not found {kwargs}')

        if BACServer().status():
            BACServer().remove_point(point)
        point.delete_from_db()
        return '', 204
Exemple #20
0
 def patch(cls, uuid):
     data = BPGPMappingResourceByUUID.parser.parse_args()
     mapping = cls.get_mapping(uuid)
     if not mapping:
         raise NotFoundException(f'Does not exist {uuid}')
     BPGPointMapping.filter_by_uuid(uuid).update(data)
     BPGPointMapping.commit()
     output_mapping: BPGPointMapping = cls.get_mapping(uuid)
     sync_point_value(output_mapping)
     return output_mapping
Exemple #21
0
 def patch(cls, **kwargs):
     data = cls.patch_parser.parse_args()
     point: PointModel = cls.get_point(**kwargs)
     if not point:
         raise NotFoundException('Point does not exist')
     if not point.writable:
         raise BadDataException('Point is not writable')
     point.update_point_store(value=data.get('value'),
                              priority=data.get('priority'),
                              priority_array_write=data.get('priority_array_write'))
     return {}
Exemple #22
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)}
Exemple #23
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('username', type=str, required=True)
     parser.add_argument('password', type=str, required=True)
     data = parser.parse_args()
     user = UserModel.get_user()
     if user and user[
             'username'] == data['username'] and check_password_hash(
                 user['password'], data['password']):
         return UserModel.encode_jwt_token(user['username'])
     else:
         raise NotFoundException(
             'username and password combination is incorrect')
Exemple #24
0
 def patch(cls, uuid):
     parser = reqparse.RequestParser()
     parser.add_argument('device_id',
                         type=str,
                         required=False,
                         store_missing=False)
     args = parser.parse_args()
     user_uuid = get_authorized_user_uuid()
     device: DeviceModel = DeviceModel.find_by_user_uuid_and_uuid(
         user_uuid, uuid)
     if device is None:
         raise NotFoundException("Device not found")
     device.update(**args)
     return device
Exemple #25
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)
Exemple #26
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))}
Exemple #27
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('global_uuid', type=str)
     args = parser.parse_args()
     global_uuid = args['global_uuid']
     device: Dict = {**RemoteDeviceRegistry().devices[global_uuid]}  # new dict
     del device['count']
     if global_uuid not in RemoteDeviceRegistry().devices and device:
         raise NotFoundException(f"global_uuid = {global_uuid} does not exist on discovered devices list")
     slaves, slaves_file = cls.get_slaves()
     if global_uuid in slaves:
         raise BadDataException(f"global_uuid = {global_uuid} is already inserted")
     slaves[global_uuid] = device
     write_file(slaves_file, json.dumps(slaves))
     return slaves
Exemple #28
0
 def get(cls, service):
     parser = reqparse.RequestParser()
     parser.add_argument('browser_download_url', type=inputs.boolean, default=False)
     parser.add_argument('latest_version', type=inputs.boolean, default=False)
     args = parser.parse_args()
     get_browser_download_url = args['browser_download_url']
     get_latest_version = args['latest_version']
     app_settings = current_app.config[AppSetting.FLASK_KEY].installable_app_settings
     app_settings_params = []
     for app_setting in app_settings:
         if app_setting.service == service:
             app_settings_params = [app_setting]
             break
     if app_settings_params:
         return AppResource.get_installed_apps(app_settings_params, get_browser_download_url, get_latest_version)[0]
     else:
         raise NotFoundException(f'Not found service {service}')
Exemple #29
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
     }
Exemple #30
0
 def post(cls):
     parser = reqparse.RequestParser()
     parser.add_argument('username',
                         type=str,
                         required=True,
                         store_missing=False)
     parser.add_argument('password',
                         type=str,
                         required=True,
                         store_missing=False)
     args = parser.parse_args()
     user = UserModel.find_by_username(args['username'])
     if user is None:
         raise NotFoundException('User does not exist')
     if not check_password_hash(user.password, args['password']):
         raise BadDataException(
             'username and password combination is incorrect')
     return encode_jwt_token(user.uuid, user.username)