mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 08:47:40 +00:00
[FIX] attachment_azure: clean dbname to fit with container naming rules
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from odoo import _, api, exceptions, models
|
from odoo import _, api, exceptions, models
|
||||||
@@ -91,9 +92,20 @@ class IrAttachment(models.Model):
|
|||||||
return blob_service_client
|
return blob_service_client
|
||||||
|
|
||||||
@api.model
|
@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")
|
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()
|
blob_service_client = self._get_blob_service_client()
|
||||||
container_client = blob_service_client.get_container_client(container_name)
|
container_client = blob_service_client.get_container_client(container_name)
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user