mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 02:08:36 +00:00
Add AWS_REGION to connect to bucket with specific region
This commit is contained in:
@@ -70,11 +70,11 @@ The exact naming is important, because the `cloud_platform` addon rely on these
|
|||||||
|
|
||||||
* prod: stored RW in the object storage
|
* prod: stored RW in the object storage
|
||||||
* `AWS_HOST`: depends of the platform
|
* `AWS_HOST`: depends of the platform
|
||||||
|
* `AWS_REGION`: region's endpoint
|
||||||
* `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`
|
* `AWS_BUCKETNAME`: `<client>-odoo-prod`
|
||||||
* integration:
|
* integration:
|
||||||
* `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-integration`
|
* `AWS_BUCKETNAME`: `<client>-odoo-integration`
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ Activate S3 storage:
|
|||||||
Configure accesses with environment variables:
|
Configure accesses with environment variables:
|
||||||
|
|
||||||
* ``AWS_HOST`` (not required if using AWS services)
|
* ``AWS_HOST`` (not required if using AWS services)
|
||||||
|
* ``AWS_REGION`` (required if using AWS services)
|
||||||
* ``AWS_ACCESS_KEY_ID``
|
* ``AWS_ACCESS_KEY_ID``
|
||||||
* ``AWS_SECRET_ACCESS_KEY``
|
* ``AWS_SECRET_ACCESS_KEY``
|
||||||
* ``AWS_BUCKETNAME``
|
* ``AWS_BUCKETNAME``
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import base64
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
from functools import partial
|
|
||||||
|
|
||||||
from odoo import _, api, exceptions, models
|
from odoo import _, api, exceptions, models
|
||||||
from ..s3uri import S3Uri
|
from ..s3uri import S3Uri
|
||||||
@@ -37,6 +36,7 @@ class IrAttachment(models.Model):
|
|||||||
|
|
||||||
The following environment variables can be set:
|
The following environment variables can be set:
|
||||||
* ``AWS_HOST``
|
* ``AWS_HOST``
|
||||||
|
* ``AWS_REGION``
|
||||||
* ``AWS_ACCESS_KEY_ID``
|
* ``AWS_ACCESS_KEY_ID``
|
||||||
* ``AWS_SECRET_ACCESS_KEY``
|
* ``AWS_SECRET_ACCESS_KEY``
|
||||||
* ``AWS_BUCKETNAME``
|
* ``AWS_BUCKETNAME``
|
||||||
@@ -46,17 +46,23 @@ class IrAttachment(models.Model):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
host = os.environ.get('AWS_HOST')
|
host = os.environ.get('AWS_HOST')
|
||||||
if host:
|
region_name = os.environ.get('AWS_REGION')
|
||||||
connect_s3 = partial(boto.connect_s3, host=host)
|
|
||||||
else:
|
|
||||||
connect_s3 = boto.connect_s3
|
|
||||||
|
|
||||||
access_key = os.environ.get('AWS_ACCESS_KEY_ID')
|
access_key = os.environ.get('AWS_ACCESS_KEY_ID')
|
||||||
secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY')
|
secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY')
|
||||||
if name:
|
bucket_name = name or os.environ.get('AWS_BUCKETNAME')
|
||||||
bucket_name = name
|
|
||||||
|
params = {
|
||||||
|
'aws_access_key_id': access_key,
|
||||||
|
'aws_secret_access_key': secret_key,
|
||||||
|
}
|
||||||
|
if host:
|
||||||
|
params['host'] = host
|
||||||
|
if region_name:
|
||||||
|
# needs specific method for region
|
||||||
|
connect_s3 = boto.s3.connect_to_region
|
||||||
|
params['region_name'] = region_name
|
||||||
else:
|
else:
|
||||||
bucket_name = os.environ.get('AWS_BUCKETNAME')
|
connect_s3 = boto.connect_s3
|
||||||
if not (access_key and secret_key and bucket_name):
|
if not (access_key and secret_key and bucket_name):
|
||||||
msg = _('If you want to read from the %s S3 bucket, the following '
|
msg = _('If you want to read from the %s S3 bucket, the following '
|
||||||
'environment variables must be set:\n'
|
'environment variables must be set:\n'
|
||||||
@@ -72,8 +78,7 @@ class IrAttachment(models.Model):
|
|||||||
raise exceptions.UserError(msg)
|
raise exceptions.UserError(msg)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
conn = connect_s3(aws_access_key_id=access_key,
|
conn = connect_s3(**params)
|
||||||
aws_secret_access_key=secret_key)
|
|
||||||
|
|
||||||
except S3ResponseError as error:
|
except S3ResponseError as error:
|
||||||
# log verbose error from s3, return short message for user
|
# log verbose error from s3, return short message for user
|
||||||
|
|||||||
Reference in New Issue
Block a user