-
Notifications
You must be signed in to change notification settings - Fork 929
/
defaults.go
44 lines (35 loc) · 1.25 KB
/
defaults.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
package defaults
import (
"fmt"
"code.cloudfoundry.org/cli/cf/api/resources"
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
"code.cloudfoundry.org/cli/cf/models"
"code.cloudfoundry.org/cli/cf/net"
)
type DefaultSecurityGroupsRepoBase struct {
ConfigRepo coreconfig.Reader
Gateway net.Gateway
}
func (repo *DefaultSecurityGroupsRepoBase) Bind(groupGUID string, path string) error {
updatedPath := fmt.Sprintf("%s/%s", path, groupGUID)
return repo.Gateway.UpdateResourceFromStruct(repo.ConfigRepo.APIEndpoint(), updatedPath, "")
}
func (repo *DefaultSecurityGroupsRepoBase) List(path string) ([]models.SecurityGroupFields, error) {
groups := []models.SecurityGroupFields{}
err := repo.Gateway.ListPaginatedResources(
repo.ConfigRepo.APIEndpoint(),
path,
resources.SecurityGroupResource{},
func(resource interface{}) bool {
if securityGroupResource, ok := resource.(resources.SecurityGroupResource); ok {
groups = append(groups, securityGroupResource.ToFields())
}
return true
},
)
return groups, err
}
func (repo *DefaultSecurityGroupsRepoBase) Delete(groupGUID string, path string) error {
updatedPath := fmt.Sprintf("%s/%s", path, groupGUID)
return repo.Gateway.DeleteResource(repo.ConfigRepo.APIEndpoint(), updatedPath)
}