From 11daf3fb7b4d056316e94775f7dd92f5cdf5c61f Mon Sep 17 00:00:00 2001 From: Patrick Tombez Date: Fri, 6 Aug 2021 09:52:21 +0200 Subject: [PATCH 1/3] [13.0][ADD] cloud_platform_azure --- cloud_platform_azure/README.md | 6 + cloud_platform_azure/__init__.py | 1 + cloud_platform_azure/__manifest__.py | 24 ++++ cloud_platform_azure/models/__init__.py | 1 + cloud_platform_azure/models/cloud_platform.py | 124 ++++++++++++++++++ 5 files changed, 156 insertions(+) create mode 100644 cloud_platform_azure/README.md create mode 100644 cloud_platform_azure/__init__.py create mode 100644 cloud_platform_azure/__manifest__.py create mode 100644 cloud_platform_azure/models/__init__.py create mode 100644 cloud_platform_azure/models/cloud_platform.py diff --git a/cloud_platform_azure/README.md b/cloud_platform_azure/README.md new file mode 100644 index 0000000..1f7bd5d --- /dev/null +++ b/cloud_platform_azure/README.md @@ -0,0 +1,6 @@ +Cloud Platform Azure +==================== + +Install addons specific to the Azure setup. + + * The object storage is Azure blob storage diff --git a/cloud_platform_azure/__init__.py b/cloud_platform_azure/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/cloud_platform_azure/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/cloud_platform_azure/__manifest__.py b/cloud_platform_azure/__manifest__.py new file mode 100644 index 0000000..292f964 --- /dev/null +++ b/cloud_platform_azure/__manifest__.py @@ -0,0 +1,24 @@ +# Copyright 2017-2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + + +{ + "name": "Cloud Platform Azure", + "summary": "Addons required for the Camptocamp Cloud Platform on Azure", + "version": "13.0.1.0.0", + "author": "Camptocamp,Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Extra Tools", + "depends": [ + "cloud_platform", + "attachment_azure", + "monitoring_prometheus", + ], + "excludes": [ + "cloud_platform_ovh", + "cloud_platform_exoscale", + ], + "website": "https://www.camptocamp.com", + "data": [], + "installable": True, +} diff --git a/cloud_platform_azure/models/__init__.py b/cloud_platform_azure/models/__init__.py new file mode 100644 index 0000000..5d08f36 --- /dev/null +++ b/cloud_platform_azure/models/__init__.py @@ -0,0 +1 @@ +from . import cloud_platform diff --git a/cloud_platform_azure/models/cloud_platform.py b/cloud_platform_azure/models/cloud_platform.py new file mode 100644 index 0000000..23b39ec --- /dev/null +++ b/cloud_platform_azure/models/cloud_platform.py @@ -0,0 +1,124 @@ +# Copyright 2016-2021 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +import re +import os + +from odoo import models, api +from odoo.addons.cloud_platform.models.cloud_platform import FilestoreKind +from odoo.addons.cloud_platform.models.cloud_platform import PlatformConfig + + +AZURE_STORE_KIND = FilestoreKind("azure", "remote") + + +class CloudPlatform(models.AbstractModel): + _inherit = "cloud.platform" + + @api.model + def _filestore_kinds(self): + kinds = super(CloudPlatform, self)._filestore_kinds() + kinds["azure"] = AZURE_STORE_KIND + return kinds + + @api.model + def _platform_kinds(self): + kinds = super(CloudPlatform, self)._platform_kinds() + kinds.append("azure") + return kinds + + @api.model + def _config_by_server_env_for_azure(self): + fs_kinds = self._filestore_kinds() + configs = { + "prod": PlatformConfig(filestore=fs_kinds["azure"]), + "integration": PlatformConfig(filestore=fs_kinds["azure"]), + "labs": PlatformConfig(filestore=fs_kinds["azure"]), + "test": PlatformConfig(filestore=fs_kinds["db"]), + "dev": PlatformConfig(filestore=fs_kinds["db"]), + } + return configs + + @api.model + def _check_filestore(self, environment_name): + params = self.env["ir.config_parameter"].sudo() + use_azure = (params.get_param("ir_attachment.location") == + AZURE_STORE_KIND.name) + if environment_name in ("prod", "integration"): + # Labs instances use azure by default, but we don't want + # to enforce it in case we want to test something with a different + # storage. At your own risks! + assert use_azure, ( + "azure must be used on production and integration instances. " + "It is activated by setting 'ir_attachment.location.' to 'azure'." + " The 'install()' function sets this option " + "automatically." + ) + if use_azure: + key_sets = [ + ["AZURE_STORAGE_USE_AAD", "AZURE_STORAGE_ACCOUNT_URL"], + ["AZURE_STORAGE_CONNECTION_STRING"], + [ + "AZURE_STORAGE_ACCOUNT_NAME", + "AZURE_STORAGE_ACCOUNT_URL", + "AZURE_STORAGE_ACCOUNT_KEY", + ], + ] + is_valid = False + for key_set in key_sets: + if all([os.environ.get(key) for key in key_set]): + is_valid = True + break + assert is_valid, ( + "When ir_attachment.location is set to 'azure', " + "at least one of the following enviromnent variable set " + "is required : {}".format( + " or ".join( + [" + ".join([key for key in key_set]) for key_set in key_sets] + ) + ) + ) + storage_name = os.environ.get("AZURE_STORAGE_NAME", "") + if environment_name in ("prod", "integration", "labs"): + assert storage_name, ( + "AZURE_STORAGE_NAME environment variable is required when " + "ir_attachment.location is 'azure'.\n" + "Normally, 'azure' is activated on labs, integration " + "and production, but should not be used in dev environment" + " (or using a dedicated dev bucket, never using the " + "integration/prod bucket).\n" + "If you don't actually need a bucket, change the" + " 'ir_attachment.location' parameter." + ) + # A bucket name is defined under the following format + # -odoo- + # + # Use AZURE_STORAGE_NAME_UNSTRUCTURED to by-pass check + # on bucket name structure + if os.environ.get("AZURE_STORAGE_NAME_UNSTRUCTURED"): + return + prod_bucket = bool(re.match(r"[a-z-0-9]+-odoo-prod", storage_name)) + if environment_name == "prod": + assert prod_bucket, ( + "AZURE_STORAGE_NAME should match '-odoo-prod', " + "we got: '%s'" % (storage_name,) + ) + else: + # if we are using the prod bucket on another instance + # such as an integration, we must be sure to be in read only! + assert not prod_bucket, ( + "AZURE_STORAGE_NAME should not match '-odoo-prod', " + "we got: '%s'" % (storage_name,) + ) + + elif environment_name == "test": + # store in DB so we don't have files local to the host + assert params.get_param("ir_attachment.location") == "db", ( + "In test instances, files must be stored in the database with " + "'ir_attachment.location' set to 'db'. This is " + "automatically set by the function 'install()'." + ) + + @api.model + def install(self): + self._install("azure") From c5fb7a20a39d57b6e9774b138ee0a5a28f08a823 Mon Sep 17 00:00:00 2001 From: Patrick Tombez Date: Wed, 13 Oct 2021 10:13:05 +0200 Subject: [PATCH 2/3] fix: Update bucket name format for new convention defined in platform specifications --- cloud_platform_azure/models/cloud_platform.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/cloud_platform_azure/models/cloud_platform.py b/cloud_platform_azure/models/cloud_platform.py index 23b39ec..a0f50a6 100644 --- a/cloud_platform_azure/models/cloud_platform.py +++ b/cloud_platform_azure/models/cloud_platform.py @@ -91,23 +91,24 @@ class CloudPlatform(models.AbstractModel): " 'ir_attachment.location' parameter." ) # A bucket name is defined under the following format - # -odoo- + # ^[a-z]+_[a-z]+_\d+$ + # Anything other than prod bucket must be suffixed with env name # # Use AZURE_STORAGE_NAME_UNSTRUCTURED to by-pass check # on bucket name structure if os.environ.get("AZURE_STORAGE_NAME_UNSTRUCTURED"): return - prod_bucket = bool(re.match(r"[a-z-0-9]+-odoo-prod", storage_name)) + prod_bucket = bool(re.match(r"^[a-z]+_[a-z]+_\d+$", storage_name)) if environment_name == "prod": assert prod_bucket, ( - "AZURE_STORAGE_NAME should match '-odoo-prod', " + "AZURE_STORAGE_NAME should match '^[a-z]+_[a-z]+_\\d+$', " "we got: '%s'" % (storage_name,) ) else: # if we are using the prod bucket on another instance # such as an integration, we must be sure to be in read only! assert not prod_bucket, ( - "AZURE_STORAGE_NAME should not match '-odoo-prod', " + "AZURE_STORAGE_NAME should not match '^[a-z]+_[a-z]+_\\d+$', " "we got: '%s'" % (storage_name,) ) From 8f3e75d8b229fbef5344fd463d4f1be11789d934 Mon Sep 17 00:00:00 2001 From: Yannick Vaucher Date: Mon, 1 Nov 2021 19:59:41 +0100 Subject: [PATCH 3/3] [MIG] cloud_platform_azure: Forwardport from 13.0 to 14.0 --- cloud_platform_azure/__manifest__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cloud_platform_azure/__manifest__.py b/cloud_platform_azure/__manifest__.py index 292f964..865e000 100644 --- a/cloud_platform_azure/__manifest__.py +++ b/cloud_platform_azure/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Cloud Platform Azure", "summary": "Addons required for the Camptocamp Cloud Platform on Azure", - "version": "13.0.1.0.0", + "version": "14.0.1.0.0", "author": "Camptocamp,Odoo Community Association (OCA)", "license": "AGPL-3", "category": "Extra Tools",