mirror of
https://codeberg.org/vlw/cloud-backup.git
synced 2025-09-14 10:03:40 +02:00
31 lines
No EOL
750 B
Python
31 lines
No EOL
750 B
Python
import os
|
|
from azure.storage.blob import BlobServiceClient
|
|
|
|
from ..fs.utils import get_file
|
|
|
|
class StorageClient:
|
|
def __init__(self):
|
|
self.client = BlobServiceClient.from_connection_string(os.getenv("SERVICE_KEY"))
|
|
|
|
self._error = None
|
|
|
|
@property
|
|
def error(self):
|
|
return self._error
|
|
|
|
@error.setter
|
|
def error(self, state):
|
|
self._error = state
|
|
|
|
def upload(self, path: str) -> bool:
|
|
name = get_file(path)
|
|
blob = self.client.get_blob_client(container=os.getenv("TARGET_BUCKET"), blob=name)
|
|
|
|
try:
|
|
with open(path, "rb") as f:
|
|
blob.upload_blob(f,overwrite=True)
|
|
return True
|
|
except Exception as e:
|
|
if e.response.status_code == 403:
|
|
self.error = "Azure: Access key invalid or lacking required permissions"
|
|
return False |