diff --git a/tsuru/client/env.go b/tsuru/client/env.go index 69fe3f11..5bef989e 100644 --- a/tsuru/client/env.go +++ b/tsuru/client/env.go @@ -20,7 +20,6 @@ import ( "github.com/tsuru/go-tsuruclient/pkg/config" "github.com/tsuru/tsuru-client/tsuru/formatter" tsuruHTTP "github.com/tsuru/tsuru-client/tsuru/http" - tsuruAPIApp "github.com/tsuru/tsuru/app" "github.com/tsuru/tsuru/cmd" apiTypes "github.com/tsuru/tsuru/types/api" ) @@ -96,10 +95,18 @@ func (c *EnvGet) Run(context *cmd.Context) error { formatted := make([]string, 0, len(variables)) for _, v := range variables { - value := tsuruAPIApp.SuppressedEnv - if v["public"].(bool) { - value = v["value"].(string) + value := v["value"].(string) + public := v["public"].(bool) + managedBy, _ := v["managedBy"].(string) + + if public && managedBy != "" { + value = fmt.Sprintf("%s (managed by %s)", value, managedBy) + } else if !public && managedBy != "" { + value = fmt.Sprintf("*** (private variable managed by %s)", managedBy) + } else if !public { + value = "*** (private variable)" } + formatted = append(formatted, fmt.Sprintf("%s=%s", v["name"], value)) } sort.Strings(formatted) @@ -109,24 +116,27 @@ func (c *EnvGet) Run(context *cmd.Context) error { func (c *EnvGet) renderJSON(context *cmd.Context, variables []map[string]interface{}) error { type envJSON struct { - Name string `json:"name"` - Value string `json:"value"` - Private bool `json:"private"` + Name string `json:"name"` + Value string `json:"value"` + Private bool `json:"private"` + ManagedBy string `json:"managedBy,omitempty"` } data := make([]envJSON, 0, len(variables)) for _, v := range variables { private := true - value := tsuruAPIApp.SuppressedEnv + value := "*** (private variable)" if v["public"].(bool) { value = v["value"].(string) private = false } + managedBy, _ := v["managedBy"].(string) data = append(data, envJSON{ - Name: v["name"].(string), - Value: value, - Private: private, + Name: v["name"].(string), + Value: value, + Private: private, + ManagedBy: managedBy, }) } diff --git a/tsuru/client/env_test.go b/tsuru/client/env_test.go index 5318ac94..d415d1d8 100644 --- a/tsuru/client/env_test.go +++ b/tsuru/client/env_test.go @@ -103,6 +103,24 @@ func (s *S) TestEnvGetPrivateVariables(c *check.C) { c.Assert(stdout.String(), check.Equals, result) } +func (s *S) TestEnvGetManagedByVariables(c *check.C) { + var stdout, stderr bytes.Buffer + jsonResult := `[{"name": "DATABASE_USER", "value": "someuser", "public": false, "managedBy": "my-service/instance"}, {"name": "DATABASE_HOST", "value": "somehost", "public": true, "managedBy": "my-service/instance"}]` + result := "DATABASE_HOST=somehost (managed by my-service/instance)\nDATABASE_USER=*** (private variable managed by my-service/instance)\n" + params := []string{"DATABASE_HOST", "DATABASE_USER"} + context := cmd.Context{ + Args: params, + Stdout: &stdout, + Stderr: &stderr, + } + s.setupFakeTransport(&cmdtest.Transport{Message: jsonResult, Status: http.StatusOK}) + command := EnvGet{} + command.Flags().Parse(true, []string{"-a", "someapp"}) + err := command.Run(&context) + c.Assert(err, check.IsNil) + c.Assert(stdout.String(), check.Equals, result) +} + func (s *S) TestEnvGetWithoutTheFlag(c *check.C) { var stdout, stderr bytes.Buffer jsonResult := `[{"name": "DATABASE_HOST", "value": "somehost", "public": true}, {"name": "DATABASE_USER", "value": "someuser", "public": true}]`