/
list.go
67 lines (50 loc) · 1.42 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
package registry_integration
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
Environment string
CloudProvider string
Status string
}
func NewListOptions() *ListOptions {
return &ListOptions{
ListOptions: *common.NewListOptions(),
}
}
func (lo *ListOptions) UpdateFlagSet(flags *pflag.FlagSet) {
lo.ListOptions.UpdateFlagSet(flags)
}
func List(options *ListOptions) (*sdk.PaginatedRegistryIntegrationCollection, error) {
model, resp, err := ListRaw(options)
if err != nil {
return nil, api.ParseError(resp, err)
}
return model, nil
}
func ListRaw(options *ListOptions) (*sdk.PaginatedRegistryIntegrationCollection, *http.Response, error) {
profile := options.GetProfile()
ctx, cancel := lib.GetContextFromProfile(profile)
defer cancel()
request := lib.GetAPIFromProfile(profile).RegistryIntegrationAPI.RegistryIntegrationList(ctx)
return applyOptions(request, options).Execute()
}
func applyOptions(request sdk.ApiRegistryIntegrationListRequest, options *ListOptions) sdk.ApiRegistryIntegrationListRequest {
if options == nil {
return request
}
if options.Page > 1 {
request = request.Page(options.Page)
}
if options.Organization != "" {
request = request.Organization(options.Organization)
}
return request
}