Merge lp:~rvb/gwacl/delete-deployment into lp:gwacl

Proposed by Raphaël Badin
Status: Merged
Approved by: Raphaël Badin
Approved revision: 71
Merged at revision: 71
Proposed branch: lp:~rvb/gwacl/delete-deployment
Merge into: lp:gwacl
Diff against target: 53 lines (+21/-0)
3 files modified
example/live_example_managementapi.go (+4/-0)
managementapi.go (+5/-0)
managementapi_test.go (+12/-0)
To merge this branch: bzr merge lp:~rvb/gwacl/delete-deployment
Reviewer Review Type Date Requested Status
Gavin Panella Approve
Review via email: mp+155946@code.launchpad.net

Commit message

Add method to delete a deployment.

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

Looks good, but [1] is something we need to address before this
library is ready for production.

[1]

+    URI := "services/hostedservices/" + serviceName + "/deployments/" + deploymentName

serviceName and deploymentName ought to be passed through
url.QueryEscape... but then that will cause double escaping if set as
Path on a url.URL instance. Perhaps what needs to be done is to
replace / with %2F, *then* set as the Path. Something like:

    uri := url.Parse(base_url)
    uri.Path = (
        "services/hostedservices/" +
        strings.Replace(serviceName, "/", "%2F") +
        "/deployments/" +
        strings.Replace(deploymentName, "/", "%2F"))
    return api.session.delete(uri.String())

(Fwiw, I gleaned this from reading url.go alongside §3.3 of RFC 3986.)

This is not a problem unique to this branch, so I don't really expect
you to fix it, but we really ought to before stamping this with a 1.0
version.

Fwiw, a poor-man's fix would be to ensure that we (a) don't allow
forward-slash in user-supplied parts of URLs, and (b) ensure that URLs
are put together using url.URL so that proper escaping takes place.

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

Thanks for the review. As discussed on IRC, I completely agree that we should fix it. But we should fix it with a utility method used everywhere because this escaping problem is all over the place.

I'll look into it and see if we can create a utility like func Urlf(format string, components ...string) that would url-escape the components given to it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'example/live_example_managementapi.go'
2--- example/live_example_managementapi.go 2013-03-27 09:01:34 +0000
3+++ example/live_example_managementapi.go 2013-03-28 12:23:20 +0000
4@@ -143,6 +143,10 @@
5 api.PerformRoleOperation(hostServiceName, deployment.Name, role.RoleName, operation)
6 fmt.Println("Done starting VM\n")
7
8+ fmt.Println("Deleting deployment...")
9+ api.DeleteDeployment(hostServiceName, deployment.Name)
10+ fmt.Println("Done deleting deployment\n")
11+
12 fmt.Println("Deleting hosted service...")
13 api.DeleteHostedService(hostServiceName)
14 fmt.Println("Done deleting hosted service\n")
15
16=== modified file 'managementapi.go'
17--- managementapi.go 2013-03-28 06:34:47 +0000
18+++ managementapi.go 2013-03-28 12:23:20 +0000
19@@ -83,6 +83,11 @@
20 return nil
21 }
22
23+func (api *ManagementAPI) DeleteDeployment(serviceName string, deploymentName string) error {
24+ URI := "services/hostedservices/" + serviceName + "/deployments/" + deploymentName
25+ return api.session.delete(URI)
26+}
27+
28 // AddStorageAccount starts the creation of a storage account. This is
29 // called a storage service in the Azure API, but nomenclature seems to
30 // have changed.
31
32=== modified file 'managementapi_test.go'
33--- managementapi_test.go 2013-03-28 06:34:47 +0000
34+++ managementapi_test.go 2013-03-28 12:23:20 +0000
35@@ -145,6 +145,18 @@
36 checkOneRequest(c, recordedRequests, expectedURL, expectedPayload, "POST")
37 }
38
39+func (suite *managementAPISuite) TestDeleteDeployment(c *C) {
40+ api := suite.makeAPI(c)
41+ recordedRequests := setUpDispatcher("operationID")
42+ hostedServiceName := "testHosterServiceName"
43+ deploymentName := "testDeploymentName"
44+ err := api.DeleteDeployment(hostedServiceName, deploymentName)
45+
46+ c.Assert(err, IsNil)
47+ expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices/" + hostedServiceName + "/deployments/" + deploymentName
48+ checkOneRequest(c, recordedRequests, expectedURL, []byte{}, "DELETE")
49+}
50+
51 func (suite *managementAPISuite) TestAddStorageAccount(c *C) {
52 api := suite.makeAPI(c)
53 rigFixedResponseDispatcher(&x509Response{StatusCode: http.StatusAccepted})

Subscribers

People subscribed via source and target branches

to all changes: