Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fs_attachment/tests/test_fs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,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,
Expand Down
38 changes: 1 addition & 37 deletions fs_storage/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

==========================
Filesystem Storage Backend
==========================
Expand All @@ -17,7 +13,7 @@ Filesystem Storage Backend
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github
Expand Down Expand Up @@ -129,9 +125,6 @@ When you create a new backend, you must specify the following:
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.
Expand Down Expand Up @@ -166,35 +159,6 @@ 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:: 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

When evaluating directory_path, ``{db_name}`` is replaced by the
database name. This is usefull in multi-tenant with a setup completly
controlled by configuration files.

Migration from storage_backend
------------------------------

Expand Down
4 changes: 2 additions & 2 deletions fs_storage/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
{
"name": "Filesystem Storage Backend",
"summary": "Implement the concept of Storage with amazon S3, sftp...",
"version": "17.0.2.1.1",
"version": "17.0.2.1.2",
"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",
Expand Down
52 changes: 3 additions & 49 deletions fs_storage/models/fs_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,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")
Expand Down Expand Up @@ -141,17 +140,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",
}
""",
)

# When accessing this field, use the method get_directory_path instead so that
# parameter expansion is done.
directory_path = fields.Char(
help="Relative path to the directory to store the file",
)
Expand Down Expand Up @@ -192,25 +180,13 @@ def __init__(self, env, ids=(), prefetch_ids=()):
),
]

_server_env_section_name_field = "code"

@api.model
def _get_check_connection_method_selection(self):
return [
("marker_file", _("Create Marker file")),
("ls", _("List File")),
]

@property
def _server_env_fields(self):
return {
"protocol": {},
"options": {},
"directory_path": {},
"eval_options_from_env": {},
"check_connection_method": {},
}

@api.model_create_multi
@prevent_call_from_safe_eval("create")
def create(self, vals_list):
Expand Down Expand Up @@ -416,32 +392,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.
Expand Down
30 changes: 0 additions & 30 deletions fs_storage/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ When you create a new backend, you must specify the following:
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.
Expand Down Expand Up @@ -51,34 +49,6 @@ 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:

``` 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

When evaluating directory_path, `{db_name}` is replaced by the database name.
This is usefull in multi-tenant with a setup completly controlled by
configuration files.

## Migration from storage_backend

The fs_storage addon can be used to replace the storage_backend addon.
Expand Down
Loading
Loading