-
Notifications
You must be signed in to change notification settings - Fork 492
/
mesh_tenant.go
107 lines (89 loc) · 2.47 KB
/
mesh_tenant.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package command
import (
"errors"
"github.com/spf13/cobra"
"net/http"
)
func tenantCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "tenant",
Short: "query and manager tenant",
}
cmd.AddCommand(createTenantCmd())
cmd.AddCommand(updateTenantCmd())
cmd.AddCommand(deleteTenantCmd())
cmd.AddCommand(getTenantCmd())
cmd.AddCommand(listTenantsCmd())
return cmd
}
func createTenantCmd() *cobra.Command {
var specFile string
cmd := &cobra.Command{
Use: "create",
Short: "Create an tenant from a yaml file or stdin",
Run: func(cmd *cobra.Command, args []string) {
buff, _ := readFromFileOrStdin(specFile, cmd)
handleRequest(http.MethodPost, makeURL(MeshTenantsURL), buff, cmd)
},
}
cmd.Flags().StringVarP(&specFile, "file", "f", "", "A yaml file specifying the tenant.")
return cmd
}
func updateTenantCmd() *cobra.Command {
var specFile string
cmd := &cobra.Command{
Use: "update",
Short: "Update an tenant from a yaml file or stdin",
Run: func(cmd *cobra.Command, args []string) {
buff, name := readFromFileOrStdin(specFile, cmd)
handleRequest(http.MethodPut, makeURL(MeshTenantURL, name), buff, cmd)
},
}
cmd.Flags().StringVarP(&specFile, "file", "f", "", "A yaml file specifying the tenant.")
return cmd
}
func deleteTenantCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
Short: "Delete an tenant",
Example: "egctl mesh tenant delete <tenant_name>",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("requires one tenant name to be deleted")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
handleRequest(http.MethodDelete, makeURL(MeshTenantURL, args[0]), nil, cmd)
},
}
return cmd
}
func getTenantCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "get",
Short: "Get an tenant",
Example: "egctl mesh tenant get <tenant_name>",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 1 {
return errors.New("requires one tenant name to be retrieved")
}
return nil
},
Run: func(cmd *cobra.Command, args []string) {
handleRequest(http.MethodGet, makeURL(MeshTenantURL, args[0]), nil, cmd)
},
}
return cmd
}
func listTenantsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "List all tenants",
Example: "egctl mesh tenant list",
Run: func(cmd *cobra.Command, args []string) {
handleRequest(http.MethodGet, makeURL(MeshTenantsURL), nil, cmd)
},
}
return cmd
}