Skip to content

Commit

Permalink
generate public url without signature (#100)
Browse files Browse the repository at this point in the history
* generate public url without signature

* imports

* update rules
  • Loading branch information
ncgl-syngenta authored Feb 3, 2022
1 parent 62dc945 commit a5cc93c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ persistent=no
unsafe-load-any-extension=no

[MESSAGES CONTROL]
disable=import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,missing-docstring,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating,relative-import,invalid-name,bad-continuation,no-member,locally-disabled,fixme,import-error,too-many-locals,no-name-in-module,too-many-instance-attributes,no-self-use,logging-fstring-interpolation,W0703,W0702,R0904
disable=W0212,C0116,missing-function-docstring,import-star-module-level,old-octal-literal,oct-method,print-statement,unpacking-in-except,parameter-unpacking,backtick,old-raise-syntax,old-ne-operator,long-suffix,dict-view-method,dict-iter-method,metaclass-assignment,next-method-called,raising-string,indexing-exception,raw_input-builtin,long-builtin,file-builtin,execfile-builtin,coerce-builtin,cmp-builtin,buffer-builtin,basestring-builtin,apply-builtin,filter-builtin-not-iterating,using-cmp-argument,useless-suppression,range-builtin-not-iterating,suppressed-message,missing-docstring,no-absolute-import,old-division,cmp-method,reload-builtin,zip-builtin-not-iterating,intern-builtin,unichr-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,input-builtin,round-builtin,hex-method,nonzero-method,map-builtin-not-iterating,relative-import,invalid-name,bad-continuation,no-member,locally-disabled,fixme,import-error,too-many-locals,no-name-in-module,too-many-instance-attributes,no-self-use,logging-fstring-interpolation,W0703,W0702,R0904
enable=W0603,global-statement

[REPORTS]
Expand Down
22 changes: 19 additions & 3 deletions syngenta_digital_dta/s3/adapter.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from io import BytesIO
import os
from io import BytesIO

import boto3
import botocore
import jsonpickle
from botocore.exceptions import ClientError

from syngenta_digital_dta.common.base_adapter import BaseAdapter


Expand All @@ -18,14 +20,20 @@ def __init__(self, **kwargs):
self.aws_access_key_id = kwargs.get('aws_access_key_id')
self.aws_secret_access_key = kwargs.get('aws_secret_access_key')
self.region = kwargs.get('region')
self.client = boto3.client(
self.client = self.__make_client()
self.resource = self.__make_resource()

def __make_client(self):
return boto3.client(
's3',
endpoint_url=self.endpoint,
aws_access_key_id=self.aws_access_key_id,
aws_secret_access_key=self.aws_secret_access_key,
region_name=self.region
)
self.resource = boto3.resource(

def __make_resource(self):
return boto3.resource(
's3',
endpoint_url=self.endpoint,
aws_access_key_id=self.aws_access_key_id,
Expand Down Expand Up @@ -102,6 +110,14 @@ def multipart_upload(self, **kwargs):
super().publish('create', self.__generate_publish_data(**kwargs))
return complete_response

def create_public_url(self, **kwargs):
# we create a new client here to not modify other method calls
client = self.__make_client()
client._client_config.signature_version = botocore.UNSIGNED
return client.generate_presigned_url(
'get_object', ExpiresIn=0, Params={'Bucket': self.bucket, 'Key': kwargs['s3_path']}
)

def create_presigned_read_url(self, **kwargs):
results = self.client.generate_presigned_url(
'get_object',
Expand Down

0 comments on commit a5cc93c

Please sign in to comment.