github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/api/security_groups/defaults/defaults.go (about) 1 package defaults 2 3 import ( 4 "fmt" 5 6 "github.com/cloudfoundry/cli/cf/api/resources" 7 "github.com/cloudfoundry/cli/cf/configuration/core_config" 8 "github.com/cloudfoundry/cli/cf/models" 9 "github.com/cloudfoundry/cli/cf/net" 10 ) 11 12 type DefaultSecurityGroupsRepoBase struct { 13 ConfigRepo core_config.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 }