Skip to content

Commit 772eb66

Browse files
committed
[18.0][ADD] fs_storage_environment: make server_environment an optional dependency
1 parent f159d82 commit 772eb66

14 files changed

Lines changed: 745 additions & 0 deletions

File tree

fs_storage_environment/README.rst

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

0 commit comments

Comments
 (0)