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
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
def grpc_totimeUUID(uuid): return TimeUUID(uuid.value)