forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
defaults.go
44 lines (35 loc) · 1.26 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"
"github.com/cloudfoundry/cli/cf/api/resources"
"github.com/cloudfoundry/cli/cf/configuration"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/net"
)
type DefaultSecurityGroupsRepoBase struct {
ConfigRepo configuration.Reader
Gateway net.Gateway
}
func (repo *DefaultSecurityGroupsRepoBase) Bind(groupGuid string, path string) error {
updatedPath := fmt.Sprintf("%s%s/%s", repo.ConfigRepo.ApiEndpoint(), path, groupGuid)
return repo.Gateway.UpdateResourceFromStruct(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/%s", repo.ConfigRepo.ApiEndpoint(), path, groupGuid)
return repo.Gateway.DeleteResource(updatedPath)
}