func (repo CloudControllerServiceRepository) FindInstanceByName(name string) (instance models.ServiceInstance, apiErr error) { path := fmt.Sprintf("%s/v2/spaces/%s/service_instances?return_user_provided_service_instances=true&q=%s&inline-relations-depth=1", repo.config.ApiEndpoint(), repo.config.SpaceFields().Guid, url.QueryEscape("name:"+name)) responseJSON := new(resources.PaginatedServiceInstanceResources) apiErr = repo.gateway.GetResource(path, responseJSON) if apiErr != nil { return } if len(responseJSON.Resources) == 0 { apiErr = errors.NewModelNotFoundError("Service instance", name) return } instanceResource := responseJSON.Resources[0] instance = instanceResource.ToModel() if instanceResource.Entity.ServicePlan.Metadata.Guid != "" { resource := &resources.ServiceOfferingResource{} path = fmt.Sprintf("%s/v2/services/%s", repo.config.ApiEndpoint(), instanceResource.Entity.ServicePlan.Entity.ServiceOfferingGuid) apiErr = repo.gateway.GetResource(path, resource) instance.ServiceOffering = resource.ToFields() } return }
func (repo cloudControllerSecurityGroupRepo) Read(name string) (models.SecurityGroup, error) { path := fmt.Sprintf("/v2/security_groups?q=%s&inline-relations-depth=2", 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 { err = errors.NewModelNotFoundError("security group", name) } return group, err }
func (repo *FakeServiceBrokerRepo) FindByName(name string) (serviceBroker models.ServiceBroker, apiErr error) { repo.FindByNameName = name serviceBroker = repo.FindByNameServiceBroker if repo.FindByNameNotFound { apiErr = errors.NewModelNotFoundError("Service Broker", name) } return }
func (repo *FakeBuildpackRepository) FindByName(name string) (buildpack models.Buildpack, apiErr error) { repo.FindByNameName = name buildpack = repo.FindByNameBuildpack if repo.FindByNameNotFound { apiErr = errors.NewModelNotFoundError("Buildpack", name) } return }
func (repo *FakeUserRepository) FindByUsername(username string) (user models.UserFields, apiErr error) { repo.FindByUsernameUsername = username user = repo.FindByUsernameUserFields if repo.FindByUsernameNotFound { apiErr = errors.NewModelNotFoundError("User", "") } return }
func (repo *FakeServiceBrokerRepo) FindByGuid(guid string) (serviceBroker models.ServiceBroker, apiErr error) { repo.FindByGuidGuid = guid serviceBroker = repo.FindByGuidServiceBroker if repo.FindByGuidNotFound { apiErr = errors.NewModelNotFoundError("Service Broker", guid) } return }
func (repo CloudControllerDomainRepository) FindByNameInOrg(name string, orgGuid string) (domain models.DomainFields, apiErr error) { domain, apiErr = repo.findOneWithPath(repo.strategy.OrgDomainURL(orgGuid, name), name) switch apiErr.(type) { case *errors.ModelNotFoundError: domain, apiErr = repo.FindByName(name) if !domain.Shared { apiErr = errors.NewModelNotFoundError("Domain", name) } } return }
func (repo CloudControllerServiceRepository) FindServiceOfferingByLabelAndProvider(label, provider string) (models.ServiceOffering, error) { path := fmt.Sprintf("/v2/services?q=%s", url.QueryEscape("label:"+label+";provider:"+provider)) offerings, apiErr := repo.getServiceOfferings(path) if apiErr != nil { return models.ServiceOffering{}, apiErr } else if len(offerings) == 0 { apiErr = errors.NewModelNotFoundError("Service offering", label+" "+provider) return models.ServiceOffering{}, apiErr } return offerings[0], apiErr }
func (repo *FakeDomainRepository) FindByName(name string) (domain models.DomainFields, apiErr error) { repo.FindByNameName = name domain = repo.FindByNameDomain if repo.FindByNameNotFound { apiErr = errors.NewModelNotFoundError("Domain", name) } if repo.FindByNameErr { apiErr = errors.New("Error finding domain") } return }
func (repo CloudControllerDomainRepository) findOneWithPath(path, name string) (domain models.DomainFields, apiErr error) { foundDomain := false apiErr = repo.listDomains(path, func(result models.DomainFields) bool { domain = result foundDomain = true return false }) if apiErr == nil && !foundDomain { apiErr = errors.NewModelNotFoundError("Domain", name) } return }
func (repo CloudControllerServiceRepository) FindServiceOfferingsForSpaceByLabel(spaceGuid, name string) (offerings models.ServiceOfferings, err error) { offerings, err = repo.getServiceOfferings( fmt.Sprintf("/v2/spaces/%s/services?q=%s&inline-relations-depth=1", spaceGuid, url.QueryEscape("label:"+name))) if httpErr, ok := err.(errors.HttpError); ok && httpErr.ErrorCode() == errors.BAD_QUERY_PARAM { offerings, err = repo.findServiceOfferingsByPaginating(spaceGuid, name) } if err == nil && len(offerings) == 0 { err = errors.NewModelNotFoundError("Service offering", name) } return }
func (repo CloudControllerServiceAuthTokenRepository) FindByLabelAndProvider(label, provider string) (authToken models.ServiceAuthTokenFields, apiErr error) { path := fmt.Sprintf("/v2/service_auth_tokens?q=%s", url.QueryEscape("label:"+label+";provider:"+provider)) authTokens, apiErr := repo.findAllWithPath(path) if apiErr != nil { return } if len(authTokens) == 0 { apiErr = errors.NewModelNotFoundError("Service Auth Token", label+" "+provider) return } authToken = authTokens[0] return }
func (repo CloudControllerStackRepository) FindByName(name string) (stack models.Stack, apiErr error) { path := fmt.Sprintf("/v2/stacks?q=%s", url.QueryEscape("name:"+name)) stacks, apiErr := repo.findAllWithPath(path) if apiErr != nil { return } if len(stacks) == 0 { apiErr = errors.NewModelNotFoundError("Stack", name) return } stack = stacks[0] return }
func (repo CloudControllerSpaceQuotaRepository) FindByGuid(guid string) (quota models.SpaceQuota, apiErr error) { quotas, apiErr := repo.FindByOrg(repo.config.OrganizationFields().Guid) if apiErr != nil { return } for _, quota := range quotas { if quota.Guid == guid { return quota, nil } } apiErr = errors.NewModelNotFoundError("Space Quota", guid) return models.SpaceQuota{}, apiErr }
func (repo CloudControllerQuotaRepository) FindByName(name string) (quota models.QuotaFields, apiErr error) { path := fmt.Sprintf("/v2/quota_definitions?q=%s", url.QueryEscape("name:"+name)) quotas, apiErr := repo.findAllWithPath(path) if apiErr != nil { return } if len(quotas) == 0 { apiErr = errors.NewModelNotFoundError("Quota", name) return } quota = quotas[0] return }
func (repo CloudControllerApplicationRepository) ReadFromSpace(name string, spaceGuid string) (app models.Application, apiErr error) { path := fmt.Sprintf("%s/v2/spaces/%s/apps?q=%s&inline-relations-depth=1", repo.config.ApiEndpoint(), spaceGuid, url.QueryEscape("name:"+name)) appResources := new(resources.PaginatedApplicationResources) apiErr = repo.gateway.GetResource(path, appResources) if apiErr != nil { return } if len(appResources.Resources) == 0 { apiErr = errors.NewModelNotFoundError("App", name) return } res := appResources.Resources[0] app = res.ToModel() return }
func (repo CloudControllerBuildpackRepository) FindByName(name string) (buildpack models.Buildpack, apiErr error) { foundIt := false apiErr = repo.gateway.ListPaginatedResources( repo.config.ApiEndpoint(), fmt.Sprintf("%s?q=%s", buildpacks_path, url.QueryEscape("name:"+name)), resources.BuildpackResource{}, func(resource interface{}) bool { buildpack = resource.(resources.BuildpackResource).ToFields() foundIt = true return false }) if !foundIt { apiErr = errors.NewModelNotFoundError("Buildpack", name) } return }
func (repo CloudControllerSpaceRepository) FindByNameInOrg(name, orgGuid string) (space models.Space, apiErr error) { foundSpace := false apiErr = repo.gateway.ListPaginatedResources( repo.config.ApiEndpoint(), fmt.Sprintf("/v2/organizations/%s/spaces?q=%s&inline-relations-depth=1", orgGuid, url.QueryEscape("name:"+strings.ToLower(name))), resources.SpaceResource{}, func(resource interface{}) bool { space = resource.(resources.SpaceResource).ToModel() foundSpace = true return false }) if !foundSpace { apiErr = errors.NewModelNotFoundError("Space", name) } return }
func (repo CloudControllerRouteRepository) FindByHostAndDomain(host string, domain models.DomainFields) (route models.Route, apiErr error) { found := false apiErr = repo.gateway.ListPaginatedResources( repo.config.ApiEndpoint(), fmt.Sprintf("/v2/routes?inline-relations-depth=1&q=%s", url.QueryEscape("host:"+host+";domain_guid:"+domain.Guid)), resources.RouteResource{}, func(resource interface{}) bool { route = resource.(resources.RouteResource).ToModel() found = true return false }) if apiErr == nil && !found { apiErr = errors.NewModelNotFoundError("Route", host) } return }
func (repo CloudControllerOrganizationRepository) FindByName(name string) (org models.Organization, apiErr error) { found := false apiErr = repo.gateway.ListPaginatedResources( repo.config.ApiEndpoint(), fmt.Sprintf("/v2/organizations?q=%s&inline-relations-depth=1", url.QueryEscape("name:"+strings.ToLower(name))), resources.OrganizationResource{}, func(resource interface{}) bool { org = resource.(resources.OrganizationResource).ToModel() found = true return false }) if apiErr == nil && !found { apiErr = errors.NewModelNotFoundError("Organization", name) } return }
func (repo CloudControllerUserRepository) FindByUsername(username string) (user models.UserFields, apiErr error) { uaaEndpoint, apiErr := repo.getAuthEndpoint() if apiErr != nil { return } usernameFilter := neturl.QueryEscape(fmt.Sprintf(`userName Eq "%s"`, username)) path := fmt.Sprintf("%s/Users?attributes=id,userName&filter=%s", uaaEndpoint, usernameFilter) users, apiErr := repo.updateOrFindUsersWithUAAPath([]models.UserFields{}, path) if len(users) == 0 { apiErr = errors.NewModelNotFoundError("User", username) return } user = users[0] return }
func (repo CloudControllerServiceBrokerRepository) FindByName(name string) (serviceBroker models.ServiceBroker, apiErr error) { foundBroker := false apiErr = repo.gateway.ListPaginatedResources( repo.config.ApiEndpoint(), fmt.Sprintf("/v2/service_brokers?q=%s", url.QueryEscape("name:"+name)), resources.ServiceBrokerResource{}, func(resource interface{}) bool { serviceBroker = resource.(resources.ServiceBrokerResource).ToFields() foundBroker = true return false }) if !foundBroker { apiErr = errors.NewModelNotFoundError("Service Broker", name) } return }
func (repo *FakeServiceRepo) FindInstanceByName(name string) (instance models.ServiceInstance, apiErr error) { repo.FindInstanceByNameName = name if repo.FindInstanceByNameMap != nil && repo.FindInstanceByNameMap.Has(name) { instance = repo.FindInstanceByNameMap.Get(name).(models.ServiceInstance) } else { instance = repo.FindInstanceByNameServiceInstance } if repo.FindInstanceByNameErr { apiErr = errors.New("Error finding instance") } if repo.FindInstanceByNameNotFound { apiErr = errors.NewModelNotFoundError("Service instance", name) } return }
func (repo *FakeZoneRepository) FindByName(name string, orgGuid string) (zone models.Zone, apiErr error) { repo.FindByNameName = name var foundZone bool = false for _, anZone := range repo.Zones { if name == anZone.Name { foundZone = true zone = anZone break } } if repo.FindByNameErr || !foundZone { apiErr = errors.New("Error finding zone by name.") } if repo.FindByNameNotFound { apiErr = errors.NewModelNotFoundError("Zone", name) } return }
func (repo *FakeSpaceRepository) FindByName(name string) (space models.Space, apiErr error) { repo.FindByNameName = name var foundSpace bool = false for _, someSpace := range repo.Spaces { if name == someSpace.Name { foundSpace = true space = someSpace break } } if repo.FindByNameErr || !foundSpace { apiErr = errors.New("Error finding space by name.") } if repo.FindByNameNotFound { apiErr = errors.NewModelNotFoundError("Space", name) } return }
func (repo CloudControllerServiceRepository) FindServicePlanByDescription(planDescription resources.ServicePlanDescription) (string, error) { path := fmt.Sprintf("/v2/services?inline-relations-depth=1&q=%s", url.QueryEscape("label:"+planDescription.ServiceLabel+";provider:"+planDescription.ServiceProvider)) var planGuid string offerings, apiErr := repo.getServiceOfferings(path) if apiErr != nil { return planGuid, apiErr } for _, serviceOfferingResource := range offerings { for _, servicePlanResource := range serviceOfferingResource.Plans { if servicePlanResource.Name == planDescription.ServicePlanName { planGuid := servicePlanResource.Guid return planGuid, apiErr } } } apiErr = errors.NewModelNotFoundError("Plan", planDescription.String()) return planGuid, apiErr }
func (repo CloudControllerZoneRepository) FindByName(name string, orgGuid string) (zone models.Zone, apiErr error) { found := false apiErr = repo.gateway.ListPaginatedResources( repo.config.ApiEndpoint(), fmt.Sprintf("/v2/zones?q=%s&inline-relations-depth=1", url.QueryEscape("name:"+name)), resources.ZoneResource{}, func(resource interface{}) bool { zone = resource.(resources.ZoneResource).ToModel() if zone.IsPublic == false { if orgGuid == "" || zone.OrgGuid != orgGuid { return true } } found = true return false }) if apiErr == nil && !found { apiErr = errors.NewModelNotFoundError("Zone", name) } return }
It("fails when the user is not logged in", func() { requirementsFactory.LoginSuccess = false runCommand("my-app") Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) }) }) It("fails with usage when no app name is given", func() { runCommand() Expect(ui.FailedWithUsage).To(BeTrue()) Expect(testcmd.CommandDidPassRequirements).To(BeFalse()) }) It("fails with usage when the app cannot be found", func() { appRepo.ReadReturns.Error = errors.NewModelNotFoundError("app", "hocus-pocus") runCommand("hocus-pocus") Expect(ui.Outputs).To(ContainSubstrings( []string{"FAILED"}, []string{"not found"}, )) }) Context("when the app has at least one env var", func() { BeforeEach(func() { app = models.Application{} app.Name = "my-app" app.Guid = "the-app-guid" appRepo.ReadReturns.App = app
It("shows an error when deletion fails", func() { quotaRepo.DeleteReturns(errors.New("some error")) runCommand("-f", "my-quota") Expect(ui.Outputs).To(ContainSubstrings( []string{"Deleting", "my-quota"}, []string{"FAILED"}, )) }) }) Context("when finding the quota fails", func() { Context("when the quota provided does not exist", func() { BeforeEach(func() { quotaRepo.FindByNameReturns(models.SpaceQuota{}, errors.NewModelNotFoundError("Quota", "non-existent-quota")) }) It("warns the user when that the quota does not exist", func() { runCommand("-f", "non-existent-quota") Expect(ui.Outputs).To(ContainSubstrings( []string{"Deleting", "non-existent-quota"}, []string{"OK"}, )) Expect(ui.WarnOutputs).To(ContainSubstrings( []string{"non-existent-quota", "does not exist"}, )) }) })
[]string{"Deleting route", "my-host.example.com"}, []string{"OK"}, )) Expect(routeRepo.DeletedRouteGuids).To(Equal([]string{"route-guid"})) }) It("does not prompt the user to confirm when they pass the '-f' flag", func() { ui.Inputs = []string{} runCommand("-f", "-n", "my-host", "example.com") Expect(ui.Prompts).To(BeEmpty()) Expect(ui.Outputs).To(ContainSubstrings( []string{"Deleting", "my-host.example.com"}, []string{"OK"}, )) Expect(routeRepo.DeletedRouteGuids).To(Equal([]string{"route-guid"})) }) It("succeeds with a warning when the route does not exist", func() { routeRepo.FindByHostAndDomainReturns.Error = errors.NewModelNotFoundError("Org", "not found") runCommand("-n", "my-host", "example.com") Expect(ui.WarnOutputs).To(ContainSubstrings([]string{"my-host", "does not exist"})) Expect(ui.Outputs).ToNot(ContainSubstrings([]string{"OK"})) }) }) })