Skip to content

Commit

Permalink
removes setAppEnvFile and add version on request header (#6)
Browse files Browse the repository at this point in the history
removes setAppEnvFile and add version on request header
  • Loading branch information
guilhermebr authored Aug 7, 2017
1 parent c1647a9 commit b0baa76
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 37 deletions.
15 changes: 9 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ func (c Client) getAppEnvs(appName string) ([]bind.EnvVar, error) {
if err != nil {
return nil, err
}
req.Header.Set("Authorization", fmt.Sprintf("bearer %s", c.Token))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
c.setHeaders(req)
resp, err := httpClient.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -87,8 +86,7 @@ func (c Client) registerUnit(appName string, customData TsuruYaml) ([]bind.EnvVa
if err != nil {
return nil, err
}
req.Header.Set("Authorization", fmt.Sprintf("bearer %s", c.Token))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
c.setHeaders(req)
resp, err := httpClient.Do(req)
if err != nil {
return nil, err
Expand All @@ -115,8 +113,7 @@ func (c Client) sendDiffDeploy(diff, appName string) error {
if err != nil {
return err
}
req.Header.Set("Authorization", fmt.Sprintf("bearer %s", c.Token))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
c.setHeaders(req)
resp, err := httpClient.Do(req)
if err != nil {
return err
Expand All @@ -135,3 +132,9 @@ func (c Client) sendDiffDeploy(diff, appName string) error {
func (c Client) url(path string) string {
return fmt.Sprintf("%s/%s", strings.TrimRight(c.URL, "/"), strings.TrimLeft(path, "/"))
}

func (c Client) setHeaders(req *http.Request) {
req.Header.Set("Authorization", fmt.Sprintf("bearer %s", c.Token))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("x-Agent-Version", version)
}
2 changes: 2 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func (s *S) TestClient(c *check.C) {
call++
c.Assert(r.Header.Get("Authorization"), check.Not(check.Equals), "")
c.Assert(r.Header.Get("Content-Type"), check.Equals, "application/x-www-form-urlencoded")
c.Assert(r.Header.Get("x-Agent-Version"), check.Equals, version)
c.Assert(r.URL.Path, check.Equals, "/apps/test/units/register")
b, err := ioutil.ReadAll(r.Body)
c.Assert(err, check.IsNil)
Expand Down Expand Up @@ -76,6 +77,7 @@ func (s *S) TestClientSendDiff(c *check.C) {
call++
c.Assert(r.Header.Get("Authorization"), check.Not(check.Equals), "")
c.Assert(r.Header.Get("Content-Type"), check.Equals, "application/x-www-form-urlencoded")
c.Assert(r.Header.Get("x-Agent-Version"), check.Equals, version)
c.Assert(r.URL.Path, check.Equals, "/apps/test/diff")
b, err := ioutil.ReadAll(r.Body)
c.Assert(err, check.IsNil)
Expand Down
4 changes: 0 additions & 4 deletions deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ func build(c Client, appName string, cmd []string) {
if err != nil {
log.Fatal(err)
}
err = saveAppEnvsFile(envs)
if err != nil {
log.Fatal(err)
}
err = execScript(cmd, envs, nil)
if err != nil {
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"os"
)

const version = "0.2.4"
const version = "0.2.5"

var printVersion bool

Expand Down
12 changes: 0 additions & 12 deletions tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,6 @@ func loadProcesses(t *TsuruYaml) error {
return nil
}

func saveAppEnvsFile(envs []bind.EnvVar) error {
f, err := filesystem().Create(appEnvsFile)
if err != nil {
return err
}
defer f.Close()
for _, e := range envs {
f.Write([]byte(fmt.Sprintf("export %s='%s'\n", e.Name, e.Value)))
}
return nil
}

func readDiffDeploy() (string, bool, error) {
filePath := fmt.Sprintf("%s/%s", defaultWorkingDir, "diff")
f, err := filesystem().Open(filePath)
Expand Down
14 changes: 0 additions & 14 deletions tasks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"os"

"github.com/tsuru/tsuru/app/bind"
Expand Down Expand Up @@ -191,19 +190,6 @@ func (s *S) TestDontLoadWrongProcfile(c *check.C) {
c.Assert(err.Error(), check.Equals, `invalid Procfile, no processes found in "web:\n\t@python test.py"`)
}

func (s *S) TestSaveAppEnvsFile(c *check.C) {
envs := []bind.EnvVar{{Name: "foo", Value: "bar"}}
err := saveAppEnvsFile(envs)
c.Assert(err, check.IsNil)
c.Assert(s.fs.HasAction(fmt.Sprintf("create %s", appEnvsFile)), check.Equals, true)
f, err := s.fs.Open(appEnvsFile)
c.Assert(err, check.IsNil)
defer f.Close()
content, err := ioutil.ReadAll(f)
c.Assert(err, check.IsNil)
c.Assert(string(content), check.Equals, "export foo='bar'\n")
}

func (s *S) TestDiffDeploy(c *check.C) {
diff := `--- hello.go 2015-11-25 16:04:22.409241045 +0000
+++ hello.go 2015-11-18 18:40:21.385697080 +0000
Expand Down

0 comments on commit b0baa76

Please sign in to comment.