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
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ To upload all local resources located in `ckan.storage_path` location dir to the

ckan -c /etc/ckan/default/ckan.ini s3-upload

To test AWS S3 connection by adding and deleting a single text file

ckan -c /etc/ckan/default/ckan.ini s3-test-connection

------------------------
Development Installation
Expand Down
33 changes: 32 additions & 1 deletion ckanext/s3filestore/click_commands.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

from io import StringIO
import os
import click

Expand Down Expand Up @@ -81,3 +81,34 @@ def upload_resources():
len(uploaded_resources)),
fg=u'green',
bold=True)


@click.command(u's3-test-connection', short_help=u'Test connection to AWS S3')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps there should be an s3 command group?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, @ThrawnCA. Probably a s3filestore group

def upload_resources():
bucket_name = config.get('ckanext.s3filestore.aws_bucket_name')
acl = config.get('ckanext.s3filestore.acl', 'public-read')

click.secho('Testing AWS S3 connection', fg=u'green', bold=True)

uploader = BaseS3Uploader()
s3_connection = uploader.get_s3_resource()
buf = StringIO('Testing S3 connection')

try:
s3_object = s3_connection.Object(bucket_name, 'testNN.text')

s3_object.put(
Body=buf.getvalue(),
ACL=acl,
ContentType='text/plain'
)
except Exception as e:
error = 'Failed to create S3 Object: {}'.format(e)
click.secho(error, fg=u'red', bold=True)
raise click.Abort()

click.secho('S3 Object created', fg=u'green', bold=True)
s3_object.delete()
click.secho('S3 Object deleted', fg=u'green', bold=True)

click.secho('Done', fg=u'green', bold=True)