Skip to content

Commit 33155f9

Browse files
committed
[16.0][ADD] fs_storage_environment: make server_environment an optional dependency
1 parent 542f37a commit 33155f9

15 files changed

Lines changed: 752 additions & 0 deletions

File tree

fs_storage_environment/README.rst

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
.. image:: https://odoo-community.org/readme-banner-image
2+
:target: https://odoo-community.org/get-involved?utm_source=readme
3+
:alt: Odoo Community Association
4+
5+
===============================================
6+
Filesystem Storage Backend - Server Environment
7+
===============================================
8+
9+
..
10+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11+
!! This file is generated by oca-gen-addon-readme !!
12+
!! changes will be overwritten. !!
13+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
14+
!! source digest: sha256:156bf422ce912fb80137f8203230a58ff1f4159a2f6befa17aa9eec9fb6dbcd5
15+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
16+
17+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
18+
:target: https://odoo-community.org/page/development-status
19+
:alt: Beta
20+
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
21+
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
22+
:alt: License: LGPL-3
23+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github
24+
:target: https://github.com/OCA/storage/tree/16.0/fs_storage_environment
25+
:alt: OCA/storage
26+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
27+
:target: https://translation.odoo-community.org/projects/storage-16-0/storage-16-0-fs_storage_environment
28+
:alt: Translate me on Weblate
29+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
30+
:target: https://runboat.odoo-community.org/builds?repo=OCA/storage&target_branch=16.0
31+
:alt: Try me on Runboat
32+
33+
|badge1| |badge2| |badge3| |badge4| |badge5|
34+
35+
Glue module to make Server Environment features available for the Filesystem Storage Backend addon.
36+
37+
**Table of contents**
38+
39+
.. contents::
40+
:local:
41+
42+
Usage
43+
=====
44+
45+
Configuration
46+
~~~~~~~~~~~~~
47+
48+
When you create a new backend, you must specify the following:
49+
50+
* Resolve env vars. This options resolves the protocol options values starting
51+
with $ from environment variables
52+
53+
Server Environment
54+
~~~~~~~~~~~~~~~~~~
55+
56+
To ease the management of the filesystem storages configuration accross the different
57+
environments, the configuration of the filesystem storages can be defined in
58+
environment files or directly in the main configuration file. For example, the
59+
configuration of a filesystem storage with the code `fsprod` can be provided in the
60+
main configuration file as follows:
61+
62+
.. code-block:: ini
63+
64+
[fs_storage.fsprod]
65+
protocol=s3
66+
options={"endpoint_url": "https://my_s3_server/", "key": "KEY", "secret": "SECRET"}
67+
directory_path=my_bucket
68+
69+
To work, a `storage.backend` record must exist with the code `fsprod` into the database.
70+
In your configuration section, you can specify the value for the following fields:
71+
72+
* `protocol`
73+
* `options`
74+
* `directory_path`
75+
76+
Bug Tracker
77+
===========
78+
79+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/storage/issues>`_.
80+
In case of trouble, please check there if your issue has already been reported.
81+
If you spotted it first, help us to smash it by providing a detailed and welcomed
82+
`feedback <https://github.com/OCA/storage/issues/new?body=module:%20fs_storage_environment%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
83+
84+
Do not contact contributors directly about support or help with technical issues.
85+
86+
Credits
87+
=======
88+
89+
Authors
90+
~~~~~~~
91+
92+
* ACSONE SA/NV
93+
94+
Contributors
95+
~~~~~~~~~~~~
96+
97+
* Laurent Mignon <laurent.mignon@acsone.eu>
98+
* Sébastien BEAU <sebastien.beau@akretion.com>
99+
* Maksym Yankin <maksym.yankin@camptocamp.com>
100+
101+
Maintainers
102+
~~~~~~~~~~~
103+
104+
This module is maintained by the OCA.
105+
106+
.. image:: https://odoo-community.org/logo.png
107+
:alt: Odoo Community Association
108+
:target: https://odoo-community.org
109+
110+
OCA, or the Odoo Community Association, is a nonprofit organization whose
111+
mission is to support the collaborative development of Odoo features and
112+
promote its widespread use.
113+
114+
This module is part of the `OCA/storage <https://github.com/OCA/storage/tree/16.0/fs_storage_environment>`_ project on GitHub.
115+
116+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

