mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-03 13:18:57 -04:00
Localize notification_utils to the admin
This changeset pulls in all of the notification_utils code directly into the admin and removes it as an external dependency. We are doing this to cut down on operational maintenance of the project and will begin removing parts of it no longer needed for the admin. Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
This commit is contained in:
22
notifications_utils/base64_uuid.py
Normal file
22
notifications_utils/base64_uuid.py
Normal file
@@ -0,0 +1,22 @@
|
||||
from base64 import urlsafe_b64decode, urlsafe_b64encode
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
def base64_to_bytes(key):
|
||||
return urlsafe_b64decode(key + "==")
|
||||
|
||||
|
||||
def bytes_to_base64(bytes):
|
||||
# remove trailing = to save precious bytes
|
||||
return urlsafe_b64encode(bytes).decode("ascii").rstrip("=")
|
||||
|
||||
|
||||
def base64_to_uuid(value):
|
||||
# uuids are 16 bytes, and will always have two ==s of padding
|
||||
return UUID(bytes=urlsafe_b64decode(value.encode("ascii") + b"=="))
|
||||
|
||||
|
||||
def uuid_to_base64(value):
|
||||
if not isinstance(value, UUID):
|
||||
value = UUID(value)
|
||||
return bytes_to_base64(value.bytes)
|
||||
Reference in New Issue
Block a user