Re: [Txawsteam] [Merge] lp:~oubiwann/txaws/416109-arbitrary-endpoints into lp:txaws

2009-08-28 Thread Duncan McGreggor
 [1] Some flakes
 txaws/ec2/client.py:6: 'b64encode' imported but unused
 txaws/storage/client.py:10: 'b64encode' imported but unused
 txaws/storage/client.py:11: 'md5' imported but unused
 txaws/storage/client.py:18: 'AWSCredentials' imported but unused
 txaws/tests/test_credentials.py:6: 'TestCase' imported but unused

Fixed.

 [2]
 +try:
 +gtk2reactor.install()
 +except AssertionError:
 +pass
 
 Really? What's the reason behind this change?

I was getting errors in the unit tests without this. I've just commented it 
out, and run it again, but I'm not longer getting the errors. Dunno. Removed.
 
 [3]
  key_id = content.get_children()[0].get_children()[1].get_text()
  secret_key =
 content.get_children()[1].get_children()[1].get_text()
  creds = AWSCredentials(access_key=key_id, secret_key=secret_key)
 +region = AWSServiceRegion(creds=creds)
  self.create_client(creds)
  gnomekeyring.item_create_sync(
  None,
 
 This change seems unecessary.

Yup, it is. Removed.

 [4]
 +from twisted.web.client import _parse
 
 It's pretty sad, but you can't import that, it's private. You have to copy the
 function.

Copied this function and its unit tests from twisted.

 [5]
 +self.assertEquals(client1, client2)
 +
 +
 +def test_get_s3_client(self):
 
 There is an extra blank line here.

This was removed with the changes I made from Jamu's comments.
-- 
https://code.edge.launchpad.net/~oubiwann/txaws/416109-arbitrary-endpoints/+merge/10671
Your team txAWS Team is subscribed to branch lp:txaws.

___
Mailing list: https://launchpad.net/~txawsteam
Post to : txawsteam@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txawsteam
More help   : https://help.launchpad.net/ListHelp


[Txawsteam] [Merge] lp:~oubiwann/txaws/416109-arbitrary-endpoints into lp:txaws

2009-08-25 Thread Duncan McGreggor
Duncan McGreggor has proposed merging 
lp:~oubiwann/txaws/416109-arbitrary-endpoints into lp:txaws.


-- 
https://code.launchpad.net/~oubiwann/txaws/416109-arbitrary-endpoints/+merge/10671
Your team txAWS Team is subscribed to branch lp:txaws.
=== modified file 'txaws/client/gui/gtk.py'
--- txaws/client/gui/gtk.py	2009-08-18 22:53:53 +
+++ txaws/client/gui/gtk.py	2009-08-25 16:04:05 +
@@ -9,6 +9,7 @@
 import gtk
 
 from txaws.credentials import AWSCredentials
+from txaws.service import AWSServiceRegion
 
 
 __all__ = ['main']
@@ -30,6 +31,7 @@
 creds = AWSCredentials()
 except ValueError:
 creds = self.from_gnomekeyring()
+self.region = AWSServiceRegion(creds)
 self.create_client(creds)
 menu = '''
 ui
@@ -55,9 +57,8 @@
 self.connect('popup-menu', self.on_popup_menu)
 
 def create_client(self, creds):
-from txaws.ec2.client import EC2Client
 if creds is not None:
-self.client = EC2Client(creds=creds)
+self.client = self.region.get_ec2_client()
 self.on_activate(None)
 else:
 # waiting on user entered credentials.
@@ -134,6 +135,7 @@
 key_id = content.get_children()[0].get_children()[1].get_text()
 secret_key = content.get_children()[1].get_children()[1].get_text()
 creds = AWSCredentials(access_key=key_id, secret_key=secret_key)
+region = AWSServiceRegion(creds=creds)
 self.create_client(creds)
 gnomekeyring.item_create_sync(
 None,
@@ -196,7 +198,10 @@
 
 if reactor is None:
 from twisted.internet import gtk2reactor
-gtk2reactor.install()
+try:
+gtk2reactor.install()
+except AssertionError:
+pass
 from twisted.internet import reactor
 status = AWSStatusIcon(reactor)
 gobject.set_application_name('aws-status')

=== modified file 'txaws/credentials.py'
--- txaws/credentials.py	2009-08-17 11:18:56 +
+++ txaws/credentials.py	2009-08-25 14:36:20 +
@@ -5,32 +5,37 @@
 
 import os
 
-from txaws.util import *
+from txaws.util import hmac_sha1
 
 
 __all__ = ['AWSCredentials']
 
 
+ENV_ACCESS_KEY = AWS_ACCESS_KEY_ID
+ENV_SECRET_KEY = AWS_SECRET_ACCESS_KEY
+
+
 class AWSCredentials(object):
 
-def __init__(self, access_key=None, secret_key=None):
+def __init__(self, access_key=, secret_key=):
 Create an AWSCredentials object.
 
-:param access_key: The access key to use. If None the environment
+@param access_key: The access key to use. If None the environment
 variable AWS_ACCESS_KEY_ID is consulted.
-:param secret_key: The secret key to use. If None the environment
+@param secret_key: The secret key to use. If None the environment
 variable AWS_SECRET_ACCESS_KEY is consulted.
 
+self.access_key = access_key
 self.secret_key = secret_key
-if self.secret_key is None:
-self.secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY')
-if self.secret_key is None:
-raise ValueError('Could not find AWS_SECRET_ACCESS_KEY')
-self.access_key = access_key
-if self.access_key is None:
-self.access_key = os.environ.get('AWS_ACCESS_KEY_ID')
-if self.access_key is None:
-raise ValueError('Could not find AWS_ACCESS_KEY_ID')
+if not self.access_key:
+self.access_key = os.environ.get(ENV_ACCESS_KEY)
+if not self.access_key:
+raise ValueError(Could not find %s % ENV_ACCESS_KEY)
+# perform checks for secret key
+if not self.secret_key:
+self.secret_key = os.environ.get(ENV_SECRET_KEY)
+if not self.secret_key:
+raise ValueError(Could not find %s % ENV_SECRET_KEY)
 
 def sign(self, bytes):
 Sign some bytes.

=== modified file 'txaws/ec2/client.py'
--- txaws/ec2/client.py	2009-08-21 03:26:35 +
+++ txaws/ec2/client.py	2009-08-25 16:04:05 +
@@ -8,7 +8,8 @@
 
 from twisted.web.client import getPage
 
-from txaws import credentials
+from txaws.credentials import AWSCredentials
+from txaws.service import AWSServiceEndpoint
 from txaws.util import iso8601time, XML
 
 
@@ -77,16 +78,16 @@
 
 name_space = '{http://ec2.amazonaws.com/doc/2008-12-01/}'
 
-def __init__(self, creds=None, query_factory=None):
+def __init__(self, creds=None, endpoint=None, query_factory=None):
 Create an EC2Client.
 
-@param creds: Explicit credentials to use. If None, credentials are
-inferred as per txaws.credentials.AWSCredentials.
+@param creds: User authentication credentials to use.
+@param endpoint: The service endpoint URI.
+@param query_factory: The class or function that produces a query
+object for making requests to the EC2 service.
 
-if creds is None:
-   

Re: [Txawsteam] [Merge] lp:~oubiwann/txaws/416109-arbitrary-endpoints into lp:txaws

2009-08-24 Thread Robert Collins

On Sun, 2009-08-23 at 21:30 +, Robert Collins wrote:
 === modified file 'txaws/client/gui/gtk.py'
 --- txaws/client/gui/gtk.py 2009-08-18 22:53:53 +
 +++ txaws/client/gui/gtk.py 2009-08-20 19:14:32 +
 @@ -8,7 +8,7 @@
  import gobject
  import gtk
  
 -from txaws.credentials import AWSCredentials
 +from txaws.ec2.service import EC2Service
  
  
  __all__ = ['main']
 @@ -27,10 +27,10 @@
  # Nested import because otherwise we get 'reactor already
 installed'.
  self.password_dialog = None
  try:
 -creds = AWSCredentials()
 +service = AWSService()

This is going to be a NameError :P

...
 === added file 'txaws/credentials.py'

this file already exists. I think you've done something weird in your
branch. lets review once thats fixed. Find me in #bzr :P

review needsfixing



-- 

https://code.launchpad.net/~oubiwann/txaws/416109-arbitrary-endpoints/+merge/10581
Your team txAWS Team is subscribed to branch lp:txaws.

___
Mailing list: https://launchpad.net/~txawsteam
Post to : txawsteam@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txawsteam
More help   : https://help.launchpad.net/ListHelp


[Txawsteam] [Merge] lp:~oubiwann/txaws/416109-arbitrary-endpoints into lp:txaws

2009-08-20 Thread Duncan McGreggor
Duncan McGreggor has proposed merging 
lp:~oubiwann/txaws/416109-arbitrary-endpoints into lp:txaws.

Requested reviews:
txAWS Team (txawsteam)

This branch adds support for a service object that manages host endpoints as 
well as authorization keys (thus obviating the need for the AWSCredential 
object).
-- 
https://code.launchpad.net/~oubiwann/txaws/416109-arbitrary-endpoints/+merge/10477
Your team txAWS Team is subscribed to branch lp:txaws.
=== modified file 'txaws/client/gui/gtk.py'
--- txaws/client/gui/gtk.py	2009-08-18 22:53:53 +
+++ txaws/client/gui/gtk.py	2009-08-20 19:14:32 +
@@ -8,7 +8,7 @@
 import gobject
 import gtk
 
-from txaws.credentials import AWSCredentials
+from txaws.ec2.service import EC2Service
 
 
 __all__ = ['main']
@@ -27,10 +27,10 @@
 # Nested import because otherwise we get 'reactor already installed'.
 self.password_dialog = None
 try:
-creds = AWSCredentials()
+service = AWSService()
 except ValueError:
-creds = self.from_gnomekeyring()
-self.create_client(creds)
+service = self.from_gnomekeyring()
+self.create_client(service)
 menu = '''
 ui
  menubar name=Menubar
@@ -54,10 +54,10 @@
 '/Menubar/Menu/Stop instances').props.parent
 self.connect('popup-menu', self.on_popup_menu)
 
