[FIX] attachment_azure: clean dbname to fit with container naming rules

This commit is contained in:
Nils Hamerlinck
2021-07-20 22:36:50 +07:00
parent 09641a2dc5
commit d82e0a9be9
+14 -2
View File
@@ -4,6 +4,7 @@
import io
import logging
import os
import re
from datetime import datetime, timedelta
from odoo import _, api, exceptions, models
@@ -91,9 +92,20 @@ class IrAttachment(models.Model):
return blob_service_client
@api.model
def _get_azure_container(self):
def _get_container_name(self):
"""
Container naming rules:
https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names
"""
running_env = os.environ.get("RUNNING_ENV", "dev")
container_name = str.lower(running_env + "-" + self.env.cr.dbname)
# replace invalid characters by _
dbname_cleaned = re.sub(r"[\W_]+", "-", self.env.cr.dbname)
# lowercase, max 63 chars
return str.lower(running_env + "-" + dbname_cleaned)[:63]
@api.model
def _get_azure_container(self):
container_name = self._get_container_name()
blob_service_client = self._get_blob_service_client()
container_client = blob_service_client.get_container_client(container_name)
try: