Skip to content

Commit

Permalink
[CI] add pyvows test and circleci config
Browse files Browse the repository at this point in the history
  • Loading branch information
dhardy92 committed Mar 25, 2015
1 parent 46aa1ab commit ac33466
Show file tree
Hide file tree
Showing 12 changed files with 326 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
*.pyc
7 changes: 7 additions & 0 deletions circle.yml
@@ -0,0 +1,7 @@
dependencies:
override:
- pip install pyvows coverage tornado_pyvows thumbor boto py-dateutil moto

test:
override:
- pyvows -c -l thumbor_aws
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -11,5 +11,5 @@
zip_safe = False,
include_package_data = True,
packages=find_packages(),
requires=['dateutil','thumbor','boto']
)
requires=['py-dateutil','thumbor','boto']
)
15 changes: 14 additions & 1 deletion thumbor_aws/__init__.py
@@ -1 +1,14 @@
# coding: utf-8
# coding: utf-8
from thumbor.config import Config
Config.define('STORAGE_BUCKET', 'thumbor-images','S3 bucket for Storage', 'S3')
Config.define('RESULT_STORAGE_BUCKET', 'thumbor-result', 'S3 bucket for result Storage', 'S3')
Config.define('S3_LOADER_BUCKET','thumbor-images','S3 bucket for loader', 'S3')
Config.define('RESULT_STORAGE_AWS_STORAGE_ROOT_PATH','', 'S3 path prefix', 'S3')
Config.define('STORAGE_EXPIRATION_SECONDS', 3600, 'S3 expiration', 'S3')
Config.define('S3_STORAGE_SSE', False, 'S3 encriptipon key', 'S3')
Config.define('S3_STORAGE_RRS', False, 'S3 redundency', 'S3')
Config.define('S3_ALLOWED_BUCKETS', False, 'List of allowed bucket to be requeted', 'S3')

Config.define('AWS_ACCESS_KEY', None, 'AWS Access key, if None use environment AWS_ACCESS_KEY_ID', 'AWS')
Config.define('AWS_SECRET_KEY', None, 'AWS Secret key, if None use environment AWS_SECRET_ACCESS_KEY', 'AWS')
Config.define('AWS_ROLE_BASED_CONNECTION', False, 'EC2 instance can use role that does not require AWS_ACCESS_KEY see http://docs.aws.amazon.com/IAM/latest/UserGuide/roles-usingrole-ec2instance.html', 'AWS')
6 changes: 3 additions & 3 deletions thumbor_aws/connection.py
Expand Up @@ -7,12 +7,12 @@
def get_connection(context):
conn = connection
if conn is None:
if context.config.get('AWS_ROLE_BASED_CONNECTION', default=False):
if context.config.AWS_ROLE_BASED_CONNECTION:
conn = S3Connection()
else:
conn = S3Connection(
context.config.get('AWS_ACCESS_KEY'),
context.config.get('AWS_SECRET_KEY')
context.config.AWS_ACCESS_KEY,
context.config.AWS_SECRET_KEY
)

return conn
9 changes: 4 additions & 5 deletions thumbor_aws/result_storages/s3_storage.py
Expand Up @@ -36,8 +36,8 @@ def put(self, bytes):
file_key.key = file_abspath

file_key.set_contents_from_string(bytes,
encrypt_key = self.context.config.get('S3_STORAGE_SSE', default=False),
reduced_redundancy = self.context.config.get('S3_STORAGE_RRS', default=False)
encrypt_key = self.context.config.S3_STORAGE_SSE,
reduced_redundancy = self.context.config.S3_STORAGE_RRS
)

def get(self):
Expand All @@ -51,12 +51,11 @@ def get(self):
return file_key.read()

def normalize_path(self, path):
root_path = self.context.config.get('RESULT_STORAGE_AWS_STORAGE_ROOT_PATH', default='thumbor/result_storage/')
root_path = self.context.config.RESULT_STORAGE_AWS_STORAGE_ROOT_PATH
path_segments = [path]
if self.is_auto_webp:
path_segments.append("webp")
digest = hashlib.sha1(".".join(path_segments).encode('utf-8')).hexdigest()
return os.path.join(root_path, digest)
return os.path.join(root_path, *path_segments)

def is_expired(self, key):
if key:
Expand Down
25 changes: 15 additions & 10 deletions thumbor_aws/storages/s3_storage.py
Expand Up @@ -5,7 +5,7 @@
import hashlib
from json import loads, dumps

from os.path import splitext
from os.path import splitext, join

from thumbor.storages import BaseStorage
from thumbor.utils import logger
Expand Down Expand Up @@ -36,8 +36,8 @@ def put(self, path, bytes):
file_key.key = file_abspath

file_key.set_contents_from_string(bytes,
encrypt_key = self.context.config.get('S3_STORAGE_SSE', default=False),
reduced_redundancy = self.context.config.get('S3_STORAGE_RRS', default=False)
encrypt_key = self.context.config.S3_STORAGE_SSE,
reduced_redundancy = self.context.config.S3_STORAGE_RRS
)

return path
Expand All @@ -57,8 +57,8 @@ def put_crypto(self, path):
file_key.key = crypto_path

file_key.set_contents_from_string(self.context.server.security_key,
encrypt_key = self.context.config.get('S3_STORAGE_SSE', default=False),
reduced_redundancy = self.context.config.get('S3_STORAGE_RRS', default=False)
encrypt_key = self.context.config.S3_STORAGE_SSE,
reduced_redundancy = self.context.config.S3_STORAGE_RRS
)

return crypto_path
Expand All @@ -72,8 +72,8 @@ def put_detector_data(self, path, data):
file_key.key = path

file_key.set_contents_from_string(dumps(data),
encrypt_key = self.context.config.get('S3_STORAGE_SSE', default=False),
reduced_redundancy = self.context.config.get('S3_STORAGE_RRS', default=False)
encrypt_key = self.context.config.S3_STORAGE_SSE,
reduced_redundancy = self.context.config.S3_STORAGE_RRS
)

return path
Expand Down Expand Up @@ -119,12 +119,14 @@ def exists(self, path):
return True

def normalize_path(self, path):
digest = hashlib.sha1(path.encode('utf-8')).hexdigest()
return "thumbor/storage/"+digest
root_path = self.context.config.RESULT_STORAGE_AWS_STORAGE_ROOT_PATH
path_segments = [path]
return join(root_path, *path_segments)


def is_expired(self, key):
if key:
expire_in_seconds = self.context.config.get('RESULT_STORAGE_EXPIRATION_SECONDS', None)
expire_in_seconds = self.context.config.RESULT_STORAGE_EXPIRATION_SECONDS

#Never expire
if expire_in_seconds is None or expire_in_seconds == 0:
Expand All @@ -151,3 +153,6 @@ def utc_to_local(self, utc_dt):
local_dt = datetime.fromtimestamp(timestamp)
assert utc_dt.resolution >= timedelta(microseconds=1)
return local_dt.replace(microsecond=utc_dt.microsecond)

def resolve_original_photo_path(self,filename):
return filename
Empty file added vows/__init__.py
Empty file.
Empty file added vows/fixtures/__init__.py
Empty file.
Binary file added vows/fixtures/image.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions vows/fixtures/storage_fixture.py
@@ -0,0 +1,39 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# thumbor imaging service
# https://github.com/globocom/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com

from os.path import join, abspath, dirname

from thumbor.context import ServerParameters, Context
from thumbor.config import Config
from thumbor.importer import Importer

IMAGE_URL = 's.glbimg.com/some/image_%s.jpg'
IMAGE_PATH = join(abspath(dirname(__file__)), 'image.jpg')

with open(IMAGE_PATH, 'r') as img:
IMAGE_BYTES = img.read()

def get_server(key=None):
server_params = ServerParameters(8888, 'localhost', 'thumbor.conf', None, 'info', None)
server_params.security_key = key
return server_params

def get_context(server=None, config=None, importer=None):
if not server:
server = get_server()

if not config:
config = Config()

if not importer:
importer = Importer(config)

ctx = Context(server=server, config=config, importer=importer)
return ctx

0 comments on commit ac33466

Please sign in to comment.