Skip to content

Commit

Permalink
deploy: send data in body instead of query string in app-deploy-rollb…
Browse files Browse the repository at this point in the history
…ack.
  • Loading branch information
dnsaoki2 committed Jun 3, 2016
1 parent 34721db commit 83ecdaa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 6 additions & 3 deletions tsuru/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"io/ioutil"
"mime/multipart"
"net/http"
"net/url"
"os"
"path"
"sort"
Expand Down Expand Up @@ -419,12 +420,14 @@ func (c *appDeployRollback) Run(context *cmd.Context, client *cmd.Client) error
if !c.Confirm(context, fmt.Sprintf("Are you sure you want to rollback app %q to image %q?", appName, imgName)) {
return nil
}
url, err := cmd.GetURL(fmt.Sprintf("/apps/%s/deploy/rollback?origin=%s", appName, "rollback"))
u, err := cmd.GetURL(fmt.Sprintf("/apps/%s/deploy/rollback", appName))
if err != nil {
return err
}
body := strings.NewReader("image=" + imgName)
request, err := http.NewRequest("POST", url, body)
v := url.Values{}
v.Set("origin", "rollback")
v.Set("image", imgName)
request, err := http.NewRequest("POST", u, strings.NewReader(v.Encode()))
if err != nil {
return err
}
Expand Down
8 changes: 5 additions & 3 deletions tsuru/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,11 @@ func (s *S) TestAppDeployRollback(c *check.C) {
Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
called = true
body, _ := ioutil.ReadAll(req.Body)
return strings.HasSuffix(req.URL.Path, "/apps/arrakis/deploy/rollback") &&
req.Method == "POST" && string(body) == "image=my-image" && req.URL.RawQuery == "origin=rollback"
method := req.Method == "POST"
path := strings.HasSuffix(req.URL.Path, "/apps/arrakis/deploy/rollback")
image := req.FormValue("image") == "my-image"
rollback := req.FormValue("origin") == "rollback"
return method && path && image && rollback
},
}
client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
Expand Down

0 comments on commit 83ecdaa

Please sign in to comment.