* feat(backend): implemented azure blob storage support * feat(backend): added azure implementation to backend services * feat(backend): added azure blob storage support to chalice service * fix(backend): removed prev version of s3 * feat(backend): moved azure support to ee subfolder * feat(backend): prepared ee code for new utils.objects package * feat(backend): added missed modules to go.mod * feat(backend): added missed modules to go.sum * feat(backend): go mod tidy * feat(backend): temporary made s3 vars are not required * feat(backend): added azure lib to ee chalice * feat(api): changed azure env var name * feat(api): added new object store and extra methods to chalice ee * fix(api): added azure blob lib to alerts * fix(api): fixed incorrect call in sessions_devtool * fix(crons): added azure blob storage library to requirements list * chore(build): Error message for not providing flag. Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * feat(backend): removed ios headers and object store for ios messages * feat(backend): object config refactoring * chore(helm): Update BUCKET_NAME * fix(backend): removed object storage usage in http * feat(backend): added debug logs to azure upload method * fix(backend): fixed empty folder issue * fix(backend): removed extra debug log * chore(helm): Adding global variables for crons * chore(helm): Remove clickhouse resource limit Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> * fix(backend): removed assets debug log * feat(api): use ABC class instead of empty interface * feat(api): renamed helpers to generators * feat(api): changed prep/clean dev scripts * feat(api): changed name obj_store -> StorageClient * feat(api): some changes after code review * fix(api): removed unnecesery packages in oss api * feat(backend): moved azure implementation to ee folder --------- Signed-off-by: rjshrjndrn <rjshrjndrn@gmail.com> Co-authored-by: rjshrjndrn <rjshrjndrn@gmail.com>
55 lines
2.7 KiB
Python
55 lines
2.7 KiB
Python
from decouple import config
|
|
from datetime import datetime, timedelta
|
|
from chalicelib.utils.objects.interface import ObjectStorage
|
|
from azure.storage.blob import BlobServiceClient, BlobSasPermissions, generate_blob_sas
|
|
|
|
|
|
class AzureBlobStorage(ObjectStorage):
|
|
# Prepare blob storage client
|
|
client = BlobServiceClient(
|
|
account_url=f"https://{config('AZURE_ACCOUNT_NAME')}.blob.core.windows.net",
|
|
credential=config("AZURE_ACCOUNT_KEY"),
|
|
)
|
|
|
|
def exists(self, bucket, key):
|
|
return self.client.get_blob_client(bucket, key).exists()
|
|
|
|
def get_presigned_url_for_sharing(self, bucket, expires_in, key, check_exists=False):
|
|
blob_client = self.client.get_blob_client(bucket, key)
|
|
if check_exists and not blob_client.exists():
|
|
return None
|
|
|
|
blob_sas = generate_blob_sas(account_name=config("AZURE_ACCOUNT_NAME"),
|
|
container_name=bucket,
|
|
blob_name=key,
|
|
account_key=config("AZURE_ACCOUNT_KEY"),
|
|
permission=BlobSasPermissions(read=True),
|
|
expiry=datetime.utcnow() + timedelta(seconds=expires_in),
|
|
)
|
|
return f"https://{config('AZURE_ACCOUNT_NAME')}.blob.core.windows.net/{bucket}/{key}?{blob_sas}"
|
|
|
|
def get_presigned_url_for_upload(self, bucket, expires_in, key, **args):
|
|
blob_sas = generate_blob_sas(account_name=config("AZURE_ACCOUNT_NAME"),
|
|
container_name=bucket,
|
|
blob_name=key,
|
|
account_key=config("AZURE_ACCOUNT_KEY"),
|
|
permission=BlobSasPermissions(write=True),
|
|
expiry=datetime.utcnow() + timedelta(seconds=expires_in),
|
|
)
|
|
return f"https://{config('AZURE_ACCOUNT_NAME')}.blob.core.windows.net/{bucket}/{key}?{blob_sas}"
|
|
|
|
def get_file(self, source_bucket, source_key):
|
|
blob_client = self.client.get_blob_client(source_bucket, source_key)
|
|
return blob_client.download_blob().readall()
|
|
|
|
def tag_for_deletion(self, bucket, key):
|
|
blob_client = self.client.get_blob_client(bucket, key)
|
|
if not blob_client.exists():
|
|
return False
|
|
blob_tags = blob_client.get_blob_tags()
|
|
blob_client.start_copy_from_url(
|
|
source_url=f"https://{config('AZURE_ACCOUNT_NAME')}.blob.core.windows.net/{bucket}/{key}",
|
|
requires_sync=True,
|
|
)
|
|
blob_tags["to_delete_in_days"] = config("SCH_DELETE_DAYS", default='7')
|
|
blob_client.set_blob_tags(blob_tags)
|