mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 02:08:36 +00:00
[14.0][IMP] attachment_azure: Allow storage name override
This commit is contained in:
committed by
Nils Hamerlinck
co-authored by
Nils Hamerlinck
parent
81f7aeca08
commit
470c4b40d5
@@ -23,6 +23,10 @@ Configure accesses with environment variables:
|
|||||||
One container will be created per database using the `RUNNING_ENV` environment variable
|
One container will be created per database using the `RUNNING_ENV` environment variable
|
||||||
and the name of the database. By default, `RUNNING_ENV` is set to `dev`.
|
and the name of the database. By default, `RUNNING_ENV` is set to `dev`.
|
||||||
|
|
||||||
|
The container name can be overridden with environment variable ``AZURE_STORAGE_NAME``.
|
||||||
|
The strings ``{db}`` and ``{env}`` can be used inside that variable and the values
|
||||||
|
will be replaced respectively by the database name and environment name.
|
||||||
|
|
||||||
This addon must be added in the server wide addons with (``--load`` option):
|
This addon must be added in the server wide addons with (``--load`` option):
|
||||||
|
|
||||||
``--load=web,attachment_azure``
|
``--load=web,attachment_azure``
|
||||||
|
|||||||
@@ -117,10 +117,15 @@ class IrAttachment(models.Model):
|
|||||||
https://docs.microsoft.com/en-us/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata#container-names
|
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")
|
||||||
|
storage_name = os.environ.get('AZURE_STORAGE_NAME', r'{env}-{db}')
|
||||||
|
storage_name = storage_name.format(
|
||||||
|
env=running_env,
|
||||||
|
db=self.env.cr.dbname
|
||||||
|
)
|
||||||
# replace invalid characters by _
|
# replace invalid characters by _
|
||||||
dbname_cleaned = re.sub(r"[\W_]+", "-", self.env.cr.dbname)
|
storage_name = re.sub(r"[\W_]+", "-", storage_name)
|
||||||
# lowercase, max 63 chars
|
# lowercase, max 63 chars
|
||||||
return str.lower(running_env + "-" + dbname_cleaned)[:63]
|
return str.lower(storage_name)[:63]
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def _get_azure_container(self):
|
def _get_azure_container(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user