From 85e05f45e894609508e9d19de96ab0e318303128 Mon Sep 17 00:00:00 2001 From: Randall Degges Date: Tue, 24 Jul 2012 17:05:27 -0700 Subject: [PATCH 1/3] Making all `auth` arguments optional. This lets us authenticate to DynamoDB using our environment credentials (through boto), eg: AWS_ACCESS_KEY_ID, and AWS_SECRET_ACCESS_KEY --- dynamo.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/dynamo.py b/dynamo.py index 084f802..4f8487e 100644 --- a/dynamo.py +++ b/dynamo.py @@ -110,14 +110,22 @@ class Item(object): return key in self.item -def table(name, auth, eager=True): +def table(name, auth=None, eager=True): """Returns a given table for the given user.""" - dynamodb = boto.connect_dynamodb(*auth) + if auth: + dynamodb = boto.connect_dynamodb(*auth) + else: + dynamodb = boto.connect_dynamodb() + table = dynamodb.get_table(name) return Table(table=table, eager=eager) -def tables(auth, eager=True): +def tables(auth=None, eager=True): """Returns a list of tables for the given user.""" - dynamodb = boto.connect_dynamodb(*auth) + if auth: + dynamodb = boto.connect_dynamodb(*auth) + else: + dynamodb = boto.connect_dynamodb() + return [table(t, auth, eager=eager) for t in dynamodb.list_tables()] From 053d36046e30c9048811fecf2ce6028aeafc9f73 Mon Sep 17 00:00:00 2001 From: Randall Degges Date: Tue, 24 Jul 2012 17:10:08 -0700 Subject: [PATCH 2/3] Adding environment variable auth docs to README. --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 8fee536..85de0d5 100644 --- a/README.rst +++ b/README.rst @@ -17,6 +17,9 @@ Usage table = dynamo.table(TABLE_NAME, (ACCESS_KEY, SECRET_ACCESS_KEY)) + # Or, if you have AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY defined as + # environment variables, you can do: + table = dynamo.table(TABLE_NAME) Writing is simple:: From 45fa3cbdc950270fd375ab7856ac266c93a60586 Mon Sep 17 00:00:00 2001 From: Randall Degges Date: Tue, 24 Jul 2012 17:11:05 -0700 Subject: [PATCH 3/3] Cleaning up that nastiness. --- dynamo.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/dynamo.py b/dynamo.py index 4f8487e..a842f4d 100644 --- a/dynamo.py +++ b/dynamo.py @@ -112,10 +112,8 @@ class Item(object): def table(name, auth=None, eager=True): """Returns a given table for the given user.""" - if auth: - dynamodb = boto.connect_dynamodb(*auth) - else: - dynamodb = boto.connect_dynamodb() + auth = auth or [] + dynamodb = boto.connect_dynamodb(*auth) table = dynamodb.get_table(name) return Table(table=table, eager=eager) @@ -123,9 +121,7 @@ def table(name, auth=None, eager=True): def tables(auth=None, eager=True): """Returns a list of tables for the given user.""" - if auth: - dynamodb = boto.connect_dynamodb(*auth) - else: - dynamodb = boto.connect_dynamodb() + auth = auth or [] + dynamodb = boto.connect_dynamodb(*auth) return [table(t, auth, eager=eager) for t in dynamodb.list_tables()]