Merge lp:~rvb/gwacl/anon-access into lp:gwacl

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: 129
Merged at revision: 129
Proposed branch: lp:~rvb/gwacl/anon-access
Merge into: lp:gwacl
Diff against target: 76 lines (+23/-7)
3 files modified
example/storage/run.go (+3/-3)
storage_base.go (+8/-4)
storage_base_test.go (+12/-0)
To merge this branch: bzr merge lp:~rvb/gwacl/anon-access
Reviewer Review Type Date Requested Status
Gavin Panella Approve
Review via email: mp+171063@code.launchpad.net

Commit message

Allow anon access to the storage API.

Description of the change

This branch changes the gwacl client object so that if the key is the empty string, it will perform anon (i.e. non-authenticated) access.

This is needed because the provider needs to access a public container (i.e. a canonical-maintained container that is publicly readable) to get the tools.
One might argue that the proper way to do this is to split the 'Account' variable into 2: the account used to sign the request and the account to access but this way of doing things is simpler and completely addresses my use case.

This was pre-imp'ed with Gavin.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) wrote :

[1]

Commit message:

  Allow anon access.

It's worth mentioning that this is for the storage API only.

[2]

+    // Access key: access will be done anonymously if the key is the empty
+    // string.

s/will be done anonymously/will be anonymous/

review: Approve
lp:~rvb/gwacl/anon-access updated
129. By Raphaël Badin

Fix comment.

Revision history for this message
Raphaël Badin (rvb) wrote :

Thanks for the review!

> [1]
>
> Commit message:
>
>  Allow anon access.
>
> It's worth mentioning that this is for the storage API only.

Right, done.

> [2]
>
> +    // Access key: access will be done anonymously if the key is the empty
> +    // string.
>
> s/will be done anonymously/will be anonymous/

Okay, done.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'example/storage/run.go'
--- example/storage/run.go 2013-06-21 03:39:08 +0000
+++ example/storage/run.go 2013-06-24 14:42:33 +0000
@@ -42,7 +42,7 @@
4242
43func getParams() (string, error) {43func getParams() (string, error) {
44 flag.StringVar(&account, "account", "", "Storage account name")44 flag.StringVar(&account, "account", "", "Storage account name")
45 flag.StringVar(&key, "key", "", "A valid storage account key (base64 encoded)")45 flag.StringVar(&key, "key", "", "A valid storage account key (base64 encoded), defaults to the empty string (i.e. anonymous access)")
46 flag.StringVar(&container, "container", "", "Name of the container to use")46 flag.StringVar(&container, "container", "", "Name of the container to use")
47 flag.StringVar(&filename, "filename", "", "File containing blob/page to upload/download")47 flag.StringVar(&filename, "filename", "", "File containing blob/page to upload/download")
48 flag.StringVar(&prefix, "prefix", "", "Prefix to match when listing blobs")48 flag.StringVar(&prefix, "prefix", "", "Prefix to match when listing blobs")
@@ -52,8 +52,8 @@
52 flag.StringVar(&pagerange, "pagerange", "", "When uploading to a page blob, this specifies what range in the blob. Use the format 'start-end', e.g. -pagerange 1024-2048")52 flag.StringVar(&pagerange, "pagerange", "", "When uploading to a page blob, this specifies what range in the blob. Use the format 'start-end', e.g. -pagerange 1024-2048")
53 flag.Parse()53 flag.Parse()
5454
55 if account == "" || key == "" {55 if account == "" {
56 return "", fmt.Errorf("Must supply account and key parameters")56 return "", fmt.Errorf("Must supply account parameter")
57 }57 }
5858
59 if len(flag.Args()) != 1 {59 if len(flag.Args()) != 1 {
6060
=== modified file 'storage_base.go'
--- storage_base.go 2013-06-21 14:09:42 +0000
+++ storage_base.go 2013-06-24 14:42:33 +0000
@@ -183,8 +183,11 @@
183// Don't make any further changes to the request before sending it, or the183// Don't make any further changes to the request before sending it, or the
184// signature will not be valid.184// signature will not be valid.
185func (context *StorageContext) signRequest(req *http.Request) {185func (context *StorageContext) signRequest(req *http.Request) {
186 header := composeAuthHeader(req, context.Account, context.Key)186 // Only sign the request if the key is not empty.
187 req.Header.Set("Authorization", header)187 if context.Key != "" {
188 header := composeAuthHeader(req, context.Account, context.Key)
189 req.Header.Set("Authorization", header)
190 }
188}191}
189192
190// StorageContext keeps track of the mandatory parameters required to send a193// StorageContext keeps track of the mandatory parameters required to send a
@@ -192,8 +195,9 @@
192// the client is only created once for all requests.195// the client is only created once for all requests.
193type StorageContext struct {196type StorageContext struct {
194 Account string197 Account string
195 Key string198 // Access key: access will be anonymous if the key is the empty string.
196 client *http.Client199 Key string
200 client *http.Client
197}201}
198202
199// getClient is used when sending a request. If called with an existing client203// getClient is used when sending a request. If called with an existing client
200204
=== modified file 'storage_base_test.go'
--- storage_base_test.go 2013-06-21 15:06:12 +0000
+++ storage_base_test.go 2013-06-24 14:42:33 +0000
@@ -195,6 +195,18 @@
195 c.Assert(req.Header.Get("Authorization"), Equals, expected)195 c.Assert(req.Header.Get("Authorization"), Equals, expected)
196}196}
197197
198func (suite *TestSignRequest) TestDoesNotAddHeaderIfEmptyKey(c *C) {
199 req, err := http.NewRequest(
200 "GET", "http://example.com/mypath?Kevin=Perry&foo=bar", nil)
201 c.Assert(err, IsNil)
202 c.Assert(req.Header.Get("Authorization"), Equals, "")
203
204 context := StorageContext{client: nil, Account: "myname", Key: ""}
205 context.signRequest(req)
206
207 c.Assert(req.Header.Get("Authorization"), Equals, "")
208}
209
198type TestRequestHeaders struct{}210type TestRequestHeaders struct{}
199211
200var _ = Suite(&TestRequestHeaders{})212var _ = Suite(&TestRequestHeaders{})

Subscribers

People subscribed via source and target branches

to all changes: