github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/api/security_groups/spaces/space_binder.go (about)

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