Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allows to configure generic object storage other than amazon s3 (eg: wasabi.com) #1119

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion ir_attachment_s3/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Copyright 2019 Alexandr Kolushov <https://it-projects.info/team/KolushovAlexandr>
# Copyright 2019-2020 Eugene Molotov <https://it-projects.info/team/em230418>
import os
from urllib.parse import urlparse

import boto3

Expand All @@ -19,6 +20,7 @@ class S3Settings(models.TransientModel):
s3_access_key_id = fields.Char(string="S3 access key id")
s3_secret_key = fields.Char(string="S3 secret key")
s3_endpoint_url = fields.Char(string="S3 Endpoint")
s3_region = fields.Char(string="S3 Region")
s3_obj_url = fields.Char(string="S3 URL")
s3_condition = fields.Char(
string="S3 condition",
Expand All @@ -38,13 +40,18 @@ def get_s3_obj_url(self, bucket, file_id):
base_url = self._get_s3_settings("s3.obj_url", "S3_OBJ_URL")
if base_url:
return base_url + file_id
return "https://{}.s3.amazonaws.com/{}".format(bucket.name, file_id)

endpoint_url = self._get_s3_settings("s3.endpoint_url", "S3_ENDPOINT_URL")
bucket_name = self._get_s3_settings("s3.bucket", "S3_BUCKET")
url = urlparse(endpoint_url)
return "{}://{}.{}/{}".format(url.scheme, bucket_name, url.netloc, file_id)

def get_s3_bucket(self):
access_key_id = self._get_s3_settings("s3.access_key_id", "S3_ACCESS_KEY_ID")
secret_key = self._get_s3_settings("s3.secret_key", "S3_SECRET_KEY")
bucket_name = self._get_s3_settings("s3.bucket", "S3_BUCKET")
endpoint_url = self._get_s3_settings("s3.endpoint_url", "S3_ENDPOINT_URL")
region = self._get_s3_settings("s3.region", "S3_REGION")

if not access_key_id or not secret_key or not bucket_name:
raise NotAllCredentialsGiven(
Expand All @@ -56,6 +63,7 @@ def get_s3_bucket(self):
aws_access_key_id=access_key_id,
aws_secret_access_key=secret_key,
endpoint_url=endpoint_url,
region_name=region
)
bucket = s3.Bucket(bucket_name)
if not bucket:
Expand All @@ -71,6 +79,7 @@ def get_values(self):
s3_access_key_id = ICPSudo.get_param("s3.access_key_id", default="")
s3_secret_key = ICPSudo.get_param("s3.secret_key", default="")
s3_endpoint_url = ICPSudo.get_param("s3.endpoint_url", default="")
s3_region = ICPSudo.get_param("s3.region", default="")
s3_obj_url = ICPSudo.get_param("s3.obj_url", default="")
s3_condition = ICPSudo.get_param("s3.condition", default="")

Expand All @@ -80,6 +89,7 @@ def get_values(self):
s3_secret_key=s3_secret_key,
s3_condition=s3_condition,
s3_endpoint_url=s3_endpoint_url,
s3_region=s3_region,
s3_obj_url=s3_obj_url,
)
return res
Expand All @@ -91,6 +101,7 @@ def set_values(self):
ICPSudo.set_param("s3.access_key_id", self.s3_access_key_id or "")
ICPSudo.set_param("s3.secret_key", self.s3_secret_key or "")
ICPSudo.set_param("s3.endpoint_url", self.s3_endpoint_url or "")
ICPSudo.set_param("s3.region", self.s3_region or "")
ICPSudo.set_param("s3.obj_url", self.s3_obj_url or "")
ICPSudo.set_param("s3.condition", self.s3_condition or "")

Expand Down
13 changes: 13 additions & 0 deletions ir_attachment_s3/views/res_config_settings_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@
/>
</div>
</div>
<div class="content-group">
<div class="mt16 row">
<label
for="s3_region"
string="S3 Region"
class="col-xs-3 col-md-3 o_light_label"
/>
<field
name="s3_region"
class="oe_inline"
/>
</div>
</div>
<div class="content-group">
<div class="mt16 row">
<label
Expand Down