mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-23 18:04:34 +00:00
Adapt cloud_platform setup for 73aaff6
Following the changes in attachment_s3
This commit is contained in:
@@ -50,8 +50,7 @@ The exact naming is important, because the `cloud_platform` addon rely on these
|
|||||||
* `AWS_HOST`: depends of the platform
|
* `AWS_HOST`: depends of the platform
|
||||||
* `AWS_ACCESS_KEY_ID`: depends of the platform
|
* `AWS_ACCESS_KEY_ID`: depends of the platform
|
||||||
* `AWS_SECRET_ACCESS_KEY`: depends of the platform
|
* `AWS_SECRET_ACCESS_KEY`: depends of the platform
|
||||||
* `AWS_BUCKETNAME`: `<client>-odoo-prod` (this is normal, we read only the data)
|
* `AWS_BUCKETNAME`: `<client>-odoo-integration`
|
||||||
* `AWS_ATTACHMENT_READONLY`: `1`
|
|
||||||
* test: attachments are stored in database
|
* test: attachments are stored in database
|
||||||
|
|
||||||
Besides, the
|
Besides, the
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ def is_true(strval):
|
|||||||
|
|
||||||
PlatformConfig = namedtuple(
|
PlatformConfig = namedtuple(
|
||||||
'PlatformConfig',
|
'PlatformConfig',
|
||||||
'filestore filestore_readonly'
|
'filestore'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class FilestoreKind(object):
|
class FilestoreKind(object):
|
||||||
db = 'db'
|
db = 'db'
|
||||||
s3 = 's3://' # or compatible s3 object storage
|
s3 = 's3' # or compatible s3 object storage
|
||||||
file = 'file'
|
file = 'file'
|
||||||
|
|
||||||
|
|
||||||
@@ -40,14 +40,10 @@ class CloudPlatform(models.AbstractModel):
|
|||||||
@api.model
|
@api.model
|
||||||
def _config_by_server_env(self, environment):
|
def _config_by_server_env(self, environment):
|
||||||
configs = {
|
configs = {
|
||||||
'prod': PlatformConfig(filestore=FilestoreKind.s3,
|
'prod': PlatformConfig(filestore=FilestoreKind.s3),
|
||||||
filestore_readonly=False),
|
'integration': PlatformConfig(filestore=FilestoreKind.s3),
|
||||||
'integration': PlatformConfig(filestore=FilestoreKind.s3,
|
'test': PlatformConfig(filestore=FilestoreKind.db),
|
||||||
filestore_readonly=True),
|
'dev': PlatformConfig(filestore=FilestoreKind.db),
|
||||||
'test': PlatformConfig(filestore=FilestoreKind.db,
|
|
||||||
filestore_readonly=True),
|
|
||||||
'dev': PlatformConfig(filestore=FilestoreKind.db,
|
|
||||||
filestore_readonly=True),
|
|
||||||
}
|
}
|
||||||
return configs.get(environment) or configs['dev']
|
return configs.get(environment) or configs['dev']
|
||||||
|
|
||||||
@@ -66,10 +62,7 @@ class CloudPlatform(models.AbstractModel):
|
|||||||
@api.model
|
@api.model
|
||||||
def _check_s3(self, environment_name):
|
def _check_s3(self, environment_name):
|
||||||
params = self.env['ir.config_parameter'].sudo()
|
params = self.env['ir.config_parameter'].sudo()
|
||||||
attachment_readonly = is_true(
|
use_s3 = params.get_param('ir_attachment.location') == FilestoreKind.s3
|
||||||
os.environ.get('AWS_ATTACHMENT_READONLY')
|
|
||||||
)
|
|
||||||
use_s3 = params.get_param('ir_attachment.location') == 's3://'
|
|
||||||
if environment_name in ('prod', 'integration'):
|
if environment_name in ('prod', 'integration'):
|
||||||
assert use_s3
|
assert use_s3
|
||||||
if use_s3:
|
if use_s3:
|
||||||
@@ -83,11 +76,14 @@ class CloudPlatform(models.AbstractModel):
|
|||||||
"AWS_BUCKETNAME should match '<client>-odoo-prod', "
|
"AWS_BUCKETNAME should match '<client>-odoo-prod', "
|
||||||
"we got: '%s'" % (bucket_name,)
|
"we got: '%s'" % (bucket_name,)
|
||||||
)
|
)
|
||||||
assert not attachment_readonly
|
|
||||||
else:
|
else:
|
||||||
# if we are using the prod bucket on another instance
|
# if we are using the prod bucket on another instance
|
||||||
# such as an integration, we must be sure to be in read only!
|
# such as an integration, we must be sure to be in read only!
|
||||||
assert not prod_bucket or attachment_readonly
|
assert not prod_bucket, (
|
||||||
|
"AWS_BUCKETNAME should not match '<client>-odoo-prod', "
|
||||||
|
"we got: '%s'" % (bucket_name,)
|
||||||
|
)
|
||||||
|
|
||||||
elif environment_name == 'test':
|
elif environment_name == 'test':
|
||||||
# store in DB so we don't have files local to the host
|
# store in DB so we don't have files local to the host
|
||||||
assert params.get_param('ir_attachment.location') == 'db'
|
assert params.get_param('ir_attachment.location') == 'db'
|
||||||
@@ -125,5 +121,6 @@ class CloudPlatform(models.AbstractModel):
|
|||||||
|
|
||||||
@api.cr
|
@api.cr
|
||||||
def _register_hook(self, cr):
|
def _register_hook(self, cr):
|
||||||
|
super(CloudPlatform, self)._register_hook(cr)
|
||||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||||
env['cloud.platform'].check()
|
env['cloud.platform'].check()
|
||||||
|
|||||||
Reference in New Issue
Block a user