fix: add env variable

This commit is contained in:
vrenaville
2022-03-21 08:39:37 +01:00
parent 2139c2acbf
commit 7686d7a99c
2 changed files with 11 additions and 1 deletions
+10 -1
View File
@@ -54,6 +54,7 @@ class IrAttachment(models.Model):
region_name = os.environ.get('AWS_REGION')
access_key = os.environ.get('AWS_ACCESS_KEY_ID')
secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY')
aws_use_instance_profile = os.environ.get('AWS_USE_INSTANCE_PROFILE')
bucket_name = bucket_name or os.environ.get('AWS_BUCKETNAME')
# replaces {db} by the database name to handle multi-tenancy
bucket_name = bucket_name.format(db=self.env.cr.dbname)
@@ -64,6 +65,8 @@ class IrAttachment(models.Model):
params['aws_access_key_id'] = access_key
if secret_key:
params['aws_secret_access_key'] = secret_key
if aws_use_instance_profile:
params['aws_use_instance_profile'] = aws_use_instance_profile
if host:
params['endpoint_url'] = host
if region_name:
@@ -81,6 +84,7 @@ class IrAttachment(models.Model):
* ``AWS_ACCESS_KEY_ID``
* ``AWS_SECRET_ACCESS_KEY``
* ``AWS_BUCKETNAME``
* ``AWS_USE_INSTANCE_PROFILE``
If a name is provided, we'll read this bucket, otherwise, the bucket
from the environment variable ``AWS_BUCKETNAME`` will be read.
@@ -91,12 +95,17 @@ class IrAttachment(models.Model):
# keyword argument 'bucket_name'
bucket_name = params.pop("bucket_name")
if not (
bucket_name
bucket_name and
(params["aws_access_key_id"] and
params["aws_secret_access_key"] or
params["aws_use_instance_profile"])
):
msg = _('If you want to read from the %s S3 bucket, the following '
'environment variables must be set:\n'
'* AWS_ACCESS_KEY_ID\n'
'* AWS_SECRET_ACCESS_KEY\n'
'or set instance profile\n'
'* AWS_USE_INSTANCE_PROFILE\n'
'If you want to write in the %s S3 bucket, this variable '
'must be set as well:\n'
'* AWS_BUCKETNAME\n'
+1
View File
@@ -10,3 +10,4 @@ keystoneauth1==3.14.0
# error with 5.x (ConstructorError: could not determine a constructor for the tag '!record')
PyYAML==4.2b4
prometheus_client==0.11.0
portalocker==1.7.1