def device_online(data: dict, user: str, service: Service = None) -> Service: device_uuid = service.device if service is not None else data["device_uuid"] if not exists_device(device_uuid): raise MicroserviceException(device_not_found) if not check_device_online(device_uuid): raise MicroserviceException(device_not_online) return service if service is not None else ()
def device_exists(data: dict, user: str) -> Device: device: Optional[Device] = wrapper.session.query(Device).get(data["device_uuid"]) if device is None: raise MicroserviceException(device_not_found) return device
def deco(data: dict, user: str) -> Service: if device_required: service: Optional[Service] = wrapper.session.query( Service).filter_by(uuid=data["service_uuid"], device=data["device_uuid"]).first() else: service: Optional[Service] = wrapper.session.query( Service).filter_by(uuid=data["service_uuid"]).first() if service is None: raise MicroserviceException(service_not_found) if name is not None and service.name != name: raise MicroserviceException(service_not_found) return service
def file_exists(data: dict, user: str, device: Device) -> Tuple[Device, File]: file: Optional[File] = wrapper.session.query(File).filter_by(device=device.uuid, uuid=data["file_uuid"]).first() if file is None: raise MicroserviceException(file_not_found) return device, file
def device_accessible(data: dict, user: str, service: Service = None) -> Service: device_uuid = service.device if service is not None else data["device_uuid"] if not controls_device(device_uuid, user): raise MicroserviceException(permission_denied) return service if service is not None else ()
def has_service_and_device(data: dict, user: str): if not (isinstance(data.get("service_uuid"), str) and isinstance(data.get("device_uuid"), str)): raise MicroserviceException(invalid_request) return ()
def device_powered_on(data: dict, user: str, device: Device) -> Device: if not device.powered_on: raise MicroserviceException(device_powered_off) return device
def is_owner_of_device(data: dict, user: str, device: Device) -> Device: if device.owner != user: raise MicroserviceException(permission_denied) return device
def can_access_device(data: dict, user: str, device: Device) -> Device: if not device.check_access(user): raise MicroserviceException(permission_denied) return device