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

Add custom endpoint support to aws s3 tile #386

Open
wants to merge 1 commit into
base: master
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
6 changes: 6 additions & 0 deletions aws-s3/1.0.0/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ authentication:
required: true
schema:
type: string
- name: endpoint_url
description: The endpoint to use. 'default' or blank for default endpoint
example: "http://localhost:9000"
required: false
schema:
type: string
actions:
- name: create_bucket
description: Creates a bucket with the specified name
Expand Down
59 changes: 32 additions & 27 deletions aws-s3/1.0.0/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, redis, logger, console_logger=None):
"""
super().__init__(redis, logger, console_logger)

def auth_s3(self, access_key, secret_key, region):
def auth_s3(self, access_key, secret_key, region, endpoint_url=None):
my_config = Config(
region_name = region,
signature_version = "s3v4",
Expand All @@ -32,26 +32,31 @@ def auth_s3(self, access_key, secret_key, region):
},
)

self.s3 = boto3.resource(
's3',
config=my_config,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
)
resource_args = {
"service_name": 's3',
"config": my_config,
"aws_access_key_id": access_key,
"aws_secret_access_key": secret_key
}

if endpoint_url and endpoint_url != 'default':
resource_args['endpoint_url'] = endpoint_url

self.s3 = boto3.resource(**resource_args)

return self.s3

def list_buckets(self, access_key, secret_key, region):
self.s3 = self.auth_s3(access_key, secret_key, region)
def list_buckets(self, access_key, secret_key, region, endpoint_url):
self.s3 = self.auth_s3(access_key, secret_key, region, endpoint_url)
client = self.s3.meta.client
try:
newlist = client.list_buckets()
return newlist
except botocore.exceptions.ClientError as e:
return "Error: %s" % e

def create_bucket(self, access_key, secret_key, region, bucket_name, access_type):
self.s3 = self.auth_s3(access_key, secret_key, region)
def create_bucket(self, access_key, secret_key, region, bucket_name, access_type, endpoint_url):
self.s3 = self.auth_s3(access_key, secret_key, region, endpoint_url)
client = self.s3.meta.client
try:
creation = client.create_bucket(
Expand All @@ -66,8 +71,8 @@ def create_bucket(self, access_key, secret_key, region, bucket_name, access_type
except botocore.exceptions.ClientError as e:
return "Error: %s" % e

def block_ip_access(self, access_key, secret_key, region, bucket_name, ip):
self.s3 = self.auth_s3(access_key, secret_key, region)
def block_ip_access(self, access_key, secret_key, region, bucket_name, ip, endpoint_url):
self.s3 = self.auth_s3(access_key, secret_key, region, endpoint_url)
client = self.s3.meta.client

ip_policy = {
Expand Down Expand Up @@ -123,44 +128,44 @@ def block_ip_access(self, access_key, secret_key, region, bucket_name, ip):
print(putaction)
return "Successfully blocked IP %s" % ip

def bucket_request_payment(self, access_key, secret_key, region, bucket_name):
self.s3 = self.auth_s3(access_key, secret_key, region)
def bucket_request_payment(self, access_key, secret_key, region, bucket_name, endpoint_url):
self.s3 = self.auth_s3(access_key, secret_key, region, endpoint_url)
client = self.s3.meta.client

try:
return client.get_bucket_request_payment(Bucket=bucket_name)
except botocore.exceptions.ClientError as e:
return "Error: %s" % e

def bucket_replication(self, access_key, secret_key, region, bucket_name):
self.s3 = self.auth_s3(access_key, secret_key, region)
def bucket_replication(self, access_key, secret_key, region, bucket_name, endpoint_url):
self.s3 = self.auth_s3(access_key, secret_key, region, endpoint_url)
client = self.s3.meta.client

try:
return client.get_bucket_replication(Bucket=bucket_name)
except botocore.exceptions.ClientError as e:
return "Error: %s" % e

def bucket_policy_status(self, access_key, secret_key, region, bucket_name):
self.s3 = self.auth_s3(access_key, secret_key, region)
def bucket_policy_status(self, access_key, secret_key, region, bucket_name, endpoint_url):
self.s3 = self.auth_s3(access_key, secret_key, region, endpoint_url)
client = self.s3.meta.client

try:
return client.get_bucket_policy_status(Bucket=bucket_name)
except botocore.exceptions.ClientError as e:
return "Error: %s" % e

def bucket_logging(self, access_key, secret_key, region, bucket_name):
self.s3 = self.auth_s3(access_key, secret_key, region)
def bucket_logging(self, access_key, secret_key, region, bucket_name, endpoint_url):
self.s3 = self.auth_s3(access_key, secret_key, region, endpoint_url)
client = self.s3.meta.client

try:
return client.get_bucket_logging(Bucket=bucket_name)
except botocore.exceptions.ClientError as e:
return "Error: %s" % e

def upload_file_to_bucket(self, access_key, secret_key, region, bucket_name, bucket_path, file_id):
self.s3 = self.auth_s3(access_key, secret_key, region)
def upload_file_to_bucket(self, access_key, secret_key, region, bucket_name, bucket_path, file_id, endpoint_url):
self.s3 = self.auth_s3(access_key, secret_key, region, endpoint_url)
client = self.s3.meta.client

found_file = self.get_file(file_id)
Expand All @@ -171,15 +176,15 @@ def upload_file_to_bucket(self, access_key, secret_key, region, bucket_name, buc
#s3_response = client.upload_file('LOCAL PATH', bucket_name, bucket_path)
return s3_response

def delete_file_from_bucket(self, access_key, secret_key, region, bucket_name, bucket_path):
self.s3 = self.auth_s3(access_key, secret_key, region)
def delete_file_from_bucket(self, access_key, secret_key, region, bucket_name, bucket_path, endpoint_url):
self.s3 = self.auth_s3(access_key, secret_key, region, endpoint_url)
client = self.s3.meta.client

s3_response = client.delete_object(Bucket=bucket_name, Key=bucket_path)
return s3_response

def download_file_from_bucket(self, access_key, secret_key, region, bucket_name, filename):
self.s3 = self.auth_s3(access_key, secret_key, region)
def download_file_from_bucket(self, access_key, secret_key, region, bucket_name, filename, endpoint_url):
self.s3 = self.auth_s3(access_key, secret_key, region, endpoint_url)
client = self.s3.meta.client

s3_response_object = client.get_object(Bucket=bucket_name, Key=filename)
Expand Down