forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
space_binder.go
46 lines (37 loc) · 1.2 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"
"github.com/cloudfoundry/cli/cf/configuration"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/net"
)
type SecurityGroupSpaceBinder interface {
BindSpace(securityGroupGuid string, spaceGuid string) error
UnbindSpace(securityGroupGuid string, spaceGuid string) error
}
type securityGroupSpaceBinder struct {
configRepo configuration.Reader
gateway net.Gateway
}
func NewSecurityGroupSpaceBinder(configRepo configuration.Reader, gateway net.Gateway) (binder securityGroupSpaceBinder) {
return securityGroupSpaceBinder{
configRepo: configRepo,
gateway: gateway,
}
}
func (repo securityGroupSpaceBinder) BindSpace(securityGroupGuid string, spaceGuid string) error {
url := fmt.Sprintf("%s/v2/security_groups/%s/spaces/%s",
repo.configRepo.ApiEndpoint(),
securityGroupGuid,
spaceGuid,
)
return repo.gateway.UpdateResourceFromStruct(url, models.SecurityGroupParams{})
}
func (repo securityGroupSpaceBinder) UnbindSpace(securityGroupGuid string, spaceGuid string) error {
url := fmt.Sprintf("%s/v2/security_groups/%s/spaces/%s",
repo.configRepo.ApiEndpoint(),
securityGroupGuid,
spaceGuid,
)
return repo.gateway.DeleteResource(url)
}