github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/api/securitygroups/spaces/space_binder.go (about)

     1  package spaces
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     7  	"code.cloudfoundry.org/cli/cf/models"
     8  	"code.cloudfoundry.org/cli/cf/net"
     9  )
    10  
    11  //go:generate counterfeiter . SecurityGroupSpaceBinder
    12  
    13  type SecurityGroupSpaceBinder interface {
    14  	BindSpace(securityGroupGUID string, spaceGUID string) error
    15  	UnbindSpace(securityGroupGUID string, spaceGUID string) error
    16  }
    17  
    18  type securityGroupSpaceBinder struct {
    19  	configRepo coreconfig.Reader
    20  	gateway    net.Gateway
    21  }
    22  
    23  func NewSecurityGroupSpaceBinder(configRepo coreconfig.Reader, gateway net.Gateway) (binder securityGroupSpaceBinder) {
    24  	return securityGroupSpaceBinder{
    25  		configRepo: configRepo,
    26  		gateway:    gateway,
    27  	}
    28  }
    29  
    30  func (repo securityGroupSpaceBinder) BindSpace(securityGroupGUID string, spaceGUID string) error {
    31  	url := fmt.Sprintf("/v2/security_groups/%s/spaces/%s",
    32  		securityGroupGUID,
    33  		spaceGUID,
    34  	)
    35  
    36  	return repo.gateway.UpdateResourceFromStruct(repo.configRepo.APIEndpoint(), url, models.SecurityGroupParams{})
    37  }
    38  
    39  func (repo securityGroupSpaceBinder) UnbindSpace(securityGroupGUID string, spaceGUID string) error {
    40  	url := fmt.Sprintf("/v2/security_groups/%s/spaces/%s",
    41  		securityGroupGUID,
    42  		spaceGUID,
    43  	)
    44  
    45  	return repo.gateway.DeleteResource(repo.configRepo.APIEndpoint(), url)
    46  }