diff --git a/go.mod b/go.mod index 82c56c35..65022e66 100644 --- a/go.mod +++ b/go.mod @@ -19,8 +19,10 @@ require ( github.com/tsuru/go-tsuruclient v0.0.0-20231124151049-7b8d8ea2ee30 github.com/tsuru/tablecli v0.0.0-20190131152944-7ded8a3383c6 github.com/tsuru/tsuru v0.0.0-20240220172434-1ffd178d4e76 + golang.org/x/net v0.20.0 golang.org/x/oauth2 v0.16.0 golang.org/x/sys v0.16.0 + golang.org/x/term v0.16.0 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c gopkg.in/yaml.v2 v2.4.0 k8s.io/apimachinery v0.26.2 @@ -71,8 +73,6 @@ require ( github.com/tsuru/config v0.0.0-20201023175036-375aaee8b560 // indirect golang.org/x/crypto v0.18.0 // indirect golang.org/x/mod v0.8.0 // indirect - golang.org/x/net v0.20.0 // indirect - golang.org/x/term v0.16.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.6.0 // indirect diff --git a/go.sum b/go.sum index db41a8c8..a68de081 100644 --- a/go.sum +++ b/go.sum @@ -60,6 +60,7 @@ github.com/Microsoft/hcsshim v0.8.15/go.mod h1:x38A4YbHbdxJtc0sF6oIz+RG0npwSCAvn github.com/Microsoft/hcsshim v0.8.16/go.mod h1:o5/SZqmR7x9JNKsW3pu+nqHm0MF8vbA+VxGOoXdC600= github.com/Microsoft/hcsshim v0.8.18/go.mod h1:+w2gRZ5ReXQhFOrvSQeNfhrYB/dg3oDwTOcER2fw4I4= github.com/Microsoft/hcsshim v0.9.6 h1:VwnDOgLeoi2du6dAznfmspNqTiwczvjv4K7NxuY9jsY= +github.com/Microsoft/hcsshim v0.9.6/go.mod h1:7pLA8lDk46WKDWlVsENo92gC0XFa8rbKfyFRBqxEbCc= github.com/Microsoft/hcsshim/test v0.0.0-20201218223536-d3e5debf77da/go.mod h1:5hlzMzRKMLyo42nCZ9oml8AdTlq/0cvIaBv6tK1RehU= github.com/Microsoft/hcsshim/test v0.0.0-20210227013316-43a75bb4edd3/go.mod h1:mw7qgWloBUl75W/gVH3cQszUg1+gUITj7D6NY7ywVnY= github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ= @@ -161,6 +162,7 @@ github.com/containerd/continuity v0.0.0-20201208142359-180525291bb7/go.mod h1:kR github.com/containerd/continuity v0.0.0-20210208174643-50096c924a4e/go.mod h1:EXlVlkqNba9rJe3j7w3Xa924itAMLgZH4UD/Q4PExuQ= github.com/containerd/continuity v0.1.0/go.mod h1:ICJu0PwR54nI0yPEnJ6jcS+J7CZAUXrLh8lPo2knzsM= github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg= +github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM= github.com/containerd/fifo v0.0.0-20180307165137-3d5202aec260/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= github.com/containerd/fifo v0.0.0-20190226154929-a9fb20d87448/go.mod h1:ODA38xgv3Kuk8dQz2ZQXpnv/UZZUHUCL7pnLehbXgQI= github.com/containerd/fifo v0.0.0-20200410184934-f15a3290365b/go.mod h1:jPQ2IAeZRCYxpS/Cm1495vGFww6ecHmMk1YJH2Q5ln0= @@ -359,6 +361,7 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= @@ -411,6 +414,7 @@ github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJ github.com/imdario/mergo v0.3.10/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= +github.com/imdario/mergo v0.3.13/go.mod h1:4lJ1jqUDcsbIECGy0RUJAXNIhg+6ocWgb1ALK2O4oXg= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= @@ -603,6 +607,7 @@ github.com/prometheus/procfs v0.9.0 h1:wzCHvIvM5SxWqYvwgVL7yJY8Lz3PKn49KQtpgMYJf github.com/prometheus/procfs v0.9.0/go.mod h1:+pB4zwohETzFnmlpe6yd2lSc+0/46IYZRB/chUwxUZY= github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= +github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= @@ -657,6 +662,7 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/syndtr/gocapability v0.0.0-20170704070218-db04d3cc01c8/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww= @@ -664,6 +670,7 @@ github.com/tchap/go-patricia v2.2.6+incompatible/go.mod h1:bmLyhP68RS6kStMGxByiQ github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tsuru/commandmocker v0.0.0-20160909010208-e1d28f4f616a h1:Z9AGmLYCqZ+o7I/9UqvCF6Tj0DcUv72Hl7CTJ+ONDV4= +github.com/tsuru/commandmocker v0.0.0-20160909010208-e1d28f4f616a/go.mod h1:qIgHCNEogDodrCcRfLe4eWSgm3i5tH++2A8DfoO7gxQ= github.com/tsuru/config v0.0.0-20201023175036-375aaee8b560 h1:fniQ/BmYAHdnNmY333kX4RdVBY+WDAOOs78VEunpY14= github.com/tsuru/config v0.0.0-20201023175036-375aaee8b560/go.mod h1:mj6t8JKWU51GScTT50XRmDj65T5XhTyNvO5FUNV5zS4= github.com/tsuru/gnuflag v0.0.0-20151217162021-86b8c1b864aa h1:JlLQP1xa13a994p/Aau2e3K9xXYaHNoNvTDVIMHSUa4= @@ -810,6 +817,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1030,6 +1038,7 @@ gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2/go.mod h1:Xk6kEKp8OKb+X14hQBKW gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce h1:xcEWjVhvbDy+nHP67nPDDpbYrY+ILlfndk4bRioVHaU= +gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce/go.mod h1:yeKp02qBN3iKW1OzL3MGk2IdtZzaj7SFntXj72NppTA= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= @@ -1047,6 +1056,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= diff --git a/tsuru/admin/app.go b/tsuru/admin/app.go index 33a8c5bb..12a33e76 100644 --- a/tsuru/admin/app.go +++ b/tsuru/admin/app.go @@ -51,7 +51,7 @@ func (c *AppRoutesRebuild) Run(ctx *cmd.Context) error { if err != nil { return err } - rsp, err := tsuruHTTP.DefaultClient.Do(request) + rsp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/admin/event.go b/tsuru/admin/event.go index 26b2428e..6e5b6215 100644 --- a/tsuru/admin/event.go +++ b/tsuru/admin/event.go @@ -53,7 +53,7 @@ func (c *EventBlockList) Run(context *cmd.Context) error { return err } request, _ := http.NewRequest("GET", url, nil) - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -208,7 +208,7 @@ func (c *EventBlockRemove) Run(context *cmd.Context) error { return err } request, _ := http.NewRequest(http.MethodDelete, url, nil) - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/admin/plan.go b/tsuru/admin/plan.go index 2d829b6a..fd351213 100644 --- a/tsuru/admin/plan.go +++ b/tsuru/admin/plan.go @@ -81,7 +81,7 @@ func (c *PlanCreate) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { fmt.Fprintf(context.Stdout, "Failed to create plan!\n") return err @@ -113,7 +113,7 @@ func (c *PlanRemove) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { fmt.Fprintf(context.Stdout, "Failed to remove plan!\n") return err diff --git a/tsuru/admin/platform.go b/tsuru/admin/platform.go index 3b4de3d9..6ea4ee02 100644 --- a/tsuru/admin/platform.go +++ b/tsuru/admin/platform.go @@ -46,7 +46,7 @@ func (p *PlatformList) Run(context *cmd.Context) error { return err } var platforms []platform - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -154,7 +154,7 @@ func (p *PlatformAdd) Run(context *cmd.Context) error { return err } request.Header.Add("Content-Type", writer.FormDataContentType()) - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -251,7 +251,7 @@ func (p *PlatformUpdate) Run(context *cmd.Context) error { return err } request.Header.Add("Content-Type", writer.FormDataContentType()) - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -286,7 +286,7 @@ func (p *PlatformRemove) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { fmt.Fprintf(context.Stdout, "Failed to remove platform!\n") return err diff --git a/tsuru/admin/pool.go b/tsuru/admin/pool.go index 5d68df98..e36e16cc 100644 --- a/tsuru/admin/pool.go +++ b/tsuru/admin/pool.go @@ -275,7 +275,7 @@ func (c *RemovePoolFromSchedulerCmd) Run(ctx *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(req) + _, err = tsuruHTTP.AuthenticatedClient.Do(req) if err != nil { return err } @@ -309,7 +309,7 @@ func (AddTeamsToPoolCmd) Run(ctx *cmd.Context) error { return err } req.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(req) + _, err = tsuruHTTP.AuthenticatedClient.Do(req) if err != nil { return err } @@ -342,7 +342,7 @@ func (RemoveTeamsFromPoolCmd) Run(ctx *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(req) + _, err = tsuruHTTP.AuthenticatedClient.Do(req) if err != nil { return err } @@ -379,7 +379,7 @@ func doRequest(url, method string, body []byte) error { return err } req.Header.Set("Content-Type", "application/json") - _, err = tsuruHTTP.DefaultClient.Do(req) + _, err = tsuruHTTP.AuthenticatedClient.Do(req) return err } @@ -419,7 +419,7 @@ func (c *PoolConstraintList) Run(ctx *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(req) + resp, err := tsuruHTTP.AuthenticatedClient.Do(req) if err != nil { return err } diff --git a/tsuru/admin/quota.go b/tsuru/admin/quota.go index e23575f6..2f43951d 100644 --- a/tsuru/admin/quota.go +++ b/tsuru/admin/quota.go @@ -39,7 +39,7 @@ func (*UserQuotaView) Run(context *cmd.Context) error { return err } request, _ := http.NewRequest("GET", url, nil) - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -81,7 +81,7 @@ func (*UserChangeQuota) Run(context *cmd.Context) error { v.Set("limit", limit) request, _ := http.NewRequest("PUT", u, bytes.NewBufferString(v.Encode())) request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -126,7 +126,7 @@ func (c *AppQuotaView) Run(context *cmd.Context) error { return err } request, _ := http.NewRequest("GET", url, nil) - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -180,7 +180,7 @@ func (c *AppQuotaChange) Run(context *cmd.Context) error { v.Set("limit", limit) request, _ := http.NewRequest("PUT", u, bytes.NewBufferString(v.Encode())) request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -205,7 +205,7 @@ func (*TeamQuotaView) Run(context *cmd.Context) error { return err } request, _ := http.NewRequest("GET", url, nil) - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -247,7 +247,7 @@ func (*TeamChangeQuota) Run(context *cmd.Context) error { v.Set("limit", limit) request, _ := http.NewRequest("PUT", u, bytes.NewBufferString(v.Encode())) request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/admin/services.go b/tsuru/admin/services.go index b6bd9f96..bf13903d 100644 --- a/tsuru/admin/services.go +++ b/tsuru/admin/services.go @@ -75,7 +75,7 @@ func (c *ServiceCreate) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -101,7 +101,7 @@ func (c *ServiceDestroy) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -156,7 +156,7 @@ func (c *ServiceUpdate) Run(ctx *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -195,7 +195,7 @@ func (c *ServiceDocAdd) Run(ctx *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -215,7 +215,7 @@ func (c *ServiceDocGet) Run(ctx *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/admin/suite_test.go b/tsuru/admin/suite_test.go index 3e737b13..b38f7e9b 100644 --- a/tsuru/admin/suite_test.go +++ b/tsuru/admin/suite_test.go @@ -43,11 +43,11 @@ func (s *S) SetUpTest(c *check.C) { func (s *S) TearDownTest(c *check.C) { formatter.LocalTZ = &s.defaultLocation - tsuruHTTP.DefaultClient = &http.Client{} + tsuruHTTP.AuthenticatedClient = &http.Client{} } func (s *S) setupFakeTransport(rt http.RoundTripper) { - tsuruHTTP.DefaultClient = tsuruHTTP.NewTerminalClient(rt, nil, "test", "0.1.0", 0) + tsuruHTTP.AuthenticatedClient = tsuruHTTP.NewTerminalClient(rt, nil, "test", "0.1.0", 0) } var _ = check.Suite(&S{}) diff --git a/tsuru/auth/open.go b/tsuru/auth/open.go index 3f05d409..4d477032 100644 --- a/tsuru/auth/open.go +++ b/tsuru/auth/open.go @@ -42,3 +42,12 @@ func open(url string) error { } return executor().Execute(opts) } + +var execut exec.Executor + +func executor() exec.Executor { + if execut == nil { + execut = exec.OsExecutor{} + } + return execut +} diff --git a/tsuru/auth/open_windows.go b/tsuru/auth/open_windows.go index 4f005966..51c59345 100644 --- a/tsuru/auth/open_windows.go +++ b/tsuru/auth/open_windows.go @@ -19,3 +19,12 @@ func open(url string) error { } return executor().Execute(opts) } + +var execut exec.Executor + +func executor() exec.Executor { + if execut == nil { + execut = exec.OsExecutor{} + } + return execut +} diff --git a/tsuru/client/apps.go b/tsuru/client/apps.go index 13e90ee4..144f4da0 100644 --- a/tsuru/client/apps.go +++ b/tsuru/client/apps.go @@ -197,7 +197,7 @@ func (c *AppCreate) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -370,7 +370,7 @@ func (c *AppRemove) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -431,7 +431,7 @@ func (c *AppInfo) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1210,7 +1210,7 @@ func (c *AppGrant) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1249,7 +1249,7 @@ func (c *AppRevoke) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1340,7 +1340,7 @@ func (c *AppList) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1480,7 +1480,7 @@ func (c *AppStop) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1532,7 +1532,7 @@ func (c *AppStart) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1575,7 +1575,7 @@ func (c *AppRestart) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1668,7 +1668,7 @@ func unsetCName(cnames []string, g tsuruClientApp.AppNameMixIn) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) return err } @@ -1691,7 +1691,7 @@ func addCName(cnames []string, g tsuruClientApp.AppNameMixIn) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) return err } diff --git a/tsuru/client/auth.go b/tsuru/client/auth.go index 01ce9b1f..875449c2 100644 --- a/tsuru/client/auth.go +++ b/tsuru/client/auth.go @@ -68,7 +68,7 @@ func (c *UserCreate) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if resp != nil { if resp.StatusCode == http.StatusNotFound || resp.StatusCode == http.StatusMethodNotAllowed { @@ -97,7 +97,7 @@ func (c *UserRemove) currentUserEmail() (string, error) { return "", err } request, _ := http.NewRequest("GET", u, nil) - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return "", err } @@ -142,7 +142,7 @@ func (c *UserRemove) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -411,7 +411,7 @@ func (c *TeamInfo) Run(ctx *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -526,7 +526,7 @@ func (c *ChangePassword) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -588,7 +588,7 @@ func (c *ResetPassword) Run(context *cmd.Context) error { return err } request, _ := http.NewRequest("POST", url, nil) - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -634,7 +634,7 @@ func (c *ShowAPIToken) Run(context *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -692,7 +692,7 @@ func (c *RegenerateAPIToken) Run(context *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/build.go b/tsuru/client/build.go index 6de6cf26..7dd597fc 100644 --- a/tsuru/client/build.go +++ b/tsuru/client/build.go @@ -90,7 +90,7 @@ func (c *AppBuild) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -117,7 +117,7 @@ func (c *AppBuild) Run(context *cmd.Context) error { if err = uploadFiles(context, request, buf, body, values, &archive); err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/certificate.go b/tsuru/client/certificate.go index 5bd5d33a..db8ec03f 100644 --- a/tsuru/client/certificate.go +++ b/tsuru/client/certificate.go @@ -80,7 +80,7 @@ func (c *CertificateSet) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -132,7 +132,7 @@ func (c *CertificateUnset) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -180,7 +180,7 @@ func (c *CertificateList) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/deploy.go b/tsuru/client/deploy.go index b0bffd90..3c3de9b4 100644 --- a/tsuru/client/deploy.go +++ b/tsuru/client/deploy.go @@ -83,7 +83,7 @@ func (c *AppDeployList) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -309,7 +309,7 @@ func (c *AppDeploy) Run(context *cmd.Context) error { } c.m.Lock() - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { c.m.Unlock() return err @@ -430,7 +430,7 @@ func (c *AppDeployRollback) Run(context *cmd.Context) error { return err } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -480,7 +480,7 @@ func (c *AppDeployRebuild) Run(context *cmd.Context) error { return err } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -550,7 +550,7 @@ func (c *AppDeployRollbackUpdate) Run(context *cmd.Context) error { return err } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) return err } diff --git a/tsuru/client/env.go b/tsuru/client/env.go index b697994f..2ea863a6 100644 --- a/tsuru/client/env.go +++ b/tsuru/client/env.go @@ -201,7 +201,7 @@ func (c *EnvSet) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -285,7 +285,7 @@ func (c *EnvUnset) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -316,7 +316,7 @@ func requestEnvGetURL(c *EnvGet, args []string) ([]byte, error) { if err != nil { return nil, err } - r, err := tsuruHTTP.DefaultClient.Do(request) + r, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return nil, err } diff --git a/tsuru/client/event.go b/tsuru/client/event.go index c08a6181..b21f452a 100644 --- a/tsuru/client/event.go +++ b/tsuru/client/event.go @@ -112,7 +112,7 @@ func (c *EventList) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -233,7 +233,7 @@ func (c *EventInfo) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -444,7 +444,7 @@ func (c *EventCancel) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/log.go b/tsuru/client/log.go index 6b5cb99f..6c63cbf9 100644 --- a/tsuru/client/log.go +++ b/tsuru/client/log.go @@ -138,7 +138,7 @@ func (c *AppLog) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/permission.go b/tsuru/client/permission.go index bec6d69f..275143c4 100644 --- a/tsuru/client/permission.go +++ b/tsuru/client/permission.go @@ -60,7 +60,7 @@ func (c *PermissionList) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -169,7 +169,7 @@ func (c *RoleInfo) Run(context *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -246,7 +246,7 @@ func (c *RoleAdd) Run(context *cmd.Context) error { return err } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -274,7 +274,7 @@ func (c *RoleList) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -323,7 +323,7 @@ func (c *RolePermissionAdd) Run(context *cmd.Context) error { return err } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -353,7 +353,7 @@ func (c *RolePermissionRemove) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -404,7 +404,7 @@ func (c *RoleAssign) Run(context *cmd.Context) error { return err } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -449,7 +449,7 @@ func (c *RoleDissociate) Run(context *cmd.Context) error { return err } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -483,7 +483,7 @@ func (c *RoleRemove) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -543,7 +543,7 @@ func (c *RoleDefaultAdd) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -602,7 +602,7 @@ func (c *RoleDefaultRemove) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -629,7 +629,7 @@ func (c *RoleDefaultList) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -716,7 +716,7 @@ func (c *RoleUpdate) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { context.Stderr.Write([]byte("Failed to update role\n")) return err diff --git a/tsuru/client/plan.go b/tsuru/client/plan.go index a7e6b681..d3466b4d 100644 --- a/tsuru/client/plan.go +++ b/tsuru/client/plan.go @@ -262,7 +262,7 @@ func (c *PlanList) Run(context *cmd.Context) error { return err } var plans []apptypes.Plan - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/pool.go b/tsuru/client/pool.go index bc05e1cf..a46d184e 100644 --- a/tsuru/client/pool.go +++ b/tsuru/client/pool.go @@ -92,7 +92,7 @@ func (pl *PoolList) Run(context *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/router.go b/tsuru/client/router.go index c894d7bc..b134f339 100644 --- a/tsuru/client/router.go +++ b/tsuru/client/router.go @@ -343,7 +343,7 @@ func (c *AppRoutersList) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -447,7 +447,7 @@ func (c *AppRoutersAdd) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -504,7 +504,7 @@ func (c *AppRoutersUpdate) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -539,7 +539,7 @@ func (c *AppRoutersRemove) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/run.go b/tsuru/client/run.go index 292f7472..806be716 100644 --- a/tsuru/client/run.go +++ b/tsuru/client/run.go @@ -61,7 +61,7 @@ func (c *AppRun) Run(context *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - r, err := tsuruHTTP.DefaultClient.Do(request) + r, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/services.go b/tsuru/client/services.go index 0e441a37..3456ce08 100644 --- a/tsuru/client/services.go +++ b/tsuru/client/services.go @@ -106,7 +106,7 @@ func (s ServiceList) Run(ctx *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(req) + resp, err := tsuruHTTP.AuthenticatedClient.Do(req) if err != nil { return err } @@ -290,7 +290,7 @@ func (c *ServiceInstanceAdd) Run(ctx *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -465,7 +465,7 @@ func (sb *ServiceInstanceBind) Run(ctx *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -538,7 +538,7 @@ func (su *ServiceInstanceUnbind) Run(ctx *cmd.Context) error { query.Set("noRestart", strconv.FormatBool(su.noRestart)) query.Set("force", strconv.FormatBool(su.force)) request.URL.RawQuery = query.Encode() - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -620,7 +620,7 @@ func (c ServiceInstanceInfo) Run(ctx *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -642,7 +642,7 @@ func (c ServiceInstanceInfo) Run(ctx *cmd.Context) error { if err != nil { return err } - resp, err = tsuruHTTP.DefaultClient.Do(request) + resp, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1010,7 +1010,7 @@ func (c *ServiceInfo) WriteDoc(ctx *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1069,7 +1069,7 @@ func (c *ServiceInfo) fetchInstances(serviceName string) ([]ServiceInstanceModel if err != nil { return nil, err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return nil, err } @@ -1103,7 +1103,7 @@ func (c *ServiceInfo) fetchPlans(serviceName string) ([]plan, error) { if err != nil { return nil, err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return nil, err } @@ -1160,7 +1160,7 @@ func (c *ServiceInstanceRemove) Run(ctx *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1201,7 +1201,7 @@ func (c *ServiceInstanceGrant) Run(ctx *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -1233,7 +1233,7 @@ func (c *ServiceInstanceRevoke) Run(ctx *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/shell.go b/tsuru/client/shell.go index aea44bb5..f8761cfe 100644 --- a/tsuru/client/shell.go +++ b/tsuru/client/shell.go @@ -70,7 +70,7 @@ func (c *ShellToContainerCmd) Run(context *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/suite_test.go b/tsuru/client/suite_test.go index 074a0430..efc91d35 100644 --- a/tsuru/client/suite_test.go +++ b/tsuru/client/suite_test.go @@ -54,5 +54,5 @@ func Test(t *testing.T) { } func (s *S) setupFakeTransport(rt http.RoundTripper) { - tsuruHTTP.DefaultClient = tsuruHTTP.NewTerminalClient(rt, nil, "test", "0.1.0", 0) + tsuruHTTP.AuthenticatedClient = tsuruHTTP.NewTerminalClient(rt, nil, "test", "0.1.0", 0) } diff --git a/tsuru/client/swap.go b/tsuru/client/swap.go index a05f724f..49372ac1 100644 --- a/tsuru/client/swap.go +++ b/tsuru/client/swap.go @@ -97,6 +97,6 @@ func makeSwap(url string, body io.Reader) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) return err } diff --git a/tsuru/client/tag.go b/tsuru/client/tag.go index 563491ec..4f32377c 100644 --- a/tsuru/client/tag.go +++ b/tsuru/client/tag.go @@ -100,7 +100,7 @@ func getFromURL(path string) ([]byte, error) { if err != nil { return nil, err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return nil, err } diff --git a/tsuru/client/unit.go b/tsuru/client/unit.go index 2ea53a17..789ccd41 100644 --- a/tsuru/client/unit.go +++ b/tsuru/client/unit.go @@ -67,7 +67,7 @@ func (c *UnitAdd) Run(context *cmd.Context) error { return err } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -120,7 +120,7 @@ func (c *UnitRemove) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -181,7 +181,7 @@ func (c *UnitKill) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -230,7 +230,7 @@ func (c *UnitSet) Run(context *cmd.Context) error { if err != nil { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -302,7 +302,7 @@ func (c *UnitSet) Run(context *cmd.Context) error { } request.Header.Add("Content-Type", "application/x-www-form-urlencoded") - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -327,7 +327,7 @@ func (c *UnitSet) Run(context *cmd.Context) error { return err } - response, err := tsuruHTTP.DefaultClient.Do(request) + response, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/client/volume.go b/tsuru/client/volume.go index 1cd1b55c..0a482440 100644 --- a/tsuru/client/volume.go +++ b/tsuru/client/volume.go @@ -80,7 +80,7 @@ func (c *VolumeCreate) Run(ctx *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -144,7 +144,7 @@ func (c *VolumeUpdate) Run(ctx *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -225,7 +225,7 @@ func (c *VolumeList) Run(ctx *cmd.Context) error { if err != nil { return err } - rsp, err := tsuruHTTP.DefaultClient.Do(request) + rsp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -337,7 +337,7 @@ func (c *VolumeInfo) Run(ctx *cmd.Context) error { if err != nil { return err } - rsp, err := tsuruHTTP.DefaultClient.Do(request) + rsp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -424,7 +424,7 @@ func (c *VolumePlansList) Run(ctx *cmd.Context) error { if err != nil { return err } - rsp, err := tsuruHTTP.DefaultClient.Do(request) + rsp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -488,7 +488,7 @@ func (c *VolumeDelete) Run(ctx *cmd.Context) error { if err != nil { return err } - _, err = tsuruHTTP.DefaultClient.Do(request) + _, err = tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -556,7 +556,7 @@ func (c *VolumeBind) Run(ctx *cmd.Context) error { return err } request.Header.Set("Content-Type", "application/x-www-form-urlencoded") - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } @@ -620,7 +620,7 @@ func (c *VolumeUnbind) Run(ctx *cmd.Context) error { if err != nil { return err } - resp, err := tsuruHTTP.DefaultClient.Do(request) + resp, err := tsuruHTTP.AuthenticatedClient.Do(request) if err != nil { return err } diff --git a/tsuru/http/client.go b/tsuru/http/client.go index c9f713b3..960c5e4c 100644 --- a/tsuru/http/client.go +++ b/tsuru/http/client.go @@ -14,7 +14,7 @@ import ( "github.com/tsuru/tsuru/cmd" ) -var DefaultClient = &http.Client{} +var AuthenticatedClient = &http.Client{} func NewTerminalClient(rt http.RoundTripper, context *cmd.Context, clientName, clientVersion string, verbosity int) *http.Client { stdout := io.Discard @@ -42,18 +42,14 @@ func NewTerminalClient(rt http.RoundTripper, context *cmd.Context, clientName, c func TsuruClientFromEnvironment() (*tsuru.APIClient, error) { cfg := &tsuru.Configuration{ - HTTPClient: DefaultClient, + HTTPClient: AuthenticatedClient, + DefaultHeader: map[string]string{}, } var err error - if cfg.BasePath == "" { - cfg.BasePath, err = config.GetTarget() - if err != nil { - return nil, err - } - } - if cfg.DefaultHeader == nil { - cfg.DefaultHeader = map[string]string{} + cfg.BasePath, err = config.GetTarget() + if err != nil { + return nil, err } if _, authSet := cfg.DefaultHeader["Authorization"]; !authSet {