Beispiel #1
0
    async def api_vlob_update(self, client_ctx, msg):
        """
        This API call, when successful, performs the writing of a new vlob version to the database.
        Before adding new entries, extra care should be taken in order to guarantee the consistency in
        the ordering of the different timestamps stored in the database.

        In particular, the backend server performs the following checks:
        - The vlob version must have a timestamp greater or equal than the timestamp of the previous
          version of the same vlob.
        - The vlob version must have a timestamp strictly greater than the timestamp of the last role
          certificate for the corresponding user in the corresponding realm.

        If one of those constraints is not satisfied, an error is returned with the status
        `require_greater_timestamp` indicating to the client that it should craft a new certificate
        with a timestamp strictly greater than the timestamp provided with the error.

        The `api_realm_update_roles` and `api_vlob_create` calls also perform similar checks.
        """
        msg = vlob_update_serializer.req_load(msg)

        now = pendulum_now()
        if not timestamps_in_the_ballpark(msg["timestamp"], now):
            return vlob_update_serializer.timestamp_out_of_ballpark_rep_dump(
                backend_timestamp=now, client_timestamp=msg["timestamp"])

        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 VlobRequireGreaterTimestampError as exc:
            return vlob_update_serializer.require_greater_timestamp_rep_dump(
                exc.strictly_greater_than)

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

        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"})
Beispiel #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": f"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"})