-
Notifications
You must be signed in to change notification settings - Fork 4
/
gvcs.go
115 lines (89 loc) · 2.57 KB
/
gvcs.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
108
109
110
111
112
113
114
115
package cpln
import (
"encoding/json"
"fmt"
"net/http"
)
// Gvcs - GVC's
type Gvcs struct {
Kind string `json:"kind,omitempty"`
Items []Gvc `json:"items,omitempty"`
Links []Link `json:"links,omitempty"`
Query Query `json:"query,omitempty"`
}
// Gvc - Global Virtual Cloud
type Gvc struct {
Base
Spec *GvcSpec `json:"spec,omitempty"`
SpecReplace *GvcSpec `json:"$replace/spec,omitempty"`
Alias *string `json:"alias,omitempty"`
}
// GvcSpec - GVC Spec
type GvcSpec struct {
StaticPlacement *StaticPlacement `json:"staticPlacement,omitempty"`
PullSecretLinks *[]string `json:"pullSecretLinks,omitempty"`
Domain *string `json:"domain,omitempty"`
Tracing *Tracing `json:"tracing,omitempty"`
Sidecar *GvcSidecar `json:"sidecar,omitempty"`
Env *[]NameValue `json:"env,omitempty"`
LoadBalancer *LoadBalancer `json:"loadBalancer,omitempty"`
}
// StaticPlacement - Static Placement
type StaticPlacement struct {
LocationLinks *[]string `json:"locationLinks,omitempty"`
LocationQuery *Query `json:"locationQuery,omitempty"`
}
// GvcSidecar - GVC Sidecar
type GvcSidecar struct {
Envoy *any `json:"envoy,omitempty"`
}
// LoadBalancer - Load Balancer
type LoadBalancer struct {
Dedicated *bool `json:"dedicated,omitempty"`
TrustedProxies *int `json:"trustedProxies,omitempty"`
}
// GetGvcs - Get All Gvcs
func (c *Client) GetGvcs() (*Gvcs, error) {
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/org/%s/gvc/-query", c.HostURL, c.Org), nil)
if err != nil {
return nil, err
}
body, _, err := c.doRequest(req, "")
if err != nil {
return nil, err
}
gvcs := Gvcs{}
err = json.Unmarshal(body, &gvcs)
if err != nil {
return nil, err
}
return &gvcs, nil
}
// GetGvc - Get GVC by name
func (c *Client) GetGvc(name string) (*Gvc, int, error) {
gvc, code, err := c.GetResource(fmt.Sprintf("gvc/%s", name), new(Gvc))
if err != nil {
return nil, code, err
}
return gvc.(*Gvc), code, err
}
// CreateGvc - Create a new GVC
func (c *Client) CreateGvc(gvc Gvc) (*Gvc, int, error) {
code, err := c.CreateResource("gvc", *gvc.Name, gvc)
if err != nil {
return nil, code, err
}
return c.GetGvc(*gvc.Name)
}
// UpdateGvc - Update an existing GVC
func (c *Client) UpdateGvc(gvc Gvc) (*Gvc, int, error) {
code, err := c.UpdateResource(fmt.Sprintf("gvc/%s", *gvc.Name), gvc)
if err != nil {
return nil, code, err
}
return c.GetGvc(*gvc.Name)
}
// DeleteGvc - Delete GVC by name
func (c *Client) DeleteGvc(name string) error {
return c.DeleteResource(fmt.Sprintf("gvc/%s", name))
}