Add base64 utils.

master
Tom Hacohen 4 years ago
parent 2e9caf66f9
commit c918d3ed07

@ -1,6 +1,7 @@
import dataclasses import dataclasses
import typing as t import typing as t
import msgpack import msgpack
import base64
from fastapi import status, Query, Depends from fastapi import status, Query, Depends
from pydantic import BaseModel as PyBaseModel from pydantic import BaseModel as PyBaseModel
@ -53,6 +54,15 @@ def msgpack_decode(content):
return msgpack.unpackb(content, raw=False) return msgpack.unpackb(content, raw=False)
def b64encode(value):
return base64.urlsafe_b64encode(value).decode("ascii").strip("=")
def b64decode(data):
data += "=" * ((4 - len(data) % 4) % 4)
return base64.urlsafe_b64decode(data)
PERMISSIONS_READ = [Depends(x) for x in app_settings.API_PERMISSIONS_READ] PERMISSIONS_READ = [Depends(x) for x in app_settings.API_PERMISSIONS_READ]
PERMISSIONS_READWRITE = PERMISSIONS_READ + [Depends(x) for x in app_settings.API_PERMISSIONS_WRITE] PERMISSIONS_READWRITE = PERMISSIONS_READ + [Depends(x) for x in app_settings.API_PERMISSIONS_WRITE]

Loading…
Cancel
Save