fs_storage_environment/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2017 Akretion (http://www.akretion.com).
2+
# @author Sébastien BEAU <sebastien.beau@akretion.com>
3+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
4+
5+
{
6+
"name": "Filesystem Storage Backend - Server Environment",
7+
"summary": "Use Server Environment feature to manage the concept of Storage",
8+
"version": "16.0.1.0.0",
9+
"category": "FS Storage",
10+
"website": "https://github.com/OCA/storage",
11+
"author": " ACSONE SA/NV, Odoo Community Association (OCA)",
12+
"license": "LGPL-3",
13+
"development_status": "Beta",
14+
"installable": True,
15+
"depends": ["fs_storage", "server_environment"],
16+
"data": [
17+
"views/fs_storage_view.xml",
18+
],
19+
"auto_install": True,
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import fs_storage
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2023 ACSONE SA/NV (https://www.acsone.eu).
2+
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
3+
import logging
4+
import os
5+
6+
from odoo import fields, models
7+
8+
_logger = logging.getLogger(__name__)
9+
10+
11+
class FSStorage(models.Model):
12+
_name = "fs.storage"
13+
_inherit = ["fs.storage", "server.env.mixin"]
14+
15+
eval_options_from_env = fields.Boolean(
16+
string="Resolve env vars",
17+
help="""Resolve options values starting with $ from environment variables. e.g
18+
{
19+
"endpoint_url": "$AWS_ENDPOINT_URL",
20+
}
21+
""",
22+
)
23+
24+
_server_env_section_name_field = "code"
25+
26+
@property
27+
def _server_env_fields(self):
28+
return {
29+
"protocol": {},
30+
"options": {},
31+
"directory_path": {},
32+
"eval_options_from_env": {},
33+
}
34+
35+
def _eval_options_from_env(self, options):
36+
values = {}
37+
for key, value in options.items():
38+
if isinstance(value, dict):
39+
values[key] = self._eval_options_from_env(value)
40+
elif isinstance(value, str) and value.startswith("$"):
41+
env_variable_name = value[1:]
42+
env_variable_value = os.getenv(env_variable_name)
43+
if env_variable_value is not None:
44+
values[key] = env_variable_value
45+
else:
46+
values[key] = value
47+
_logger.warning(
48+
"Environment variable %s is not set for fs_storage %s.",
49+
env_variable_name,
50+
self.display_name,
51+
)
52+
else:
53+
values[key] = value
54+
return values
55+
56+
def _get_fs_options(self):
57+
# OVERRIDE: to resolve env vars in options
58+
if not self.eval_options_from_env:
59+
return super()._get_fs_options()
60+
return self._eval_options_from_env(self.json_options)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* Laurent Mignon <laurent.mignon@acsone.eu>
2+
* Sébastien BEAU <sebastien.beau@akretion.com>
3+
* Maksym Yankin <maksym.yankin@camptocamp.com>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Glue module to make Server Environment features available for the Filesystem Storage Backend addon.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Configuration
2+
~~~~~~~~~~~~~
3+
4+
When you create a new backend, you must specify the following:
5+
6+
* Resolve env vars. This options resolves the protocol options values starting
7+
with $ from environment variables
8+
9+
Server Environment
10+
~~~~~~~~~~~~~~~~~~
11+
12+
To ease the management of the filesystem storages configuration accross the different
13+
environments, the configuration of the filesystem storages can be defined in
14+
environment files or directly in the main configuration file. For example, the
15+
configuration of a filesystem storage with the code `fsprod` can be provided in the
16+
main configuration file as follows:
17+
18+
.. code-block:: ini
19+
20+
[fs_storage.fsprod]
21+
protocol=s3
22+
options={"endpoint_url": "https://my_s3_server/", "key": "KEY", "secret": "SECRET"}
23+
directory_path=my_bucket
24+
25+
To work, a `storage.backend` record must exist with the code `fsprod` into the database.
26+
In your configuration section, you can specify the value for the following fields:
27+
28+
* `protocol`
29+
* `options`
30+
* `directory_path`
9.23 KB
Loading

0 commit comments

Comments
 (0)