예제 #1
0
    def _has_valid_request_id(self, request_id):
        # Extract the timestamp from the UUID1
        timestamp = TimeUUID(request_id).get_timestamp()

        # Check to see if this request has expired
        has_valid_timestamp = time() - timestamp < self.expiry

        # Check to see if this request has been attempted before
        # (prevent replay)
        is_unused = self._has_unused_id(request_id)

        # Both checks are required to pass in order to validate the request id
        return has_valid_timestamp and is_unused
예제 #2
0
    def get_tuuid(self,
                  hex: Optional[str] = None,
                  timestamp: Optional[float] = None) -> TimeUUID:
        """
        Get a TimeUUID.

        Args:
            hex: The optional TimeUUID as hex.
            timestamp: The optional timestamp to use in the TimeUUID
        Returns:
            The TimeUUID.
        """
        if hex:
            tuuid = TimeUUID(hex=hex)
        elif timestamp:
            tuuid = TimeUUID.with_timestamp(timestamp)
        else:
            tuuid = TimeUUID.with_utcnow()

        return tuuid
예제 #3
0
def grpc_totimeUUID(uuid):
    return TimeUUID(uuid.value)