Skip to content
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
24 changes: 16 additions & 8 deletions remotecv_aws/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,42 @@
# Use of this source code is governed by the MIT license that can be
# found in the LICENSE file.

import botocore.session
from boto3.session import Session

class Bucket(object):
"""
This handles all communication with AWS API
"""
_bucket = None
_region = None
_local_cache = dict()

def __init__(self, bucket, region):
def __init__(self, bucket, region, accessKeyId, secretAccessKey):
"""
Constructor
:param string bucket: The bucket name
:param string region: The AWS API region to use
:return: The created bucket
:param string accessKeyId: The AWS access key ID for accessing the bucket
:param string secretAccessKey: The AWS secret access key for accessing the bucket
:return: The created AWS client for the bucket
"""
self._bucket = bucket
self._region = region
session = None or botocore.session.get_session()
self._client = session.create_client('s3', region_name=self._region, endpoint_url=None)

session = Session(
aws_access_key_id=accessKeyId,
aws_secret_access_key=secretAccessKey,
region_name=region
)

self._client = session.resource('s3')

def get(self, path):
"""
Returns object at given path
:param string path: Path or 'key' to retrieve AWS object
"""
file_path = self._client.get_object( Bucket=self._bucket, Key=path)

file_path = self._client.Bucket(self._bucket).Object(path).get()

return file_path['Body'].read()


4 changes: 3 additions & 1 deletion remotecv_aws/loader.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def load_sync(path):
"""
bucket = os.environ.get('AWS_LOADER_BUCKET')
region = os.environ.get('AWS_REGION', 'eu-west-1')
bucket_loader = Bucket(bucket, region)
accessKeyId = os.environ.get('AWS_ACCESS_KEY_ID')
secretAccessKey = os.environ.get('AWS_SECRET_KEY_ID')
bucket_loader = Bucket(bucket, region, accessKeyId, secretAccessKey)

return bucket_loader.get(path)
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

setup(
name='remotecv_aws',
version='0.1',
version='0.2',
description='Remotecv AWS loader',
author='Edu Heraiz @ APSL',
author_email='gshark@gmail.com',
zip_safe=False,
include_package_data=True,
packages=find_packages(),
install_requires=[
'botocore>=1.2.0',
'boto3',
],
extras_require={
},
Expand Down