func (repo cloudControllerSecurityGroupRepo) Read(name string) (models.SecurityGroup, error) { path := fmt.Sprintf("/v2/security_groups?q=%s", url.QueryEscape("name:"+name)) group := models.SecurityGroup{} foundGroup := false err := repo.gateway.ListPaginatedResources( repo.config.APIEndpoint(), path, resources.SecurityGroupResource{}, func(resource interface{}) bool { if asgr, ok := resource.(resources.SecurityGroupResource); ok { group = asgr.ToModel() foundGroup = true } return false }, ) if err != nil { return group, err } if !foundGroup { return group, errors.NewModelNotFoundError("security group", name) } err = repo.gateway.ListPaginatedResources( repo.config.APIEndpoint(), group.SpaceURL+"?inline-relations-depth=1", resources.SpaceResource{}, func(resource interface{}) bool { if asgr, ok := resource.(resources.SpaceResource); ok { group.Spaces = append(group.Spaces, asgr.ToModel()) return true } return false }, ) return group, err }