-def create_client(self, creds):
+def create_client(self, service):
 from txaws.ec2.client import EC2Client
-if creds is not None:
-self.client = EC2Client(creds=creds)
+if service is not None:
+self.client = EC2Client(service=service)
 self.on_activate(None)
 else:
 # waiting on user entered credentials.
@@ -65,7 +65,7 @@
 
 def from_gnomekeyring(self):
 # Try for gtk gui specific credentials.
-creds = None
+service = None
 try:
 items = gnomekeyring.find_items_sync(
 gnomekeyring.ITEM_GENERIC_SECRET,
@@ -78,7 +78,7 @@
 return None
 else:
 key_id, secret_key = items[0].secret.split(':')
-return AWSCredentials(access_key=key_id, secret_key=secret_key)
+return EC2Service(access_key=key_id, secret_key=secret_key)
 
 def show_a_password_dialog(self):
 self.password_dialog = gtk.Dialog(
@@ -133,8 +133,8 @@
 content = self.password_dialog.get_content_area()
 key_id = content.get_children()[0].get_children()[1].get_text()
 secret_key = content.get_children()[1].get_children()[1].get_text()
-creds = AWSCredentials(access_key=key_id, secret_key=secret_key)
-self.create_client(creds)
+service = EC2Service(access_key=key_id, secret_key=secret_key)
+self.create_client(service)
 gnomekeyring.item_create_sync(
 None,
 gnomekeyring.ITEM_GENERIC_SECRET,

=== removed file 'txaws/credentials.py'
--- txaws/credentials.py	2009-08-17 11:18:56 +
+++ txaws/credentials.py	1970-01-01 00:00:00 +
@@ -1,37 +0,0 @@
-# Copyright (C) 2009 Robert Collins robe...@robertcollins.net
-# Licenced under the txaws licence available at /LICENSE in the txaws source.
-
-Credentials for accessing AWS services.
-
-import os
-
-from txaws.util import *
-
-
-__all__ = ['AWSCredentials']
-
-
-class AWSCredentials(object):
-
-def __init__(self, access_key=None, secret_key=None):
-Create an AWSCredentials object.
-
-:param access_key: The access key to use. If None the environment
-variable AWS_ACCESS_KEY_ID is consulted.
-:param secret_key: The secret key to use. If None the environment
-variable AWS_SECRET_ACCESS_KEY is consulted.
-
-self.secret_key = secret_key
-if self.secret_key is None:
-self.secret_key = os.environ.get('AWS_SECRET_ACCESS_KEY')
-if self.secret_key is None:
-raise ValueError('Could not find AWS_SECRET_ACCESS_KEY')
-self.access_key = access_key
-if self.access_key is None:
-self.access_key = os.environ.get('AWS_ACCESS_KEY_ID')
-if self.access_key is None:
-raise ValueError('Could not find AWS_ACCESS_KEY_ID')
-
-def sign(self, bytes):
-Sign some bytes.
-return hmac_sha1(self.secret_key, bytes)

=== modified file 'txaws/ec2/client.py'
--- txaws/ec2/client.py	2009-08-18 21:56:36 +
+++ txaws/ec2/client.py	2009-08-20 16:47:54 +
@@ -8,7 +8,7 @@
 
 from twisted.web.client import getPage
 
-from txaws import credentials
+from txaws.ec2.service import EC2Service
 from txaws.util import iso8601time, XML
 
 
@@ -46,16 +46,15 @@
 
 name_space = '{http://ec2.amazonaws.com/doc/2008-12-01/}'
 
-def __init__(self, creds=None, query_factory=None):
+def __init__(self, service=None, query_factory=None):
 Create an EC2Client.
 
-

Re: [Txawsteam] [Merge] lp:~oubiwann/txaws/416109-arbitrary-endpoints into lp:txaws

2009-08-20 Thread Robert Collins
On Thu, 2009-08-20 at 19:25 +, Duncan McGreggor wrote:
 Duncan McGreggor has proposed merging
 lp:~oubiwann/txaws/416109-arbitrary-endpoints into lp:txaws.
 
 Requested reviews:
 txAWS Team (txawsteam)
 
 This branch adds support for a service object that manages host
 endpoints as well as authorization keys (thus obviating the need for
 the AWSCredential object).


Lets be careful to keep space under storage, ec2 etc for server 
components. storage.service isn't really a storage service :) Lets call
the description of an end point AWSServiceEndpoint, or something like
that.

local and credentials appear orthogonal to me - for instance, 
EC2 EU and EC2 US are different endpoints/services with common
credentials. I think conflating them is unnecessary and undesirable. 
Further  to that, the AWSCredentials are usable on related services in a
single region - EC2, S3 and so on, so when we're passing around a
description, we probably want to have a region that describes the
endpoints for a collection of services. The goal being able to have a
static object
AWS_US1 = #...
AWS_US2 = #...
and for people to make their own;
my_eucalyptus_region = #...

At runtime then, one would ask a region for a client of a particular
service, using some credentials.

AWS_US1.make_ec2_client(my_creds)
AWS_US1.make_sqs_client(my_creds)

etc.

We could do this without changing the existing clients at all, by just
storing scheme,host tuples in a AWSRegion - but I think it is cleaner to
do the sort of refactoring you have done. I think it would be best by
having an AWSServiceEndpoint which has the scheme and url, and keeping
the creds separate. For instance, 
class AWSServiceRegion:
def make_ec2_client(self, creds=None):
return EC2Client(creds=creds,  service_endpoint=self.ec2_endpoint)

Also a bit of detail review - 'default_schema = https' - in URL terms
(see http://www.ietf.org/rfc/rfc3986.txt) that is a _scheme_, not a
_schema_. 

review needsfixing

-- 
https://code.launchpad.net/~oubiwann/txaws/416109-arbitrary-endpoints/+merge/10477
Your team txAWS Team is subscribed to branch lp:txaws.

___
Mailing list: https://launchpad.net/~txawsteam
Post to : txawsteam@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txawsteam
More help   : https://help.launchpad.net/ListHelp


Re: [Txawsteam] [Merge] lp:~oubiwann/txaws/416109-arbitrary-endpoints into lp:txaws

2009-08-20 Thread Duncan McGreggor
 On Thu, 2009-08-20 at 19:25 +, Duncan McGreggor wrote:
  Duncan McGreggor has proposed merging
  lp:~oubiwann/txaws/416109-arbitrary-endpoints into lp:txaws.
 
  Requested reviews:
  txAWS Team (txawsteam)
 
  This branch adds support for a service object that manages host
  endpoints as well as authorization keys (thus obviating the need for
  the AWSCredential object).
 
 
 Lets be careful to keep space under storage, ec2 etc for server
 components. storage.service isn't really a storage service :) Lets call
 the description of an end point AWSServiceEndpoint, or something like
 that.
 
 local and credentials appear orthogonal to me - for instance,
 EC2 EU and EC2 US are different endpoints/services with common
 credentials. I think conflating them is unnecessary and undesirable.
 Further  to that, the AWSCredentials are usable on related services in a
 single region - EC2, S3 and so on, so when we're passing around a
 description, we probably want to have a region that describes the
 endpoints for a collection of services. The goal being able to have a
 static object
 AWS_US1 = #...
 AWS_US2 = #...
 and for people to make their own;
 my_eucalyptus_region = #...
 
 At runtime then, one would ask a region for a client of a particular
 service, using some credentials.
 
 AWS_US1.make_ec2_client(my_creds)
 AWS_US1.make_sqs_client(my_creds)
 
 etc.
 
 We could do this without changing the existing clients at all, by just
 storing scheme,host tuples in a AWSRegion - but I think it is cleaner to
 do the sort of refactoring you have done. I think it would be best by
 having an AWSServiceEndpoint which has the scheme and url, and keeping
 the creds separate. For instance,
 class AWSServiceRegion:
 def make_ec2_client(self, creds=None):
 return EC2Client(creds=creds,  service_endpoint=self.ec2_endpoint)
 
 Also a bit of detail review - 'default_schema = https' - in URL terms
 (see http://www.ietf.org/rfc/rfc3986.txt) that is a _scheme_, not a
 _schema_.
 
 review needsfixing

+1 on these suggestions. I'll give it another go with this in mind.
-- 
https://code.edge.launchpad.net/~oubiwann/txaws/416109-arbitrary-endpoints/+merge/10477
Your team txAWS Team is subscribed to branch lp:txaws.

___
Mailing list: https://launchpad.net/~txawsteam
Post to : txawsteam@lists.launchpad.net
Unsubscribe : https://launchpad.net/~txawsteam
More help   : https://help.launchpad.net/ListHelp