Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: form to json review #163

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5f50292
change: form to json
CarlosRoGuerra Jun 9, 2021
ced8e54
change: form to json
CarlosRoGuerra Jun 14, 2021
8371153
change: form to json
CarlosRoGuerra Jun 21, 2021
f1631ea
change: form to json
CarlosRoGuerra Jun 22, 2021
44a5f3e
change: form to json
CarlosRoGuerra Jun 24, 2021
e64ca58
change:form to json-> appStart,appStop,appRestart in apps.go, volumeU…
CarlosRoGuerra Jul 8, 2021
898957a
change: Use json.NewDescoder in tsuru client tests
CarlosRoGuerra Jul 13, 2021
cbcc43e
fix:volumeUpdate in volume.go;Add: ServiceInstanceUpdate to json
CarlosRoGuerra Jul 26, 2021
e70f3c0
fix:volumeUpdate in volume.go;Add: ServiceInstanceUpdate to json
CarlosRoGuerra Jul 26, 2021
06f0328
fix:volumeUpdate in volume.go;Add: ServiceInstanceUpdate to json
CarlosRoGuerra Jul 26, 2021
1427bf6
fix:volumeUpdate in volume.go;Add: ServiceInstanceUpdate to json
CarlosRoGuerra Jul 26, 2021
0ff04cd
change:var name changePassword to changedPassword in auth.go
CarlosRoGuerra Jul 27, 2021
b4cfeb8
Merge branch 'tsuru:master' into master
CarlosRoGuerra Aug 2, 2021
147ae47
change form to json
CarlosRoGuerra Aug 3, 2021
8a4b8af
change form to json
CarlosRoGuerra Aug 3, 2021
792f0ee
change form to json
CarlosRoGuerra Aug 3, 2021
24d08e5
change form to json
CarlosRoGuerra Aug 3, 2021
698f07f
add: certificate and permission to client
CarlosRoGuerra Aug 13, 2021
93fd277
add: certificate and permission to client
CarlosRoGuerra Aug 13, 2021
8d5a611
refactor: form to json
CarlosRoGuerra Oct 19, 2021
811c43b
refactor: json to form
CarlosRoGuerra Oct 20, 2021
6e2b5e4
Merge branch 'master' into refactor-json
CarlosRoGuerra Oct 20, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ require (
github.com/ajg/form v0.0.0-20160822230020-523a5da1a92f
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6
github.com/digitalocean/godo v1.1.1 // indirect
github.com/docker/docker v20.10.8+incompatible
github.com/docker/distribution v2.7.1+incompatible // indirect
github.com/docker/docker v20.10.9+incompatible
github.com/docker/go-connections v0.4.0
github.com/docker/machine v0.16.1
github.com/exoscale/egoscale v0.9.31 // indirect
Expand All @@ -18,13 +19,16 @@ require (
github.com/sethvargo/go-password v0.1.1
github.com/tsuru/config v0.0.0-20201023175036-375aaee8b560
github.com/tsuru/gnuflag v0.0.0-20151217162021-86b8c1b864aa
github.com/tsuru/go-tsuruclient v0.0.0-20210426181646-b7774d33597a
github.com/tsuru/go-tsuruclient v0.0.0-20210820124232-e0cdf446d41d
github.com/tsuru/tablecli v0.0.0-20190131152944-7ded8a3383c6
github.com/tsuru/tsuru v0.0.0-20210831124236-38cab1d28262
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2
github.com/tsuru/tsuru v0.0.0-20210706143918-b89a484dc93f
golang.org/x/crypto v0.0.0-20201012173705-84dcc777aaee
google.golang.org/api v0.7.0 // indirect
google.golang.org/appengine v1.6.1 // indirect
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.20.6
k8s.io/apimachinery v0.18.9
k8s.io/client-go v11.0.1-0.20190805182715-88a2adca7e76+incompatible // indirect
)

replace (
Expand Down
979 changes: 122 additions & 857 deletions go.sum

Large diffs are not rendered by default.

Binary file added tsuru/.DS_Store
Binary file not shown.
46 changes: 2 additions & 44 deletions tsuru/admin/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ type ClusterAdd struct {
addresses cmd.StringSliceFlag
pools cmd.StringSliceFlag
customData cmd.MapFlag
createData cmd.MapFlag
isDefault bool
}

Expand All @@ -51,16 +50,14 @@ func (c *ClusterAdd) Flags() *gnuflag.FlagSet {
c.fs.Var(&c.pools, "pool", desc)
desc = "Custom provisioner specific data."
c.fs.Var(&c.customData, "custom", desc)
desc = "Create data, if set an iaas will be called with this data to create a new machine."
c.fs.Var(&c.createData, "create-data", desc)
}
return c.fs
}

func (c *ClusterAdd) Info() *cmd.Info {
return &cmd.Info{
Name: "cluster-add",
Usage: "cluster add <name> <provisioner> [--addr address...] [--pool poolname]... [--cacert cacertfile] [--clientcert clientcertfile] [--clientkey clientkeyfile] [--custom key=value]... [--create-data key=value]... [--default]",
Usage: "cluster add <name> <provisioner> [--addr address...] [--pool poolname]... [--cacert cacertfile] [--clientcert clientcertfile] [--clientkey clientkeyfile] [--custom key=value]... [--default]",
Desc: `Creates a provisioner cluster definition.`,
MinArgs: 2,
MaxArgs: 2,
Expand All @@ -84,7 +81,6 @@ func (c *ClusterAdd) Run(ctx *cmd.Context, cli *cmd.Client) error {
CustomData: c.customData,
Default: c.isDefault,
Provisioner: provisioner,
CreateData: c.createData,
}
var data []byte
if c.cacert != "" {
Expand Down Expand Up @@ -134,8 +130,6 @@ type ClusterUpdate struct {
removePool cmd.StringSliceFlag
addCustomData cmd.MapFlag
removeCustomData cmd.StringSliceFlag
addCreateData cmd.MapFlag
removeCreateData cmd.StringSliceFlag
}

func (c *ClusterUpdate) Flags() *gnuflag.FlagSet {
Expand Down Expand Up @@ -165,18 +159,14 @@ func (c *ClusterUpdate) Flags() *gnuflag.FlagSet {
c.fs.Var(&c.addCustomData, "add-custom", desc)
desc = "Remove custom provisioner specific data."
c.fs.Var(&c.removeCustomData, "remove-custom", desc)
desc = "Create data, if set an iaas will be called with this data to re-create the machine."
c.fs.Var(&c.addCreateData, "add-create-data", desc)
desc = "Remove create data"
c.fs.Var(&c.removeCreateData, "remove-create-data", desc)
}
return c.fs
}

func (c *ClusterUpdate) Info() *cmd.Info {
return &cmd.Info{
Name: "cluster-update",
Usage: "cluster update <name> <provisioner> [--addr address]... [--add-pool poolname]... [--remove-pool poolname]... [--cacert cacertfile] [--remove-cacert] [--clientcert clientcertfile] [--remove-clientcert] [--clientkey clientkeyfile] [--remove-clientkey] [--add-custom key=value]... [--remove-custom key]... [--add-create-data key=value]... [--remove-create-data key]... [--default=true|false]",
Usage: "cluster update <name> <provisioner> [--addr address]... [--add-pool poolname]... [--remove-pool poolname]... [--cacert cacertfile] [--remove-cacert] [--clientcert clientcertfile] [--remove-clientcert] [--clientkey clientkeyfile] [--remove-clientkey] [--add-custom key=value]... [--remove-custom key]... [--default=true|false]",
Desc: `Updates a provisioner cluster definition.`,
MinArgs: 2,
MaxArgs: 2,
Expand Down Expand Up @@ -223,9 +213,6 @@ func (c *ClusterUpdate) mergeCluster(cluster *tsuru.Cluster) error {
if err := c.updateClientKey(cluster); err != nil {
return err
}
if err := c.updateCreateData(cluster); err != nil {
return err
}
if err := c.updateCustomData(cluster); err != nil {
return err
}
Expand Down Expand Up @@ -313,26 +300,6 @@ func (c *ClusterUpdate) updateCustomData(cluster *tsuru.Cluster) error {
}
return nil
}

func (c *ClusterUpdate) updateCreateData(cluster *tsuru.Cluster) error {
if cluster == nil {
return fmt.Errorf("cannot update a nil cluster")
}
if cluster.CreateData == nil {
cluster.CreateData = make(map[string]string)
}
for key, value := range c.addCreateData {
cluster.CreateData[key] = value
}
for _, key := range c.removeCreateData {
if _, hasKey := cluster.CreateData[key]; !hasKey {
return fmt.Errorf("cannot unset create data entry: key %q not found", key)
}
delete(cluster.CreateData, key)
}
return nil
}

func (c *ClusterUpdate) updatePools(cluster *tsuru.Cluster) error {
if cluster == nil {
return fmt.Errorf("cannot update a nil cluster")
Expand Down Expand Up @@ -534,15 +501,6 @@ func (c *ProvisionerInfo) Run(ctx *cmd.Context, cli *cmd.Client) error {
tbl.Sort()
fmt.Fprint(ctx.Stdout, tbl.String())

fmt.Fprintf(ctx.Stdout, "\nCreate Data:\n")
tbl = tablecli.NewTable()
tbl.LineSeparator = true
tbl.Headers = tablecli.Row{"Name", "Usage"}
for key, value := range provisioner.ClusterHelp.CreateDataHelp {
tbl.AddRow(tablecli.Row{key, value})
}
tbl.Sort()
fmt.Fprint(ctx.Stdout, tbl.String())
return nil
}

Expand Down
24 changes: 1 addition & 23 deletions tsuru/admin/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func (s *S) TestClusterAddRun(c *check.C) {
Pools: []string{"p1", "p2"},
Default: true,
Provisioner: "myprov",
CreateData: map[string]string{"iaas": "dockermachine"},
})
return true
},
Expand All @@ -76,7 +75,7 @@ func (s *S) TestClusterAddRun(c *check.C) {
"--pool", "p2",
"--custom", "a=b",
"--custom", "c=d",
"--create-data", "iaas=dockermachine",
"iaas=dockermachine",
"--default",
})
c.Assert(err, check.IsNil)
Expand Down Expand Up @@ -199,7 +198,6 @@ func (s *S) TestClusterUpdateMergeCluster(c *check.C) {
Clientkey: []byte("client key"),
Pools: []string{"pool1", "pool2"},
CustomData: map[string]string{"key": "value"},
CreateData: map[string]string{"key": "value"},
Default: false,
}
}
Expand Down Expand Up @@ -241,13 +239,6 @@ func (s *S) TestClusterUpdateMergeCluster(c *check.C) {
cluster: getCluster(),
errorString: "cannot unset custom data entry: key \"some-not-found-key\" not found",
},
{
command: ClusterUpdate{
removeCreateData: cmd.StringSliceFlag{"some-not-found-key"},
},
cluster: getCluster(),
errorString: "cannot unset create data entry: key \"some-not-found-key\" not found",
},
{
command: ClusterUpdate{
isDefault: "true",
Expand Down Expand Up @@ -281,7 +272,6 @@ func (s *S) TestClusterUpdateMergeCluster(c *check.C) {
Clientkey: []byte("client key"),
Pools: []string{"pool1", "pool2"},
CustomData: map[string]string{"key": "value"},
CreateData: map[string]string{"key": "value"},
Default: false,
},
},
Expand All @@ -299,7 +289,6 @@ func (s *S) TestClusterUpdateMergeCluster(c *check.C) {
Clientkey: []byte("client key"),
Pools: []string{},
CustomData: map[string]string{"key": "value"},
CreateData: map[string]string{"key": "value"},
Default: true,
},
},
Expand All @@ -319,13 +308,11 @@ func (s *S) TestClusterUpdateMergeCluster(c *check.C) {
Clientkey: nil,
Pools: []string{"pool1", "pool2"},
CustomData: map[string]string{"key": "value"},
CreateData: map[string]string{"key": "value"},
Default: false,
},
},
{
command: ClusterUpdate{
removeCreateData: cmd.StringSliceFlag{"key"},
removeCustomData: cmd.StringSliceFlag{"key"},
},
cluster: getCluster(),
Expand All @@ -338,7 +325,6 @@ func (s *S) TestClusterUpdateMergeCluster(c *check.C) {
Clientkey: []byte("client key"),
Pools: []string{"pool1", "pool2"},
CustomData: map[string]string{},
CreateData: map[string]string{},
Default: false,
},
},
Expand All @@ -358,7 +344,6 @@ func (s *S) TestClusterUpdateMergeCluster(c *check.C) {
Clientkey: []byte("ANOTHER CLIENT KEY"),
Pools: []string{"pool1", "pool2"},
CustomData: map[string]string{"key": "value"},
CreateData: map[string]string{"key": "value"},
Default: false,
},
},
Expand Down Expand Up @@ -554,12 +539,5 @@ Custom Data:
+------+--------+
| key2 | value2 |
+------+--------+

Create Data:
+-------------+---------------+
| Name | Usage |
+-------------+---------------+
| create key2 | create value2 |
+-------------+---------------+
`)
}
Loading