forked from cloudfoundry-community/cloudfoundry-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space_binder.go
46 lines (36 loc) · 1.25 KB
/
space_binder.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
package spaces
import (
"fmt"
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
"code.cloudfoundry.org/cli/cf/models"
"code.cloudfoundry.org/cli/cf/net"
)
//go:generate counterfeiter . SecurityGroupSpaceBinder
type SecurityGroupSpaceBinder interface {
BindSpace(securityGroupGUID string, spaceGUID string) error
UnbindSpace(securityGroupGUID string, spaceGUID string) error
}
type securityGroupSpaceBinder struct {
configRepo coreconfig.Reader
gateway net.Gateway
}
func NewSecurityGroupSpaceBinder(configRepo coreconfig.Reader, gateway net.Gateway) (binder securityGroupSpaceBinder) {
return securityGroupSpaceBinder{
configRepo: configRepo,
gateway: gateway,
}
}
func (repo securityGroupSpaceBinder) BindSpace(securityGroupGUID string, spaceGUID string) error {
url := fmt.Sprintf("/v2/security_groups/%s/spaces/%s",
securityGroupGUID,
spaceGUID,
)
return repo.gateway.UpdateResourceFromStruct(repo.configRepo.APIEndpoint(), url, models.SecurityGroupParams{})
}
func (repo securityGroupSpaceBinder) UnbindSpace(securityGroupGUID string, spaceGUID string) error {
url := fmt.Sprintf("/v2/security_groups/%s/spaces/%s",
securityGroupGUID,
spaceGUID,
)
return repo.gateway.DeleteResource(repo.configRepo.APIEndpoint(), url)
}