diff --git a/fs_attachment/tests/test_fs_storage.py b/fs_attachment/tests/test_fs_storage.py index 2dc0b5ad89..7d138a7601 100644 --- a/fs_attachment/tests/test_fs_storage.py +++ b/fs_attachment/tests/test_fs_storage.py @@ -387,6 +387,7 @@ def test_url_for_image_dir_optimized_and_not_obfuscated(self): { "name": "FS Product Image Backend", "code": "file", + "protocol": "odoofs", "base_url": "https://localhost/images", "optimizes_directory_path": True, "use_filename_obfuscation": False, diff --git a/fs_storage/README.rst b/fs_storage/README.rst index c6af7a9c5f..a4e34426cc 100644 --- a/fs_storage/README.rst +++ b/fs_storage/README.rst @@ -121,8 +121,6 @@ When you create a new backend, you must specify the following: * The protocol options. These are the options that will be passed to the fsspec python package when creating the filesystem. These options depend on the protocol used and are described in the fsspec documentation. -* Resolve env vars. This options resolves the protocol options values starting - with $ from environment variables * Check Connection Method. If set, Odoo will always check the connection before using a storage and it will remove the fs connection from the cache if the check fails. @@ -153,29 +151,6 @@ the protocol options as follows: In this example, the SimpleCacheFileSystem protocol will be used as a wrapper around the odoofs protocol. -Server Environment -~~~~~~~~~~~~~~~~~~ - -To ease the management of the filesystem storages configuration accross the different -environments, the configuration of the filesystem storages can be defined in -environment files or directly in the main configuration file. For example, the -configuration of a filesystem storage with the code `fsprod` can be provided in the -main configuration file as follows: - -.. code-block:: ini - - [fs_storage.fsprod] - protocol=s3 - options={"endpoint_url": "https://my_s3_server/", "key": "KEY", "secret": "SECRET"} - directory_path=my_bucket - -To work, a `storage.backend` record must exist with the code `fsprod` into the database. -In your configuration section, you can specify the value for the following fields: - -* `protocol` -* `options` -* `directory_path` - Migration from storage_backend ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/fs_storage/__manifest__.py b/fs_storage/__manifest__.py index 38f6c11bd7..e9cba4e2d7 100644 --- a/fs_storage/__manifest__.py +++ b/fs_storage/__manifest__.py @@ -5,14 +5,14 @@ { "name": "Filesystem Storage Backend", "summary": "Implement the concept of Storage with amazon S3, sftp...", - "version": "16.0.1.3.6", + "version": "16.0.1.3.7", "category": "FS Storage", "website": "https://github.com/OCA/storage", "author": " ACSONE SA/NV, Odoo Community Association (OCA)", "license": "LGPL-3", "development_status": "Beta", "installable": True, - "depends": ["base", "base_sparse_field", "server_environment"], + "depends": ["base", "base_sparse_field"], "data": [ "views/fs_storage_view.xml", "security/ir.model.access.csv", diff --git a/fs_storage/models/fs_storage.py b/fs_storage/models/fs_storage.py index c7f7d0b92a..06d88b867c 100644 --- a/fs_storage/models/fs_storage.py +++ b/fs_storage/models/fs_storage.py @@ -88,7 +88,6 @@ def wrapper(self, *args, **kwargs): class FSStorage(models.Model): _name = "fs.storage" - _inherit = "server.env.mixin" _description = "FS Storage" __slots__ = ("__fs", "__odoo_storage_path") @@ -142,15 +141,6 @@ def __init__(self, env, ids=(), prefetch_ids=()): inverse="_inverse_json_options", ) - eval_options_from_env = fields.Boolean( - string="Resolve env vars", - help="""Resolve options values starting with $ from environment variables. e.g - { - "endpoint_url": "$AWS_ENDPOINT_URL", - } - """, - ) - directory_path = fields.Char( help="Relative path to the directory to store the file" ) @@ -191,8 +181,6 @@ def __init__(self, env, ids=(), prefetch_ids=()): ), ] - _server_env_section_name_field = "code" - @api.model def _get_check_connection_method_selection(self): return [ @@ -200,15 +188,6 @@ def _get_check_connection_method_selection(self): ("ls", _("List File")), ] - @property - def _server_env_fields(self): - return { - "protocol": {}, - "options": {}, - "directory_path": {}, - "eval_options_from_env": {}, - } - @api.model_create_multi @prevent_call_from_safe_eval("create") def create(self, vals_list): @@ -406,32 +385,10 @@ def _recursive_add_odoo_storage_path(self, options: dict) -> dict: self._recursive_add_odoo_storage_path(target_options) return options - def _eval_options_from_env(self, options): - values = {} - for key, value in options.items(): - if isinstance(value, dict): - values[key] = self._eval_options_from_env(value) - elif isinstance(value, str) and value.startswith("$"): - env_variable_name = value[1:] - env_variable_value = os.getenv(env_variable_name) - if env_variable_value is not None: - values[key] = env_variable_value - else: - values[key] = value - _logger.warning( - "Environment variable %s is not set for fs_storage %s.", - env_variable_name, - self.display_name, - ) - else: - values[key] = value - return values - def _get_fs_options(self): - options = self.json_options - if not self.eval_options_from_env: - return options - return self._eval_options_from_env(self.json_options) + # We need this hook to be able to override + # the options in the dependent modules + return self.json_options def _get_filesystem(self) -> fsspec.AbstractFileSystem: """Get the fsspec filesystem for this backend. diff --git a/fs_storage/readme/USAGE.rst b/fs_storage/readme/USAGE.rst index 165148f14d..acda4bc44d 100644 --- a/fs_storage/readme/USAGE.rst +++ b/fs_storage/readme/USAGE.rst @@ -15,8 +15,6 @@ When you create a new backend, you must specify the following: * The protocol options. These are the options that will be passed to the fsspec python package when creating the filesystem. These options depend on the protocol used and are described in the fsspec documentation. -* Resolve env vars. This options resolves the protocol options values starting - with $ from environment variables * Check Connection Method. If set, Odoo will always check the connection before using a storage and it will remove the fs connection from the cache if the check fails. @@ -47,29 +45,6 @@ the protocol options as follows: In this example, the SimpleCacheFileSystem protocol will be used as a wrapper around the odoofs protocol. -Server Environment -~~~~~~~~~~~~~~~~~~ - -To ease the management of the filesystem storages configuration accross the different -environments, the configuration of the filesystem storages can be defined in -environment files or directly in the main configuration file. For example, the -configuration of a filesystem storage with the code `fsprod` can be provided in the -main configuration file as follows: - -.. code-block:: ini - - [fs_storage.fsprod] - protocol=s3 - options={"endpoint_url": "https://my_s3_server/", "key": "KEY", "secret": "SECRET"} - directory_path=my_bucket - -To work, a `storage.backend` record must exist with the code `fsprod` into the database. -In your configuration section, you can specify the value for the following fields: - -* `protocol` -* `options` -* `directory_path` - Migration from storage_backend ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/fs_storage/static/description/index.html b/fs_storage/static/description/index.html index da73105288..1a4ffa4dbe 100644 --- a/fs_storage/static/description/index.html +++ b/fs_storage/static/description/index.html @@ -438,23 +438,22 @@

Filesystem Storage Backend