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

     1  package defaults
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"code.cloudfoundry.org/cli/cf/api/resources"
     7  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     8  	"code.cloudfoundry.org/cli/cf/models"
     9  	"code.cloudfoundry.org/cli/cf/net"
    10  )
    11  
    12  type DefaultSecurityGroupsRepoBase struct {
    13  	ConfigRepo coreconfig.Reader
    14  	Gateway    net.Gateway
    15  }
    16  
    17  func (repo *DefaultSecurityGroupsRepoBase) Bind(groupGUID string, path string) error {
    18  	updatedPath := fmt.Sprintf("%s/%s", path, groupGUID)
    19  	return repo.Gateway.UpdateResourceFromStruct(repo.ConfigRepo.APIEndpoint(), updatedPath, "")
    20  }
    21  
    22  func (repo *DefaultSecurityGroupsRepoBase) List(path string) ([]models.SecurityGroupFields, error) {
    23  	groups := []models.SecurityGroupFields{}
    24  
    25  	err := repo.Gateway.ListPaginatedResources(
    26  		repo.ConfigRepo.APIEndpoint(),
    27  		path,
    28  		resources.SecurityGroupResource{},
    29  		func(resource interface{}) bool {
    30  			if securityGroupResource, ok := resource.(resources.SecurityGroupResource); ok {
    31  				groups = append(groups, securityGroupResource.ToFields())
    32  			}
    33  
    34  			return true
    35  		},
    36  	)
    37  
    38  	return groups, err
    39  }
    40  
    41  func (repo *DefaultSecurityGroupsRepoBase) Delete(groupGUID string, path string) error {
    42  	updatedPath := fmt.Sprintf("%s/%s", path, groupGUID)
    43  	return repo.Gateway.DeleteResource(repo.ConfigRepo.APIEndpoint(), updatedPath)
    44  }