-
Notifications
You must be signed in to change notification settings - Fork 4
/
list.go
109 lines (81 loc) · 2.6 KB
/
list.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
package environment
import (
"net/http"
"bunnyshell.com/cli/pkg/api"
"bunnyshell.com/cli/pkg/api/common"
"bunnyshell.com/cli/pkg/lib"
"bunnyshell.com/sdk"
"github.com/spf13/pflag"
)
type ListOptions struct {
common.ListOptions
Organization string
Project string
KubernetesIntegration string
Type string
ClusterStatus string
OperationStatus string
Search string
Labels map[string]string
}
func NewListOptions() *ListOptions {
return &ListOptions{
ListOptions: *common.NewListOptions(),
}
}
func (lo *ListOptions) UpdateFlagSet(flags *pflag.FlagSet) {
flags.StringVar(&lo.Type, "type", lo.Type, "Filter by Type")
flags.StringVar(&lo.ClusterStatus, "clusterStatus", lo.ClusterStatus, "Filter by Cluster Status")
flags.StringVar(&lo.OperationStatus, "operationStatus", lo.OperationStatus, "Filter by Operation Status")
flags.StringVar(&lo.KubernetesIntegration, "k8sCluster", lo.KubernetesIntegration, "Filter by K8SIntegrationID")
flags.StringVar(&lo.Search, "search", lo.Search, "Search by name")
flags.StringToStringVar(&lo.Labels, "label", lo.Labels, "Filter by label (key=value)")
lo.ListOptions.UpdateFlagSet(flags)
}
func List(options *ListOptions) (*sdk.PaginatedEnvironmentCollection, error) {
model, resp, err := ListRaw(options)
if err != nil {
return nil, api.ParseError(resp, err)
}
return model, nil
}
func ListRaw(options *ListOptions) (*sdk.PaginatedEnvironmentCollection, *http.Response, error) {
profile := options.GetProfile()
ctx, cancel := lib.GetContextFromProfile(profile)
defer cancel()
request := lib.GetAPIFromProfile(profile).EnvironmentAPI.EnvironmentList(ctx)
return applyOptions(request, options).Execute()
}
func applyOptions(request sdk.ApiEnvironmentListRequest, options *ListOptions) sdk.ApiEnvironmentListRequest {
if options == nil {
return request
}
if options.Page > 1 {
request = request.Page(options.Page)
}
if options.Search != "" {
request = request.Search(options.Search)
}
if options.Organization != "" {
request = request.Organization(options.Organization)
}
if options.Project != "" {
request = request.Project(options.Project)
}
if options.KubernetesIntegration != "" {
request = request.KubernetesIntegration(options.KubernetesIntegration)
}
if options.ClusterStatus != "" {
request = request.ClusterStatus(options.ClusterStatus)
}
if options.OperationStatus != "" {
request = request.OperationStatus(options.OperationStatus)
}
if options.Type != "" {
request = request.Type_(options.Type)
}
if len(options.Labels) > 0 {
request = request.Labels(options.Labels)
}
return request
}