Exemplo n.º 1
0
    async def api_vlob_read(self, client_ctx, msg):
        msg = vlob_read_serializer.req_load(msg)

        try:
            version, blob, author, created_on = await self.read(
                client_ctx.organization_id, client_ctx.device_id, **msg
            )

        except VlobNotFoundError as exc:
            return vlob_read_serializer.rep_dump({"status": "not_found", "reason": str(exc)})

        except VlobAccessError:
            return vlob_read_serializer.rep_dump({"status": "not_allowed"})

        except VlobVersionError:
            return vlob_read_serializer.rep_dump({"status": "bad_version"})

        except VlobTimestampError:
            return vlob_read_serializer.rep_dump({"status": "bad_timestamp"})

        except VlobEncryptionRevisionError:
            return vlob_create_serializer.rep_dump({"status": "bad_encryption_revision"})

        except VlobInMaintenanceError:
            return vlob_read_serializer.rep_dump({"status": "in_maintenance"})

        return vlob_read_serializer.rep_dump(
            {
                "status": "ok",
                "blob": blob,
                "version": version,
                "author": author,
                "timestamp": created_on,
            }
        )
Exemplo n.º 2
0
    async def api_vlob_update(self, client_ctx, msg):
        msg = vlob_update_serializer.req_load(msg)

        now = pendulum.now()
        if not timestamps_in_the_ballpark(msg["timestamp"], now):
            return {"status": "bad_timestamp", "reason": "Timestamp is out of date."}

        try:
            await self.update(client_ctx.organization_id, client_ctx.device_id, **msg)

        except VlobNotFoundError as exc:
            return vlob_update_serializer.rep_dump({"status": "not_found", "reason": str(exc)})

        except VlobAccessError:
            return vlob_update_serializer.rep_dump({"status": "not_allowed"})

        except VlobVersionError:
            return vlob_update_serializer.rep_dump({"status": "bad_version"})

        except VlobTimestampError:
            return vlob_update_serializer.rep_dump({"status": "bad_timestamp"})

        except VlobEncryptionRevisionError:
            return vlob_create_serializer.rep_dump({"status": "bad_encryption_revision"})

        except VlobInMaintenanceError:
            return vlob_update_serializer.rep_dump({"status": "in_maintenance"})

        return vlob_update_serializer.rep_dump({"status": "ok"})
Exemplo n.º 3
0
    async def api_vlob_maintenance_get_reencryption_batch(self, client_ctx, msg):
        msg = vlob_maintenance_get_reencryption_batch_serializer.req_load(msg)

        try:
            batch = await self.maintenance_get_reencryption_batch(
                client_ctx.organization_id, client_ctx.device_id, **msg
            )

        except VlobAccessError:
            return vlob_maintenance_get_reencryption_batch_serializer.rep_dump(
                {"status": "not_allowed"}
            )

        except VlobNotFoundError as exc:
            return vlob_maintenance_get_reencryption_batch_serializer.rep_dump(
                {"status": "not_found", "reason": str(exc)}
            )

        except VlobNotInMaintenanceError as exc:
            return vlob_maintenance_get_reencryption_batch_serializer.rep_dump(
                {"status": "not_in_maintenance", "reason": str(exc)}
            )

        except VlobEncryptionRevisionError:
            return vlob_create_serializer.rep_dump({"status": "bad_encryption_revision"})

        except VlobMaintenanceError as exc:
            return vlob_maintenance_get_reencryption_batch_serializer.rep_dump(
                {"status": "maintenance_error", "reason": str(exc)}
            )

        return vlob_maintenance_get_reencryption_batch_serializer.rep_dump(
            {
                "status": "ok",
                "batch": [
                    {"vlob_id": vlob_id, "version": version, "blob": blob}
                    for vlob_id, version, blob in batch
                ],
            }
        )
Exemplo n.º 4
0
    async def api_vlob_maintenance_save_reencryption_batch(self, client_ctx, msg):
        msg = vlob_maintenance_save_reencryption_batch_serializer.req_load(msg)

        try:
            total, done = await self.maintenance_save_reencryption_batch(
                client_ctx.organization_id,
                client_ctx.device_id,
                realm_id=msg["realm_id"],
                encryption_revision=msg["encryption_revision"],
                batch=[(x["vlob_id"], x["version"], x["blob"]) for x in msg["batch"]],
            )

        except VlobAccessError:
            return vlob_maintenance_save_reencryption_batch_serializer.rep_dump(
                {"status": "not_allowed"}
            )

        except VlobNotFoundError as exc:
            return vlob_maintenance_save_reencryption_batch_serializer.rep_dump(
                {"status": "not_found", "reason": str(exc)}
            )

        except VlobNotInMaintenanceError as exc:
            return vlob_maintenance_get_reencryption_batch_serializer.rep_dump(
                {"status": "not_in_maintenance", "reason": str(exc)}
            )

        except VlobEncryptionRevisionError:
            return vlob_create_serializer.rep_dump({"status": "bad_encryption_revision"})

        except VlobMaintenanceError as exc:
            return vlob_maintenance_save_reencryption_batch_serializer.rep_dump(
                {"status": "maintenance_error", "reason": str(exc)}
            )

        return vlob_maintenance_save_reencryption_batch_serializer.rep_dump(
            {"status": "ok", "total": total, "done": done}
        )