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
1=== modified file 'example/storage/run.go'
2--- example/storage/run.go 2013-06-21 03:39:08 +0000
3+++ example/storage/run.go 2013-06-24 14:42:33 +0000
4@@ -42,7 +42,7 @@
5
6 func getParams() (string, error) {
7 flag.StringVar(&account, "account", "", "Storage account name")
8- flag.StringVar(&key, "key", "", "A valid storage account key (base64 encoded)")
9+ flag.StringVar(&key, "key", "", "A valid storage account key (base64 encoded), defaults to the empty string (i.e. anonymous access)")
10 flag.StringVar(&container, "container", "", "Name of the container to use")
11 flag.StringVar(&filename, "filename", "", "File containing blob/page to upload/download")
12 flag.StringVar(&prefix, "prefix", "", "Prefix to match when listing blobs")
13@@ -52,8 +52,8 @@
14 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")
15 flag.Parse()
16
17- if account == "" || key == "" {
18- return "", fmt.Errorf("Must supply account and key parameters")
19+ if account == "" {
20+ return "", fmt.Errorf("Must supply account parameter")
21 }
22
23 if len(flag.Args()) != 1 {
24
25=== modified file 'storage_base.go'
26--- storage_base.go 2013-06-21 14:09:42 +0000
27+++ storage_base.go 2013-06-24 14:42:33 +0000
28@@ -183,8 +183,11 @@
29 // Don't make any further changes to the request before sending it, or the
30 // signature will not be valid.
31 func (context *StorageContext) signRequest(req *http.Request) {
32- header := composeAuthHeader(req, context.Account, context.Key)
33- req.Header.Set("Authorization", header)
34+ // Only sign the request if the key is not empty.
35+ if context.Key != "" {
36+ header := composeAuthHeader(req, context.Account, context.Key)
37+ req.Header.Set("Authorization", header)
38+ }
39 }
40
41 // StorageContext keeps track of the mandatory parameters required to send a
42@@ -192,8 +195,9 @@
43 // the client is only created once for all requests.
44 type StorageContext struct {
45 Account string
46- Key string
47- client *http.Client
48+ // Access key: access will be anonymous if the key is the empty string.
49+ Key string
50+ client *http.Client
51 }
52
53 // getClient is used when sending a request. If called with an existing client
54
55=== modified file 'storage_base_test.go'
56--- storage_base_test.go 2013-06-21 15:06:12 +0000
57+++ storage_base_test.go 2013-06-24 14:42:33 +0000
58@@ -195,6 +195,18 @@
59 c.Assert(req.Header.Get("Authorization"), Equals, expected)
60 }
61
62+func (suite *TestSignRequest) TestDoesNotAddHeaderIfEmptyKey(c *C) {
63+ req, err := http.NewRequest(
64+ "GET", "http://example.com/mypath?Kevin=Perry&foo=bar", nil)
65+ c.Assert(err, IsNil)
66+ c.Assert(req.Header.Get("Authorization"), Equals, "")
67+
68+ context := StorageContext{client: nil, Account: "myname", Key: ""}
69+ context.signRequest(req)
70+
71+ c.Assert(req.Header.Get("Authorization"), Equals, "")
72+}
73+
74 type TestRequestHeaders struct{}
75
76 var _ = Suite(&TestRequestHeaders{})

Subscribers

People subscribed via source and target branches

to all changes: