Skip to content

Commit

Permalink
Merge pull request #3 from penkin/develop
Browse files Browse the repository at this point in the history
Added an option to the connection settings to set which region you're wo...
  • Loading branch information
edgarroman committed Mar 27, 2013
2 parents 96d1816 + dae1017 commit 146348a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Installation
#'MAX_SPINLOCK_TIME': 60*60, # number of seconds before processing spinlocks give up
#'PREPARE_SILENTLY': False, # If False, raise ValidationError if preparation of uploads fails.
# If True, continue with upload
#'REGION': 'us-east-1', # The region you want to create the search domain in. Defaults to 'us-east-1'
}
}

Expand Down
21 changes: 20 additions & 1 deletion haystack_cloudsearch/cloudsearch_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ def __init__(self, connection_alias, **connection_options):
if not 'AWS_SECRET_KEY' in connection_options:
raise ImproperlyConfigured("You must specify a 'AWS_SECRET_KEY' in your settings for connection '%s'." % connection_alias)

# We want to check if there is a 'REGION' passed into the connection. If there is we validate it with the
# available regions.
region_name = connection_options.get('REGION', None)
region_list = [cloudsearch_region.name for cloudsearch_region in boto.cloudsearch.regions()]
region_conn = None

if region_name and region_name not in region_list:
raise ImproperlyConfigured("The 'REGION' in your connection settings is not valid. Available regions are %s" % region_list)
elif region_name:
for region in boto.cloudsearch.regions():
if region.name == region_name:
region_conn = region
break

# Allow overrides for the SearchDomain prefix
self.search_domain_prefix = connection_options.get('SEARCH_DOMAIN_PREFIX', 'haystack')

Expand All @@ -55,7 +69,12 @@ def __init__(self, connection_alias, **connection_options):
if self.ip_address is None:
raise ImproperlyConfigured("You must specify IP_ADDRESS in your settings for connection '%s'." % connection_alias)

self.boto_conn = boto.connect_cloudsearch(connection_options['AWS_ACCESS_KEY_ID'], connection_options['AWS_SECRET_KEY'])
self.boto_conn = boto.connect_cloudsearch(
aws_access_key_id=connection_options['AWS_ACCESS_KEY_ID'],
aws_secret_access_key=connection_options['AWS_SECRET_KEY'],
region=region_conn
)

# this will become a standard haystack logger down the line
self.log = logging.getLogger('haystack-cloudsearch')
self.setup_complete = False
Expand Down

0 comments on commit 146348a

Please sign in to comment.