mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 08:47:40 +00:00
fea
This commit is contained in:
@@ -38,7 +38,6 @@ class IrAttachment(osv.osv):
|
|||||||
l += super(IrAttachment, self)._get_stores()
|
l += super(IrAttachment, self)._get_stores()
|
||||||
return l
|
return l
|
||||||
|
|
||||||
@api.model
|
|
||||||
def _get_blob_service_client(self):
|
def _get_blob_service_client(self):
|
||||||
"""Connect to Azure and return the blob service client
|
"""Connect to Azure and return the blob service client
|
||||||
|
|
||||||
@@ -73,7 +72,7 @@ class IrAttachment(osv.osv):
|
|||||||
"or\n"
|
"or\n"
|
||||||
"* AZURE_STORAGE_USE_AAD\n"
|
"* AZURE_STORAGE_USE_AAD\n"
|
||||||
)
|
)
|
||||||
raise exceptions.UserError(msg)
|
raise osv.except_osv(_("UserError"), msg)
|
||||||
blob_service_client = None
|
blob_service_client = None
|
||||||
if account_use_aad:
|
if account_use_aad:
|
||||||
token_credential = DefaultAzureCredential()
|
token_credential = DefaultAzureCredential()
|
||||||
@@ -90,7 +89,7 @@ class IrAttachment(osv.osv):
|
|||||||
"Error during the connection to Azure container using the "
|
"Error during the connection to Azure container using the "
|
||||||
"connection string."
|
"connection string."
|
||||||
)
|
)
|
||||||
raise exceptions.UserError(str(error))
|
raise osv.except_osv(_("UserError"), str(error))
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
sas_token = generate_account_sas(
|
sas_token = generate_account_sas(
|
||||||
@@ -109,10 +108,9 @@ class IrAttachment(osv.osv):
|
|||||||
"Error during the connection to Azure container using the Shared "
|
"Error during the connection to Azure container using the Shared "
|
||||||
"Access Signature (SAS)"
|
"Access Signature (SAS)"
|
||||||
)
|
)
|
||||||
raise exceptions.UserError(str(error))
|
raise osv.except_osv(_("UserError"), str(error))
|
||||||
return blob_service_client
|
return blob_service_client
|
||||||
|
|
||||||
@api.model
|
|
||||||
def _get_container_name(self):
|
def _get_container_name(self):
|
||||||
"""
|
"""
|
||||||
Container naming rules:
|
Container naming rules:
|
||||||
@@ -126,13 +124,12 @@ class IrAttachment(osv.osv):
|
|||||||
# lowercase, max 63 chars
|
# lowercase, max 63 chars
|
||||||
return str.lower(storage_name)[:63]
|
return str.lower(storage_name)[:63]
|
||||||
|
|
||||||
@api.model
|
|
||||||
def _get_azure_container(self, container_name=None):
|
def _get_azure_container(self, container_name=None):
|
||||||
if not container_name:
|
if not container_name:
|
||||||
container_name = self._get_container_name()
|
container_name = self._get_container_name()
|
||||||
try:
|
try:
|
||||||
blob_service_client = self._get_blob_service_client()
|
blob_service_client = self._get_blob_service_client()
|
||||||
except exceptions.UserError:
|
except Exception:
|
||||||
_logger.exception(
|
_logger.exception(
|
||||||
"error accessing to storage '%s' please check credentials ",
|
"error accessing to storage '%s' please check credentials ",
|
||||||
container_name,
|
container_name,
|
||||||
@@ -145,10 +142,9 @@ class IrAttachment(osv.osv):
|
|||||||
container_client.create_container()
|
container_client.create_container()
|
||||||
except HttpResponseError as error:
|
except HttpResponseError as error:
|
||||||
_logger.exception("Error during the creation of the Azure container")
|
_logger.exception("Error during the creation of the Azure container")
|
||||||
raise exceptions.UserError(str(error))
|
raise osv.except_osv(_("UserError"), str(error))
|
||||||
return container_client
|
return container_client
|
||||||
|
|
||||||
@api.model
|
|
||||||
def _store_file_read(self, fname, bin_size=False):
|
def _store_file_read(self, fname, bin_size=False):
|
||||||
if fname.startswith("azure://"):
|
if fname.startswith("azure://"):
|
||||||
key = fname.replace("azure://", "", 1).lower()
|
key = fname.replace("azure://", "", 1).lower()
|
||||||
@@ -170,7 +166,6 @@ class IrAttachment(osv.osv):
|
|||||||
else:
|
else:
|
||||||
return super(IrAttachment, self)._store_file_read(fname, bin_size)
|
return super(IrAttachment, self)._store_file_read(fname, bin_size)
|
||||||
|
|
||||||
@api.model
|
|
||||||
def _store_file_write(self, key, bin_data):
|
def _store_file_write(self, key, bin_data):
|
||||||
location = self.env.context.get("storage_location") or self._storage()
|
location = self.env.context.get("storage_location") or self._storage()
|
||||||
if location == "azure":
|
if location == "azure":
|
||||||
@@ -187,15 +182,15 @@ class IrAttachment(osv.osv):
|
|||||||
except HttpResponseError as error:
|
except HttpResponseError as error:
|
||||||
# log verbose error from azure, return short message for user
|
# log verbose error from azure, return short message for user
|
||||||
_logger.exception("Error during storage of the file %s" % filename)
|
_logger.exception("Error during storage of the file %s" % filename)
|
||||||
raise exceptions.UserError(
|
raise osv.except_osv(
|
||||||
_("The file could not be stored: %s") % str(error)
|
_("UserError"),
|
||||||
|
_("The file could not be stored: %s") % str(error),
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
_super = super(IrAttachment, self)
|
_super = super(IrAttachment, self)
|
||||||
filename = _super._store_file_write(key, bin_data)
|
filename = _super._store_file_write(key, bin_data)
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
@api.model
|
|
||||||
def _store_file_delete(self, fname):
|
def _store_file_delete(self, fname):
|
||||||
if fname.startswith("azure://"):
|
if fname.startswith("azure://"):
|
||||||
key = fname.replace("azure://", "", 1).lower()
|
key = fname.replace("azure://", "", 1).lower()
|
||||||
|
|||||||
Reference in New Issue
Block a user