Skip to content

Commit

Permalink
Merge pull request #49 from tsuru/team-update
Browse files Browse the repository at this point in the history
Team update
  • Loading branch information
ggarnier committed Aug 17, 2017
2 parents 79caf0f + d9e02d9 commit 899fa8e
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 4 deletions.
4 changes: 4 additions & 0 deletions docs/cmds.json
Expand Up @@ -163,6 +163,10 @@
"usage": "tsuru unit-add <# of units> [-a/--app appname] [-p/--process processname]",
"desc": "Adds new units to a process of an application. You need to have access to the\napp to be able to add new units to it.\n\nFlags:\n \n -a, --app (= \"\")\n The name of the app.\n -p, --process (= \"\")\n Process name\n \nMinimum # of arguments: 1\n"
},
"team-update": {
"usage": "tsuru team-update <team-name> -n <new-team-name>",
"desc": "Updates a team name.\n\nFlags:\n \n -n, --name (= \"\")\n New team name.\n \nMinimum # of arguments: 1\nMaximum # of arguments: 1\n"
},
"bs-info": {
"usage": "tsuru bs-info",
"desc": "This command was removed. You should use `tsuru node-container-info big-sibling` instead.\n\n"
Expand Down
4 changes: 3 additions & 1 deletion docs/source/reference.rst
Expand Up @@ -49,8 +49,10 @@ Team management

.. tsuru-command:: team-create
:title: Create a new team
.. tsuru-command:: team-update
:title: Update a team
.. tsuru-command:: team-remove
:title: Remove a team from tsuru
:title: Remove a team
.. tsuru-command:: team-list
:title: List teams current user is member

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,3 +1,3 @@
Sphinx==1.2.2
sphinx-rtd-theme==0.1.6
tsuru-sphinx==0.1.3
tsuru-sphinx==0.1.4
47 changes: 47 additions & 0 deletions tsuru/client/auth.go
Expand Up @@ -182,6 +182,53 @@ func (c *TeamCreate) Run(context *cmd.Context, client *cmd.Client) error {
return nil
}

type TeamUpdate struct {
newName string
fs *gnuflag.FlagSet
}

func (t *TeamUpdate) Flags() *gnuflag.FlagSet {
if t.fs == nil {
t.fs = gnuflag.NewFlagSet("team-update", gnuflag.ExitOnError)
desc := "New team name."
t.fs.StringVar(&t.newName, "name", "", desc)
t.fs.StringVar(&t.newName, "n", "", desc)
}
return t.fs
}

func (t *TeamUpdate) Info() *cmd.Info {
return &cmd.Info{
Name: "team-update",
Usage: "team-update <team-name> -n <new-team-name>",
Desc: `Updates a team name.`,
MinArgs: 1,
MaxArgs: 1,
}
}

func (t *TeamUpdate) Run(context *cmd.Context, client *cmd.Client) error {
name := context.Args[0]
v := url.Values{}
v.Set("newname", t.newName)
b := strings.NewReader(v.Encode())
u, err := cmd.GetURLVersion("1.4", fmt.Sprintf("/teams/%s", name))
if err != nil {
return err
}
request, err := http.NewRequest("POST", u, b)
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
_, err = client.Do(request)
if err != nil {
return err
}
fmt.Fprintln(context.Stdout, "Team successfully updated!")
return nil
}

type TeamRemove struct {
cmd.ConfirmationCommand
}
Expand Down
44 changes: 44 additions & 0 deletions tsuru/client/auth_test.go
Expand Up @@ -51,6 +51,50 @@ func (s *S) TestTeamCreateInfo(c *check.C) {
c.Assert((&TeamCreate{}).Info(), check.NotNil)
}

func (s *S) TestTeamUpdate(c *check.C) {
var stdout, stderr bytes.Buffer
ctx := cmd.Context{
Args: []string{"my-team"},
Stdout: &stdout,
Stderr: &stderr,
}
trans := &cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: "", Status: http.StatusOK},
CondFunc: func(r *http.Request) bool {
c.Assert(r.FormValue("newname"), check.Equals, "new-team")
c.Assert(strings.HasSuffix(r.URL.Path, "/teams/my-team"), check.Equals, true)
c.Assert(r.Method, check.Equals, http.MethodPost)
return true
},
}
client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
command := &TeamUpdate{}
command.Flags().Parse(true, []string{"-n", "new-team"})
err := command.Run(&ctx, client)
c.Assert(err, check.IsNil)
result := stdout.String()
c.Assert(result, check.Equals, "Team successfully updated!\n")
}

func (s *S) TestTeamUpdateError(c *check.C) {
var stdout, stderr bytes.Buffer
ctx := cmd.Context{
Args: []string{"my-team"},
Stdout: &stdout,
Stderr: &stderr,
}
errMsg := "team not found"
trans := &cmdtest.Transport{Message: errMsg, Status: http.StatusNotFound}
client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)
command := &TeamUpdate{}
err := command.Run(&ctx, client)
c.Assert(err, check.ErrorMatches, errMsg)
}

func (s *S) TestTeamUpdateInfo(c *check.C) {
c.Assert((&TeamUpdate{}).Info(), check.NotNil)
}

func (s *S) TestTeamRemove(c *check.C) {
var (
buf bytes.Buffer
Expand Down
2 changes: 1 addition & 1 deletion tsuru/client/permission.go
Expand Up @@ -39,7 +39,7 @@ func (c *PermissionList) Info() *cmd.Info {

func (c *PermissionList) Flags() *gnuflag.FlagSet {
if c.fs == nil {
c.fs = gnuflag.NewFlagSet("plan-List", gnuflag.ExitOnError)
c.fs = gnuflag.NewFlagSet("permission-list", gnuflag.ExitOnError)
tree := "Show permissions in tree format."
c.fs.BoolVar(&c.tree, "tree", false, tree)
c.fs.BoolVar(&c.tree, "t", false, tree)
Expand Down
2 changes: 1 addition & 1 deletion tsuru/client/plan.go
Expand Up @@ -22,7 +22,7 @@ type PlanList struct {

func (c *PlanList) Flags() *gnuflag.FlagSet {
if c.fs == nil {
c.fs = gnuflag.NewFlagSet("plan-List", gnuflag.ExitOnError)
c.fs = gnuflag.NewFlagSet("plan-list", gnuflag.ExitOnError)
bytes := "bytesized units for memory and swap."
c.fs.BoolVar(&c.bytes, "bytes", false, bytes)
c.fs.BoolVar(&c.bytes, "b", false, bytes)
Expand Down
1 change: 1 addition & 0 deletions tsuru/main.go
Expand Up @@ -79,6 +79,7 @@ func buildManager(name string) *cmd.Manager {
m.Register(&client.UserRemove{})
m.Register(&client.ListUsers{})
m.Register(&client.TeamCreate{})
m.Register(&client.TeamUpdate{})
m.Register(&client.TeamRemove{})
m.Register(&client.TeamList{})
m.Register(&client.ChangePassword{})
Expand Down

0 comments on commit 899fa8e

Please sign in to comment.