Example #1
0
func (repo CloudControllerServiceRepository) FindServicePlanByDescription(planDescription ServicePlanDescription) (planGuid string, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("%s/v2/services?inline-relations-depth=1&q=label:%s;provider:%s",
		repo.config.ApiEndpoint(),
		planDescription.ServiceName,
		planDescription.ServiceProvider)

	response := new(PaginatedServiceOfferingResources)
	apiResponse = repo.gateway.GetResource(path, repo.config.AccessToken(), response)
	if apiResponse.IsNotSuccessful() {
		return
	}

	for _, serviceOfferingResource := range response.Resources {
		for _, servicePlanResource := range serviceOfferingResource.Entity.ServicePlans {
			if servicePlanResource.Entity.Name == planDescription.ServicePlanName {
				planGuid = servicePlanResource.Metadata.Guid
				return
			}
		}
	}

	apiResponse = net.NewNotFoundApiResponse("Plan %s cannot be found", planDescription)

	return
}
Example #2
0
func (repo *FakeUserRepository) FindByUsername(username string) (user cf.UserFields, apiResponse net.ApiResponse) {
	repo.FindByUsernameUsername = username
	user = repo.FindByUsernameUserFields

	if repo.FindByUsernameNotFound {
		apiResponse = net.NewNotFoundApiResponse("UserFields not found")
	}

	return
}
func (repo *FakeServiceBrokerRepo) FindByName(name string) (serviceBroker cf.ServiceBroker, apiResponse net.ApiResponse) {
	repo.FindByNameName = name
	serviceBroker = repo.FindByNameServiceBroker

	if repo.FindByNameNotFound {
		apiResponse = net.NewNotFoundApiResponse("%s %s not found", "Service Broker", name)
	}

	return
}
Example #4
0
func (repo *FakeBuildpackRepository) FindByName(name string) (buildpack cf.Buildpack, apiResponse net.ApiResponse) {
	repo.FindByNameName = name
	buildpack = repo.FindByNameBuildpack

	if repo.FindByNameNotFound {
		apiResponse = net.NewNotFoundApiResponse("Buildpack %s not found", name)
	}

	return
}
Example #5
0
func TestMapDomainDomainNotFound(t *testing.T) {
	reqFactory, domainRepo := getDomainMapperDeps()
	domainRepo.FindByNameInOrgApiResponse = net.NewNotFoundApiResponse("Domain foo.com not found")
	ui := callDomainMapper(t, true, []string{"my-space", "foo.com"}, reqFactory, domainRepo)

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Mapping domain", "foo.com", "my-space"},
		{"FAILED"},
		{"Error finding", "foo.com"},
	})
}
Example #6
0
func TestMapDomainDomainNotFound(t *testing.T) {
	reqFactory, domainRepo := getDomainMapperDeps()
	domainRepo.FindByNameInOrgApiResponse = net.NewNotFoundApiResponse("Domain foo.com not found")
	ui := callDomainMapper(t, true, []string{"my-space", "foo.com"}, reqFactory, domainRepo)

	assert.Equal(t, len(ui.Outputs), 3)
	assert.Contains(t, ui.Outputs[0], "Mapping domain")
	assert.Contains(t, ui.Outputs[0], "foo.com")
	assert.Contains(t, ui.Outputs[0], "my-space")
	assert.Contains(t, ui.Outputs[1], "FAILED")
	assert.Contains(t, ui.Outputs[2], "foo.com")
}
Example #7
0
func (repo *FakeQuotaRepository) FindByName(name string) (quota cf.QuotaFields, apiResponse net.ApiResponse) {
	repo.FindByNameName = name
	quota = repo.FindByNameQuota

	if repo.FindByNameNotFound {
		apiResponse = net.NewNotFoundApiResponse("%s %s not found", "Org", name)
	}
	if repo.FindByNameErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding quota")
	}

	return
}
Example #8
0
func (repo *FakeDomainRepository) FindByName(name string) (domain models.DomainFields, apiResponse net.ApiResponse) {
	repo.FindByNameName = name
	domain = repo.FindByNameDomain

	if repo.FindByNameNotFound {
		apiResponse = net.NewNotFoundApiResponse("%s %s not found", "Domain", name)
	}
	if repo.FindByNameErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding domain")
	}

	return
}
func TestDeleteServiceAuthTokenWhenTokenDoesNotExist(t *testing.T) {
	authTokenRepo := &testapi.FakeAuthTokenRepo{
		FindByLabelAndProviderApiResponse: net.NewNotFoundApiResponse("not found"),
	}
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}
	args := []string{"a label", "a provider"}

	ui := callDeleteServiceAuthToken(t, args, []string{"Y"}, reqFactory, authTokenRepo)
	assert.Contains(t, ui.Outputs[0], "Deleting service auth token as")
	assert.Contains(t, ui.Outputs[0], "my-user")
	assert.Contains(t, ui.Outputs[1], "OK")
	assert.Contains(t, ui.Outputs[2], "does not exist")
}
Example #10
0
func (repo *FakeSpaceRepository) FindByName(name string) (space cf.Space, apiResponse net.ApiResponse) {
	repo.FindByNameName = name
	space = repo.FindByNameSpace

	if repo.FindByNameErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding space by name.")
	}

	if repo.FindByNameNotFound {
		apiResponse = net.NewNotFoundApiResponse("%s %s not found", "Space", name)
	}

	return
}
Example #11
0
func (repo RemoteEndpointRepository) GetEndpoint(name cf.EndpointType) (endpoint string, apiResponse net.ApiResponse) {
	switch name {
	case cf.CloudControllerEndpointKey:
		return repo.cloudControllerEndpoint()
	case cf.UaaEndpointKey:
		return repo.uaaControllerEndpoint()
	case cf.LoggregatorEndpointKey:
		return repo.loggregatorEndpoint()
	}

	apiResponse = net.NewNotFoundApiResponse("Endpoint type %s is unkown", string(name))

	return
}
Example #12
0
File: domains.go Project: nsnt/cli
func (repo CloudControllerDomainRepository) FindByName(name string) (domain cf.Domain, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("/v2/domains?inline-relations-depth=1&q=%s", url.QueryEscape("name:"+name))
	domains, _, apiResponse := repo.findNextWithPath(path)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(domains) > 0 {
		domain = domains[0]
	} else {
		apiResponse = net.NewNotFoundApiResponse("Domain %s not found", name)
	}
	return
}
Example #13
0
func (repo CloudControllerDomainRepository) FindByNameInOrg(name string, orgGuid string) (domain models.DomainFields, apiResponse net.ApiResponse) {
	domain, apiResponse = repo.findOneWithPath(
		fmt.Sprintf("/v2/organizations/%s/domains?inline-relations-depth=1&q=%s", orgGuid, url.QueryEscape("name:"+name)),
		name)

	if apiResponse.IsNotFound() {
		domain, apiResponse = repo.FindByName(name)
		if !domain.Shared {
			apiResponse = net.NewNotFoundApiResponse("Domain %s not found", name)
		}
	}

	return
}
Example #14
0
func (repo CloudControllerDomainRepository) findOneWithPath(path, name string) (domain models.DomainFields, apiResponse net.ApiResponse) {
	foundDomain := false
	apiResponse = repo.listDomains(path, func(result models.DomainFields) bool {
		domain = result
		foundDomain = true
		return false
	})

	if apiResponse.IsSuccessful() && !foundDomain {
		apiResponse = net.NewNotFoundApiResponse("Domain %s not found", name)
	}

	return
}
Example #15
0
func (repo *FakeOrgRepository) FindByName(name string) (org cf.Organization, apiResponse net.ApiResponse) {
	repo.FindByNameName = name
	org = repo.FindByNameOrganization

	if repo.FindByNameErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding organization by name.")
	}

	if repo.FindByNameNotFound {
		apiResponse = net.NewNotFoundApiResponse("%s %s not found", "Org", name)
	}

	return
}
Example #16
0
func (repo *FakeServiceRepo) FindInstanceByName(name string) (instance cf.ServiceInstance, apiResponse net.ApiResponse) {
	repo.FindInstanceByNameName = name
	instance = repo.FindInstanceByNameServiceInstance

	if repo.FindInstanceByNameErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding instance")
	}

	if repo.FindInstanceByNameNotFound {
		apiResponse = net.NewNotFoundApiResponse("%s %s not found", "Service instance", name)
	}

	return
}
Example #17
0
File: routes.go Project: nsnt/cli
func (repo CloudControllerRouteRepository) findOneWithPath(path string) (route cf.Route, apiResponse net.ApiResponse) {
	routes, _, apiResponse := repo.findNextWithPath(path)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(routes) == 0 {
		apiResponse = net.NewNotFoundApiResponse("Route not found")
		return
	}

	route = routes[0]
	return
}
Example #18
0
func (repo CloudControllerDomainRepository) FindByName(name string) (domain cf.Domain, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("%s/v2/domains?inline-relations-depth=1&q=name%%3A%s", repo.config.Target, name)
	domains, apiResponse := repo.findAllWithPath(path)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(domains) > 0 {
		domain = domains[0]
	} else {
		apiResponse = net.NewNotFoundApiResponse("Domain %s not found", name)
	}
	return
}
Example #19
0
func (repo CloudControllerServiceBrokerRepository) FindByName(name string) (serviceBroker cf.ServiceBroker, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("%s/v2/service_brokers?q=name%%3A%s", repo.config.Target, name)
	serviceBrokers, apiResponse := repo.findAllWithPath(path)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(serviceBrokers) == 0 {
		apiResponse = net.NewNotFoundApiResponse("Service Broker %s not found", name)
		return
	}

	serviceBroker = serviceBrokers[0]
	return
}
Example #20
0
func (repo CloudControllerServiceRepository) FindServiceOfferingByLabelAndProvider(label, provider string) (offering models.ServiceOffering, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("%s/v2/services?q=%s", repo.config.ApiEndpoint(), url.QueryEscape("label:"+label+";provider:"+provider))

	resources := new(PaginatedServiceOfferingResources)
	apiResponse = repo.gateway.GetResource(path, repo.config.AccessToken(), resources)

	if apiResponse.IsError() {
		return
	} else if len(resources.Resources) == 0 {
		apiResponse = net.NewNotFoundApiResponse("Service offering not found")
	} else {
		offering = resources.Resources[0].ToModel()
	}
	return
}
Example #21
0
func (repo CloudControllerServiceAuthTokenRepository) FindByLabelAndProvider(label, provider string) (authToken models.ServiceAuthTokenFields, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("%s/v2/service_auth_tokens?q=%s", repo.config.ApiEndpoint(), url.QueryEscape("label:"+label+";provider:"+provider))
	authTokens, apiResponse := repo.findAllWithPath(path)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(authTokens) == 0 {
		apiResponse = net.NewNotFoundApiResponse("Service Auth Token %s %s not found", label, provider)
		return
	}

	authToken = authTokens[0]
	return
}
Example #22
0
func (repo CloudControllerBuildpackRepository) FindByName(name string) (buildpack cf.Buildpack, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("%s?q=name%%3A%s", buildpacks_path, url.QueryEscape(name))
	buildpacks, _, apiResponse := repo.findNextWithPath(path)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(buildpacks) == 0 {
		apiResponse = net.NewNotFoundApiResponse("%s %s not found", "Buildpack", name)
		return
	}

	buildpack = buildpacks[0]
	return
}
Example #23
0
func (repo *FakeRouteRepository) FindByHostAndDomain(host, domain string) (route cf.Route, apiResponse net.ApiResponse) {
	repo.FindByHostAndDomainHost = host
	repo.FindByHostAndDomainDomain = domain

	if repo.FindByHostAndDomainErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding Route")
	}

	if repo.FindByHostAndDomainNotFound {
		apiResponse = net.NewNotFoundApiResponse("%s %s.%s not found", "Org", host, domain)
	}

	route = repo.FindByHostAndDomainRoute
	return
}
Example #24
0
func (repo CloudControllerQuotaRepository) FindByName(name string) (quota cf.QuotaFields, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("%s/v2/quota_definitions?q=name%%3A%s", repo.config.Target, name)
	quotas, apiResponse := repo.findAllWithPath(path)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(quotas) == 0 {
		apiResponse = net.NewNotFoundApiResponse("Quota %s not found", name)
		return
	}

	quota = quotas[0]
	return
}
Example #25
0
func (repo CloudControllerServiceAuthTokenRepository) FindByLabelAndProvider(label, provider string) (authToken cf.ServiceAuthTokenFields, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("%s/v2/service_auth_tokens?q=label:%s;provider:%s", repo.config.Target, label, provider)
	authTokens, apiResponse := repo.findAllWithPath(path)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(authTokens) == 0 {
		apiResponse = net.NewNotFoundApiResponse("Service Auth Token %s %s not found", label, provider)
		return
	}

	authToken = authTokens[0]
	return
}
Example #26
0
func (repo CloudControllerDomainRepository) FindDefaultAppDomain() (domain cf.Domain, apiResponse net.ApiResponse) {
	sharedPath := fmt.Sprintf("%s/v2/domains?inline-relations-depth=1", repo.config.Target)
	sharedDomains, apiResponse := repo.findAllWithPath(sharedPath)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(sharedDomains) > 0 {
		domain = sharedDomains[0]
	} else {
		apiResponse = net.NewNotFoundApiResponse("No default domain exists")
	}

	return
}
Example #27
0
func (repo CloudControllerServiceBrokerRepository) FindByName(name string) (serviceBroker cf.ServiceBroker, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("/v2/service_brokers?q=%s", url.QueryEscape("name:"+name))
	serviceBrokers, _, apiResponse := repo.findNextWithPath(path)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(serviceBrokers) == 0 {
		apiResponse = net.NewNotFoundApiResponse("Service Broker '%s' not found", name)
		return
	}

	serviceBroker = serviceBrokers[0]
	return
}
Example #28
0
func TestDeleteDomainNotFound(t *testing.T) {
	domainRepo := &testapi.FakeDomainRepository{
		FindByNameInOrgApiResponse: net.NewNotFoundApiResponse("%s %s not found", "Domain", "foo.com"),
	}
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true, TargetedOrgSuccess: true}

	ui := callDeleteDomain(t, []string{"foo.com"}, []string{"y"}, reqFactory, domainRepo)

	assert.Equal(t, domainRepo.DeleteDomainGuid, "")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting domain", "foo.com"},
		{"OK"},
		{"foo.com", "not found"},
	})
}
Example #29
0
File: spaces.go Project: nsnt/cli
func (repo CloudControllerSpaceRepository) FindByNameInOrg(name, orgGuid string) (space cf.Space, apiResponse net.ApiResponse) {
	path := fmt.Sprintf("/v2/organizations/%s/spaces?q=%s&inline-relations-depth=1", orgGuid, url.QueryEscape("name:"+strings.ToLower(name)))

	spaces, _, apiResponse := repo.findNextWithPath(path)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if len(spaces) == 0 {
		apiResponse = net.NewNotFoundApiResponse("Space '%s' not found", name)
		return
	}

	space = spaces[0]
	return
}
Example #30
0
func (repo *FakeApplicationRepository) Read(name string) (app models.Application, apiResponse net.ApiResponse) {
	repo.ReadName = name
	app = repo.ReadApp

	if repo.ReadErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding app by name.")
	}
	if repo.ReadAuthErr {
		apiResponse = net.NewApiResponse("Authentication failed.", "1000", 401)
	}
	if repo.ReadNotFound {
		apiResponse = net.NewNotFoundApiResponse("%s %s not found", "App", name)
	}

	return
}