Skip to content

Commit 4dbbf68

Browse files
authored
constructor: Populate constructorapi Region field (#305)
Updates the constructor commands to use the region per API call.
1 parent 8d38d56 commit 4dbbf68

File tree

7 files changed

+162
-84
lines changed

7 files changed

+162
-84
lines changed

cmd/platform/constructor/command.go

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,12 @@
1818
package cmdconstructor
1919

2020
import (
21-
"fmt"
22-
"path/filepath"
23-
24-
"github.com/elastic/cloud-sdk-go/pkg/api/platformapi/constructorapi"
2521
"github.com/spf13/cobra"
2622

2723
cmdutil "github.com/elastic/ecctl/cmd/util"
28-
"github.com/elastic/ecctl/pkg/ecctl"
2924
)
3025

3126
const (
32-
constructorListMessage = `Returns all of the constructors in the platform`
3327
constructorShowMessage = `Returns information about the constructor with given ID`
3428
constructorMaintenanceMessage = `Sets/un-sets a constructor's maintenance mode`
3529
)
@@ -38,76 +32,8 @@ const (
3832
var Command = &cobra.Command{
3933
Use: "constructor",
4034
Short: cmdutil.AdminReqDescription("Manages constructors"),
41-
PreRunE: cobra.MaximumNArgs(0),
35+
PreRunE: cobra.NoArgs,
4236
Run: func(cmd *cobra.Command, args []string) {
4337
cmd.Help()
4438
},
4539
}
46-
47-
func listConstructors(cmd *cobra.Command, args []string) error {
48-
a, err := constructorapi.List(constructorapi.Params{
49-
API: ecctl.Get().API,
50-
})
51-
if err != nil {
52-
return err
53-
}
54-
55-
return ecctl.Get().Formatter.Format(filepath.Join("constructor", "list"), a)
56-
}
57-
58-
var showConstructorCmd = &cobra.Command{
59-
Use: "show <constructor id>",
60-
Short: constructorShowMessage,
61-
PreRunE: cobra.MinimumNArgs(1),
62-
RunE: func(cmd *cobra.Command, args []string) error {
63-
a, err := constructorapi.Get(constructorapi.GetParams{
64-
Params: constructorapi.Params{
65-
API: ecctl.Get().API,
66-
},
67-
ID: args[0],
68-
})
69-
if err != nil {
70-
return err
71-
}
72-
return ecctl.Get().Formatter.Format(filepath.Join("constructor", "show"), a)
73-
},
74-
}
75-
76-
var maintenanceConstructorCmd = &cobra.Command{
77-
Use: "maintenance <constructor id>",
78-
Short: constructorMaintenanceMessage,
79-
PreRunE: cobra.MinimumNArgs(1),
80-
81-
RunE: func(cmd *cobra.Command, args []string) error {
82-
unset, _ := cmd.Flags().GetBool("unset")
83-
fmt.Printf("Setting contructor %s maintenance to %t\n", args[0], !unset)
84-
var params = constructorapi.MaintenanceParams{
85-
Params: constructorapi.Params{
86-
API: ecctl.Get().API,
87-
},
88-
ID: args[0],
89-
}
90-
91-
if unset {
92-
return constructorapi.DisableMaintenance(params)
93-
}
94-
return constructorapi.EnableMaintenace(params)
95-
},
96-
}
97-
98-
var listConstructorsCmd = &cobra.Command{
99-
Use: "list",
100-
Short: constructorListMessage,
101-
PreRunE: cobra.MaximumNArgs(0),
102-
RunE: listConstructors,
103-
}
104-
105-
func init() {
106-
Command.AddCommand(
107-
listConstructorsCmd,
108-
showConstructorCmd,
109-
maintenanceConstructorCmd,
110-
)
111-
112-
maintenanceConstructorCmd.Flags().Bool("unset", false, "Unset constructor maintenance mode")
113-
}

cmd/platform/constructor/list.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package cmdconstructor
19+
20+
import (
21+
"path/filepath"
22+
23+
"github.com/elastic/cloud-sdk-go/pkg/api/platformapi/constructorapi"
24+
"github.com/spf13/cobra"
25+
26+
"github.com/elastic/ecctl/pkg/ecctl"
27+
)
28+
29+
var listConstructorsCmd = &cobra.Command{
30+
Use: "list",
31+
Short: `Returns all of the constructors in the platform`,
32+
PreRunE: cobra.NoArgs,
33+
RunE: listConstructors,
34+
}
35+
36+
func listConstructors(cmd *cobra.Command, args []string) error {
37+
a, err := constructorapi.List(constructorapi.ListParams{
38+
API: ecctl.Get().API,
39+
Region: ecctl.Get().Config.Region,
40+
})
41+
if err != nil {
42+
return err
43+
}
44+
45+
return ecctl.Get().Formatter.Format(filepath.Join("constructor", "list"), a)
46+
}
47+
48+
func init() {
49+
Command.AddCommand(listConstructorsCmd)
50+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package cmdconstructor
19+
20+
import (
21+
"fmt"
22+
23+
"github.com/elastic/cloud-sdk-go/pkg/api/platformapi/constructorapi"
24+
"github.com/spf13/cobra"
25+
26+
"github.com/elastic/ecctl/pkg/ecctl"
27+
)
28+
29+
var maintenanceConstructorCmd = &cobra.Command{
30+
Use: "maintenance <constructor id>",
31+
Short: constructorMaintenanceMessage,
32+
PreRunE: cobra.ExactArgs(1),
33+
RunE: func(cmd *cobra.Command, args []string) error {
34+
unset, _ := cmd.Flags().GetBool("unset")
35+
fmt.Printf("Setting contructor %s maintenance to %t\n", args[0], !unset)
36+
var params = constructorapi.MaintenanceParams{
37+
API: ecctl.Get().API,
38+
Region: ecctl.Get().Config.Region,
39+
ID: args[0],
40+
}
41+
42+
if unset {
43+
return constructorapi.DisableMaintenance(params)
44+
}
45+
return constructorapi.EnableMaintenace(params)
46+
},
47+
}
48+
49+
func init() {
50+
Command.AddCommand(
51+
maintenanceConstructorCmd,
52+
)
53+
maintenanceConstructorCmd.Flags().Bool("unset", false, "Unset constructor maintenance mode")
54+
}

cmd/platform/constructor/resync.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ var resyncConstructorCmd = &cobra.Command{
3636

3737
if all {
3838
fmt.Println("Resynchronizing all constructors")
39-
res, err := constructorapi.ResyncAll(constructorapi.Params{
40-
API: ecctl.Get().API,
39+
res, err := constructorapi.ResyncAll(constructorapi.ResyncAllParams{
40+
API: ecctl.Get().API,
41+
Region: ecctl.Get().Config.Region,
4142
})
4243
if err != nil {
4344
return err
@@ -48,8 +49,9 @@ var resyncConstructorCmd = &cobra.Command{
4849

4950
fmt.Printf("Resynchronizing constructor: %s\n", args[0])
5051
return constructorapi.Resync(constructorapi.ResyncParams{
51-
API: ecctl.Get().API,
52-
ID: args[0],
52+
API: ecctl.Get().API,
53+
Region: ecctl.Get().Config.Region,
54+
ID: args[0],
5355
})
5456
},
5557
}

cmd/platform/constructor/show.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Licensed to Elasticsearch B.V. under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Elasticsearch B.V. licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package cmdconstructor
19+
20+
import (
21+
"path/filepath"
22+
23+
"github.com/elastic/cloud-sdk-go/pkg/api/platformapi/constructorapi"
24+
"github.com/spf13/cobra"
25+
26+
"github.com/elastic/ecctl/pkg/ecctl"
27+
)
28+
29+
var showConstructorCmd = &cobra.Command{
30+
Use: "show <constructor id>",
31+
Short: constructorShowMessage,
32+
PreRunE: cobra.ExactArgs(1),
33+
RunE: func(cmd *cobra.Command, args []string) error {
34+
a, err := constructorapi.Get(constructorapi.GetParams{
35+
API: ecctl.Get().API,
36+
Region: ecctl.Get().Config.Region,
37+
ID: args[0],
38+
})
39+
if err != nil {
40+
return err
41+
}
42+
return ecctl.Get().Formatter.Format(filepath.Join("constructor", "show"), a)
43+
},
44+
}
45+
46+
func init() {
47+
Command.AddCommand(showConstructorCmd)
48+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.12
44

55
require (
66
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a
7-
github.com/elastic/cloud-sdk-go v1.0.0-beta3.0.20200610080731-ecad4ea9c617
7+
github.com/elastic/cloud-sdk-go v1.0.0-beta3.0.20200611022835-af13daa69099
88
github.com/go-openapi/runtime v0.19.15
99
github.com/go-openapi/strfmt v0.19.5
1010
github.com/hashicorp/go-multierror v1.0.0

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,8 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
5959
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
6060
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
6161
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
62-
github.com/elastic/cloud-sdk-go v1.0.0-beta3.0.20200610014412-d8bc0d1b9b30 h1:KlJmjQ5ZehOnYtffQ4/7vspv8rg47cckF2+etZ7MAgY=
63-
github.com/elastic/cloud-sdk-go v1.0.0-beta3.0.20200610014412-d8bc0d1b9b30/go.mod h1:+0Q5izB9Upzmolj6Pq4AkTsBwgDbQnNpODp3qFK7erQ=
64-
github.com/elastic/cloud-sdk-go v1.0.0-beta3.0.20200610080731-ecad4ea9c617 h1:y3zhClgtQaEZcnKpVQR0anI8LxbH6DL1swgju/flnpU=
65-
github.com/elastic/cloud-sdk-go v1.0.0-beta3.0.20200610080731-ecad4ea9c617/go.mod h1:+0Q5izB9Upzmolj6Pq4AkTsBwgDbQnNpODp3qFK7erQ=
62+
github.com/elastic/cloud-sdk-go v1.0.0-beta3.0.20200611022835-af13daa69099 h1:XwJFBtYATU/27Ro++EydUUdOW40qTgFAKXwmkXttCDw=
63+
github.com/elastic/cloud-sdk-go v1.0.0-beta3.0.20200611022835-af13daa69099/go.mod h1:+0Q5izB9Upzmolj6Pq4AkTsBwgDbQnNpODp3qFK7erQ=
6664
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
6765
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
6866
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=

0 commit comments

Comments
 (0)