-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.go
102 lines (90 loc) · 2.56 KB
/
client.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
package main
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
clients "github.com/cloudfoundry-community/go-cf-clients-helper/v2"
)
type Session struct {
clients.Session
}
var large = ccv3.Query{
Key: ccv3.PerPage,
Values: []string{"5000"},
}
var orderByTimestampDesc = ccv3.Query{
Key: ccv3.OrderBy,
Values: []string{"-created_at"},
}
var session *Session
func getSession() (*Session, error) {
if session != nil {
return session, nil
}
c := clients.Config{
Endpoint: options.Api,
CFClientID: options.ClientID,
CFClientSecret: options.ClientSecret,
User: options.Username,
Password: options.Password,
SkipSslValidation: options.SkipSSLValidation,
}
s, err := clients.NewSession(c)
if err != nil {
return nil, err
}
return &Session{*s}, nil
}
type Application struct {
GUID string `json:"guid,omitempty"`
Name string `json:"name,omitempty"`
State constant.ApplicationState `json:"state,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
UpdatedAt string `json:"updated_at,omitempty"`
}
type Route struct {
GUID string `json:"guid,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
}
type ServiceInstance struct {
GUID string `json:"guid,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
}
func (d *Session) ExtGetApplications(query ...ccv3.Query) ([]Application, error) {
res := []Application{}
_, _, err := d.V3().MakeListRequest(ccv3.RequestParams{
RequestName: "GetApplications",
Query: query,
ResponseBody: Application{},
AppendToList: func(item interface{}) error {
res = append(res, item.(Application))
return nil
},
})
return res, err
}
func (d *Session) ExtGetRoutes(query ...ccv3.Query) ([]Route, error) {
res := []Route{}
_, _, err := d.V3().MakeListRequest(ccv3.RequestParams{
RequestName: "GetRoutes",
Query: query,
ResponseBody: Route{},
AppendToList: func(item interface{}) error {
res = append(res, item.(Route))
return nil
},
})
return res, err
}
func (d *Session) ExtGetServiceInstances(query ...ccv3.Query) ([]ServiceInstance, error) {
res := []ServiceInstance{}
_, _, err := d.V3().MakeListRequest(ccv3.RequestParams{
RequestName: "GetServiceInstances",
Query: query,
ResponseBody: ServiceInstance{},
AppendToList: func(item interface{}) error {
res = append(res, item.(ServiceInstance))
return nil
},
})
return res, err
}