示例#1
0
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 ()
示例#2
0
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
示例#3
0
    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
示例#4
0
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
示例#5
0
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 ()
示例#6
0
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 ()
示例#7
0
def device_powered_on(data: dict, user: str, device: Device) -> Device:
    if not device.powered_on:
        raise MicroserviceException(device_powered_off)

    return device
示例#8
0
def is_owner_of_device(data: dict, user: str, device: Device) -> Device:
    if device.owner != user:
        raise MicroserviceException(permission_denied)

    return device
示例#9
0
def can_access_device(data: dict, user: str, device: Device) -> Device:
    if not device.check_access(user):
        raise MicroserviceException(permission_denied)

    return device