Merge lp:~jtv/gwacl/storage-keys into lp:gwacl

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: 74
Merged at revision: 75
Proposed branch: lp:~jtv/gwacl/storage-keys
Merge into: lp:gwacl
Diff against target: 75 lines (+47/-0)
2 files modified
managementapi.go (+16/-0)
managementapi_test.go (+31/-0)
To merge this branch: bzr merge lp:~jtv/gwacl/storage-keys
Reviewer Review Type Date Requested Status
Raphaël Badin (community) Approve
Review via email: mp+156105@code.launchpad.net

Commit message

Support retrieval of a storage account's access keys.

Description of the change

This was a very straightforward job. I also ran a live test by editing the live management-API example to retrieve the keys, and running it against the real Azure service.

However I didn't bother adding the operation permanently to the live example because, while it would serve relatively little purpose when all the hard parts are in reusable code that's already covered, the change would have had to be right in a spot where we're making important changes.

I'm already expecting a small semantic conflict: this branch uses composeURL, and another branch I have proposed turns that function into a method.

Jeroen

To post a comment you must log in.
Revision history for this message
Raphaël Badin (rvb) wrote :

Looks good.

[0]

51 + body := fmt.Sprintf(`<StorageService>
52 + <Url>%s</Url>

I think the first line should be two lines:
body := fmt.Sprintf(
`<StorageService>

this way, the XML is more readable (if there is such thing as readable XML) because it appears as a "block".

review: Approve
lp:~jtv/gwacl/storage-keys updated
74. By Jeroen T. Vermeulen

Review change: formatted test XML differently.

Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Done. I was a bit hesitant because it would misalign the opening tag's "<" with the closing tag's, but all in all it's better this way.

Revision history for this message
Julian Edwards (julian-edwards) wrote :

On Friday 29 Mar 2013 05:44:21 you wrote:
> +
> + c.Check(keys.Primary, Equals, primaryKey)
> + c.Check(keys.Secondary, Equals, secondaryKey)
> + c.Check(keys.Url, Equals, url)
> +}

You can do this as a single check if you set up an "expected" struct and do a
DeepEquals. See the storage tests (some of which do this).

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'managementapi.go'
2--- managementapi.go 2013-03-29 08:45:30 +0000
3+++ managementapi.go 2013-03-29 12:09:20 +0000
4@@ -146,6 +146,22 @@
5 return api.blockUntilCompleted(response)
6 }
7
8+// GetStorageAccountKeys retrieves a storage account's primary and secondary
9+// access keys from the Azure service.
10+func (api *ManagementAPI) GetStorageAccountKeys(accountName string) (*StorageAccountKeys, error) {
11+ url := "services/storageservices/" + accountName + "/keys"
12+ res, err := api.session.get(url)
13+ if err != nil {
14+ return nil, err
15+ }
16+ keys := StorageAccountKeys{}
17+ err = keys.Deserialize(res.Body)
18+ if err != nil {
19+ return nil, err
20+ }
21+ return &keys, nil
22+}
23+
24 // Perform an operation on the specified role (as defined by serviceName, deploymentName and
25 // roleName)
26 // This is an asynchronous operation, it blocks until the operation is completed.
27
28=== modified file 'managementapi_test.go'
29--- managementapi_test.go 2013-03-29 08:45:30 +0000
30+++ managementapi_test.go 2013-03-29 12:09:20 +0000
31@@ -4,6 +4,7 @@
32 package gwacl
33
34 import (
35+ "fmt"
36 . "launchpad.net/gocheck"
37 "net/http"
38 "time"
39@@ -219,6 +220,36 @@
40 checkOneRequest(c, &recordedRequests, expectedURL, expectedPayload, "POST")
41 }
42
43+func (suite *managementAPISuite) TestGetStorageAccountKeys(c *C) {
44+ const (
45+ accountName = "accountname"
46+ primaryKey = "primarykey"
47+ secondaryKey = "secondarykey"
48+ )
49+ api := suite.makeAPI(c)
50+ url := composeURL("services/storageservices/"+accountName, api.session.subscriptionId)
51+ body := fmt.Sprintf(
52+ `<StorageService>
53+ <Url>%s</Url>
54+ <StorageServiceKeys>
55+ <Primary>%s</Primary>
56+ <Secondary>%s</Secondary>
57+ </StorageServiceKeys>
58+ </StorageService>`,
59+ url, primaryKey, secondaryKey)
60+ rigFixedResponseDispatcher(&x509Response{
61+ StatusCode: http.StatusOK,
62+ Body: []byte(body),
63+ })
64+
65+ keys, err := api.GetStorageAccountKeys("account")
66+ c.Assert(err, IsNil)
67+
68+ c.Check(keys.Primary, Equals, primaryKey)
69+ c.Check(keys.Secondary, Equals, secondaryKey)
70+ c.Check(keys.Url, Equals, url)
71+}
72+
73 func (suite *managementAPISuite) TestPerformNodeOperation(c *C) {
74 api := suite.makeAPI(c)
75 recordedRequests := setUpDispatcher("operationID")

Subscribers

People subscribed via source and target branches