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
=== modified file 'example/live_example_managementapi.go'
--- example/live_example_managementapi.go 2013-03-27 09:01:34 +0000
+++ example/live_example_managementapi.go 2013-03-28 12:23:20 +0000
@@ -143,6 +143,10 @@
143 api.PerformRoleOperation(hostServiceName, deployment.Name, role.RoleName, operation)143 api.PerformRoleOperation(hostServiceName, deployment.Name, role.RoleName, operation)
144 fmt.Println("Done starting VM\n")144 fmt.Println("Done starting VM\n")
145145
146 fmt.Println("Deleting deployment...")
147 api.DeleteDeployment(hostServiceName, deployment.Name)
148 fmt.Println("Done deleting deployment\n")
149
146 fmt.Println("Deleting hosted service...")150 fmt.Println("Deleting hosted service...")
147 api.DeleteHostedService(hostServiceName)151 api.DeleteHostedService(hostServiceName)
148 fmt.Println("Done deleting hosted service\n")152 fmt.Println("Done deleting hosted service\n")
149153
=== modified file 'managementapi.go'
--- managementapi.go 2013-03-28 06:34:47 +0000
+++ managementapi.go 2013-03-28 12:23:20 +0000
@@ -83,6 +83,11 @@
83 return nil83 return nil
84}84}
8585
86func (api *ManagementAPI) DeleteDeployment(serviceName string, deploymentName string) error {
87 URI := "services/hostedservices/" + serviceName + "/deployments/" + deploymentName
88 return api.session.delete(URI)
89}
90
86// AddStorageAccount starts the creation of a storage account. This is91// AddStorageAccount starts the creation of a storage account. This is
87// called a storage service in the Azure API, but nomenclature seems to92// called a storage service in the Azure API, but nomenclature seems to
88// have changed.93// have changed.
8994
=== modified file 'managementapi_test.go'
--- managementapi_test.go 2013-03-28 06:34:47 +0000
+++ managementapi_test.go 2013-03-28 12:23:20 +0000
@@ -145,6 +145,18 @@
145 checkOneRequest(c, recordedRequests, expectedURL, expectedPayload, "POST")145 checkOneRequest(c, recordedRequests, expectedURL, expectedPayload, "POST")
146}146}
147147
148func (suite *managementAPISuite) TestDeleteDeployment(c *C) {
149 api := suite.makeAPI(c)
150 recordedRequests := setUpDispatcher("operationID")
151 hostedServiceName := "testHosterServiceName"
152 deploymentName := "testDeploymentName"
153 err := api.DeleteDeployment(hostedServiceName, deploymentName)
154
155 c.Assert(err, IsNil)
156 expectedURL := AZURE_URL + api.session.subscriptionId + "/services/hostedservices/" + hostedServiceName + "/deployments/" + deploymentName
157 checkOneRequest(c, recordedRequests, expectedURL, []byte{}, "DELETE")
158}
159
148func (suite *managementAPISuite) TestAddStorageAccount(c *C) {160func (suite *managementAPISuite) TestAddStorageAccount(c *C) {
149 api := suite.makeAPI(c)161 api := suite.makeAPI(c)
150 rigFixedResponseDispatcher(&x509Response{StatusCode: http.StatusAccepted})162 rigFixedResponseDispatcher(&x509Response{StatusCode: http.StatusAccepted})

Subscribers

People subscribed via source and target branches

to all changes: