コード例 #1
0
ファイル: create_buildpack.go プロジェクト: nsnt/cli
func (cmd CreateBuildpack) createBuildpack(buildpackName string, c *cli.Context) (buildpack cf.Buildpack, apiResponse net.ApiResponse) {
	position, err := strconv.Atoi(c.Args()[2])
	if err != nil {
		apiResponse = net.NewApiResponseWithMessage("Invalid position. %s", err.Error())
		return
	}

	enabled := c.Bool("enable")
	disabled := c.Bool("disable")
	if enabled && disabled {
		apiResponse = net.NewApiResponseWithMessage("Cannot specify both enabled and disabled.")
		return
	}

	var enableOption *bool = nil
	if enabled {
		enableOption = &enabled
	}
	if disabled {
		disabled = false
		enableOption = &disabled
	}

	buildpack, apiResponse = cmd.buildpackRepo.Create(buildpackName, &position, enableOption)

	return
}
コード例 #2
0
ファイル: application_bits.go プロジェクト: rodney-vin/cli
func (repo CloudControllerApplicationBitsRepository) UploadApp(appGuid string, appDir string, cb func(path string, zipSize, fileCount uint64)) (apiResponse net.ApiResponse) {
	fileutils.TempDir("apps", func(uploadDir string, err error) {
		if err != nil {
			apiResponse = net.NewApiResponseWithMessage(err.Error())
			return
		}

		var presentResourcesJson []byte
		repo.sourceDir(appDir, func(sourceDir string, sourceErr error) {
			if sourceErr != nil {
				err = sourceErr
				return
			}
			presentResourcesJson, err = repo.copyUploadableFiles(sourceDir, uploadDir)
		})

		if err != nil {
			apiResponse = net.NewApiResponseWithMessage("%s", err)
			return
		}

		fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
			if err != nil {
				apiResponse = net.NewApiResponseWithMessage("%s", err.Error())
				return
			}

			err = repo.zipper.Zip(uploadDir, zipFile)
			if err != nil {
				apiResponse = net.NewApiResponseWithError("Error zipping application", err)
				return
			}

			stat, err := zipFile.Stat()
			if err != nil {
				apiResponse = net.NewApiResponseWithError("Error zipping application", err)
				return
			}
			cb(appDir, uint64(stat.Size()), cf.CountFiles(uploadDir))

			apiResponse = repo.uploadBits(appGuid, zipFile, presentResourcesJson)
			if apiResponse.IsNotSuccessful() {
				return
			}
		})
	})
	return
}
コード例 #3
0
ファイル: fake_route_repo.go プロジェクト: nsnt/cli
func (repo *FakeRouteRepository) ListRoutes(stop chan bool) (routesChan chan []cf.Route, statusChan chan net.ApiResponse) {
	routesChan = make(chan []cf.Route, 4)
	statusChan = make(chan net.ApiResponse, 1)

	if repo.ListErr {
		statusChan <- net.NewApiResponseWithMessage("Error finding all routes")
		close(routesChan)
		close(statusChan)
		return
	}

	go func() {
		routesCount := len(repo.Routes)
		for i := 0; i < routesCount; i += 2 {
			select {
			case <-stop:
				break
			default:
				if routesCount-i > 1 {
					routesChan <- repo.Routes[i : i+2]
				} else {
					routesChan <- repo.Routes[i:]
				}
			}
		}

		close(routesChan)
		close(statusChan)

		cf.WaitForClose(stop)
	}()

	return
}
コード例 #4
0
ファイル: fake_service_broker_repo.go プロジェクト: nsnt/cli
func (repo *FakeServiceBrokerRepo) ListServiceBrokers(stop chan bool) (serviceBrokersChan chan []cf.ServiceBroker, statusChan chan net.ApiResponse) {
	serviceBrokersChan = make(chan []cf.ServiceBroker, 4)
	statusChan = make(chan net.ApiResponse, 1)

	if repo.ListErr {
		statusChan <- net.NewApiResponseWithMessage("Error finding all routes")
		close(serviceBrokersChan)
		close(statusChan)
		return
	}

	go func() {
		serviceBrokersCount := len(repo.ServiceBrokers)
		for i := 0; i < serviceBrokersCount; i += 2 {
			select {
			case <-stop:
				break
			default:
				if serviceBrokersCount-i > 1 {
					serviceBrokersChan <- repo.ServiceBrokers[i : i+2]
				} else {
					serviceBrokersChan <- repo.ServiceBrokers[i:]
				}
			}
		}

		close(serviceBrokersChan)
		close(statusChan)

		cf.WaitForClose(stop)
	}()

	return
}
コード例 #5
0
ファイル: delete_buildpack_test.go プロジェクト: nsnt/cli
func TestDeleteBuildpackDeleteError(t *testing.T) {
	ui := &testterm.FakeUI{Inputs: []string{"y"}}
	buildpack := cf.Buildpack{}
	buildpack.Name = "my-buildpack"
	buildpack.Guid = "my-buildpack-guid"
	buildpackRepo := &testapi.FakeBuildpackRepository{
		FindByNameBuildpack: buildpack,
		DeleteApiResponse:   net.NewApiResponseWithMessage("failed badly"),
	}

	cmd := NewDeleteBuildpack(ui, buildpackRepo)

	ctxt := testcmd.NewContext("delete-buildpack", []string{"my-buildpack"})
	reqFactory := &testreq.FakeReqFactory{LoginSuccess: true}

	testcmd.RunCommand(cmd, ctxt, reqFactory)

	assert.Equal(t, buildpackRepo.DeleteBuildpackGuid, "my-buildpack-guid")

	testassert.SliceContains(t, ui.Outputs, testassert.Lines{
		{"Deleting buildpack", "my-buildpack"},
		{"FAILED"},
		{"my-buildpack"},
		{"failed badly"},
	})
}
コード例 #6
0
ファイル: buildpack_bits.go プロジェクト: pmuellr/cli
func (repo CloudControllerBuildpackBitsRepository) uploadBits(buildpack cf.Buildpack, zipFile *os.File) (apiResponse net.ApiResponse) {
	url := fmt.Sprintf("%s/v2/buildpacks/%s/bits", repo.config.Target, buildpack.Guid)

	fileutils.TempFile("requests", func(requestFile *os.File, err error) {
		if err != nil {
			apiResponse = net.NewApiResponseWithMessage(err.Error())
			return
		}

		boundary, err := repo.writeUploadBody(zipFile, requestFile)
		if err != nil {
			apiResponse = net.NewApiResponseWithError("Error creating upload", err)
			return
		}

		request, apiResponse := repo.gateway.NewRequest("PUT", url, repo.config.AccessToken, requestFile)
		contentType := fmt.Sprintf("multipart/form-data; boundary=%s", boundary)
		request.HttpReq.Header.Set("Content-Type", contentType)
		if apiResponse.IsNotSuccessful() {
			return
		}

		apiResponse = repo.gateway.PerformRequest(request)
	})

	return
}
コード例 #7
0
ファイル: services.go プロジェクト: pmuellr/cli
func (repo CloudControllerServiceRepository) DeleteService(instance cf.ServiceInstance) (apiResponse net.ApiResponse) {
	if len(instance.ServiceBindings) > 0 {
		return net.NewApiResponseWithMessage("Cannot delete service instance, apps are still bound to it")
	}
	path := fmt.Sprintf("%s/v2/service_instances/%s", repo.config.Target, instance.Guid)
	return repo.gateway.DeleteResource(path, repo.config.AccessToken)
}
コード例 #8
0
ファイル: endpoints.go プロジェクト: jalateras/cli
func (repo RemoteEndpointRepository) doUpdateEndpoint(endpoint string) (apiResponse net.ApiResponse) {
	request, apiResponse := repo.gateway.NewRequest("GET", endpoint+"/v2/info", "", nil)
	if apiResponse.IsNotSuccessful() {
		return
	}

	type infoResponse struct {
		ApiVersion            string `json:"api_version"`
		AuthorizationEndpoint string `json:"authorization_endpoint"`
	}

	serverResponse := new(infoResponse)
	_, apiResponse = repo.gateway.PerformRequestForJSONResponse(request, &serverResponse)
	if apiResponse.IsNotSuccessful() {
		return
	}

	if endpoint != repo.config.Target {
		repo.configRepo.ClearSession()
	}

	repo.config.Target = endpoint
	repo.config.ApiVersion = serverResponse.ApiVersion
	repo.config.AuthorizationEndpoint = serverResponse.AuthorizationEndpoint

	err := repo.configRepo.Save()
	if err != nil {
		apiResponse = net.NewApiResponseWithMessage(err.Error())
	}
	return
}
コード例 #9
0
ファイル: fake_app_repo.go プロジェクト: jalateras/cli
func (repo *FakeApplicationRepository) Start(app cf.Application) (updatedApp cf.Application, apiResponse net.ApiResponse) {
	repo.StartAppToStart = app
	if repo.StartAppErr {
		apiResponse = net.NewApiResponseWithMessage("Error starting application")
	}
	updatedApp = repo.StartUpdatedApp
	return
}
コード例 #10
0
func (repo *FakeServiceBrokerRepo) FindAll() (serviceBrokers []cf.ServiceBroker, apiResponse net.ApiResponse) {
	if repo.FindAllErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding all service brokers")
	}

	serviceBrokers = repo.FindAllServiceBrokers
	return
}
コード例 #11
0
ファイル: fake_buildpack_bits_repo.go プロジェクト: nsnt/cli
func (repo *FakeBuildpackBitsRepository) UploadBuildpack(buildpack cf.Buildpack, dir string) net.ApiResponse {
	if repo.UploadBuildpackErr {
		return net.NewApiResponseWithMessage("Invalid buildpack")
	}

	repo.UploadBuildpackPath = dir
	return repo.UploadBuildpackApiResponse
}
コード例 #12
0
ファイル: applications.go プロジェクト: jalateras/cli
func validateApplication(app cf.Application) (apiResponse net.ApiResponse) {
	reg := regexp.MustCompile("^[0-9a-zA-Z\\-_]*$")
	if !reg.MatchString(app.Name) {
		apiResponse = net.NewApiResponseWithMessage("App name is invalid: name can only contain letters, numbers, underscores and hyphens")
	}

	return
}
コード例 #13
0
ファイル: fake_route_repo.go プロジェクト: jalateras/cli
func (repo *FakeRouteRepository) FindAll() (routes []cf.Route, apiResponse net.ApiResponse) {
	if repo.FindAllErr {
		apiResponse = net.NewApiResponseWithMessage("Error finding all routes")
	}

	routes = repo.FindAllRoutes
	return
}
コード例 #14
0
ファイル: endpoints.go プロジェクト: jalateras/cli
func (repo RemoteEndpointRepository) cloudControllerEndpoint() (endpoint string, apiResponse net.ApiResponse) {
	if repo.config.Target == "" {
		apiResponse = net.NewApiResponseWithMessage("Endpoint missing from config file")
		return
	}

	endpoint = repo.config.Target
	return
}
コード例 #15
0
ファイル: endpoints.go プロジェクト: nsnt/cli
func (repo RemoteEndpointRepository) GetLoggregatorEndpoint() (endpoint string, apiResponse net.ApiResponse) {
	if repo.config.LoggregatorEndPoint == "" {
		apiResponse = net.NewApiResponseWithMessage("Loggregator endpoint missing from config file")
		return
	}

	endpoint = repo.config.LoggregatorEndPoint
	return
}
コード例 #16
0
ファイル: fake_app_repo.go プロジェクト: normalnorman/cli
func (repo *FakeApplicationRepository) Update(appGuid string, params models.AppParams) (updatedApp models.Application, apiResponse net.ApiResponse) {
	repo.UpdateAppGuid = appGuid
	repo.UpdateParams = params
	updatedApp = repo.UpdateAppResult
	if repo.UpdateErr {
		apiResponse = net.NewApiResponseWithMessage("Error updating app.")
	}
	return
}
コード例 #17
0
ファイル: fake_app_repo.go プロジェクト: jalateras/cli
func (repo *FakeApplicationRepository) SetEnv(app cf.Application, envVars map[string]string) (apiResponse net.ApiResponse) {
	repo.SetEnvApp = app
	repo.SetEnvVars = envVars

	if repo.SetEnvErr {
		apiResponse = net.NewApiResponseWithMessage("Failed setting env")
	}
	return
}
コード例 #18
0
ファイル: endpoints.go プロジェクト: nimbus-cloud/cli
func (repo RemoteEndpointRepository) GetUAAEndpoint() (endpoint string, apiResponse net.ApiResponse) {
	if repo.config.AuthorizationEndpoint() == "" {
		apiResponse = net.NewApiResponseWithMessage("UAA endpoint missing from config file")
		return
	}

	endpoint = strings.Replace(repo.config.AuthorizationEndpoint(), "login", "uaa", 1)

	return
}
コード例 #19
0
ファイル: users.go プロジェクト: jalateras/cli
func (repo CloudControllerUserRepository) checkSpaceRole(user cf.User, space cf.Space, role string) (fullPath string, apiResponse net.ApiResponse) {
	rolePath, found := spaceRoleToPathMap[role]

	if !found {
		apiResponse = net.NewApiResponseWithMessage("Invalid Role %s", role)
	}

	fullPath = fmt.Sprintf("%s/v2/spaces/%s/%s/%s", repo.config.Target, space.Guid, rolePath, user.Guid)
	return
}
コード例 #20
0
ファイル: fake_route_repo.go プロジェクト: jalateras/cli
func (repo *FakeRouteRepository) FindByHost(host string) (route cf.Route, apiResponse net.ApiResponse) {
	repo.FindByHostHost = host

	if repo.FindByHostErr {
		apiResponse = net.NewApiResponseWithMessage("Route not found")
	}

	route = repo.FindByHostRoute
	return
}
コード例 #21
0
ファイル: login.go プロジェクト: jalateras/cli
func (cmd Login) targetSpace(space cf.Space) (apiResponse net.ApiResponse) {
	err := cmd.configRepo.SetSpace(space)
	if err != nil {
		apiResponse = net.NewApiResponseWithMessage("Error setting space %s in config file\n%s",
			terminal.EntityNameColor(space.Name),
			err.Error(),
		)
	}
	return
}
コード例 #22
0
ファイル: endpoints.go プロジェクト: jalateras/cli
func (repo RemoteEndpointRepository) uaaControllerEndpoint() (endpoint string, apiResponse net.ApiResponse) {
	if repo.config.AuthorizationEndpoint == "" {
		apiResponse = net.NewApiResponseWithMessage("Endpoint missing from config file")
		return
	}

	endpoint = strings.Replace(repo.config.AuthorizationEndpoint, authEndpointPrefix, uaaEndpointPrefix, 1)

	return
}
コード例 #23
0
ファイル: fake_app_bits_repo.go プロジェクト: jalateras/cli
func (repo *FakeApplicationBitsRepository) UploadApp(app cf.Application, dir string) (apiResponse net.ApiResponse) {
	repo.UploadedDir = dir
	repo.UploadedApp = app

	if repo.UploadAppErr {
		apiResponse = net.NewApiResponseWithMessage("Error uploading app")
	}

	return
}
コード例 #24
0
ファイル: curl_test.go プロジェクト: nsnt/cli
func TestGetRequestFailsWithError(t *testing.T) {
	deps := newCurlDependencies()

	deps.curlRepo.ApiResponse = net.NewApiResponseWithMessage("ooops")
	runCurlWithInputs(deps, []string{"/foo"})

	testassert.SliceContains(t, deps.ui.Outputs, testassert.Lines{
		{"FAILED"},
		{"ooops"},
	})
}
コード例 #25
0
ファイル: login.go プロジェクト: jalateras/cli
func (cmd Login) targetOrganization(org cf.Organization) (apiResponse net.ApiResponse) {
	err := cmd.configRepo.SetOrganization(org)

	if err != nil {
		apiResponse = net.NewApiResponseWithMessage("Error setting org %s in config file\n%s",
			terminal.EntityNameColor(org.Name),
			err.Error(),
		)
	}
	return
}
コード例 #26
0
ファイル: application_bits.go プロジェクト: jalateras/cli
func (repo CloudControllerApplicationBitsRepository) UploadApp(app cf.Application, appDir string) (apiResponse net.ApiResponse) {
	fileutils.TempDir("apps", func(uploadDir string, err error) {
		if err != nil {
			apiResponse = net.NewApiResponseWithMessage(err.Error())
			return
		}

		var resourcesJson []byte
		repo.sourceDir(appDir, func(sourceDir string, sourceErr error) {
			if sourceErr != nil {
				err = sourceErr
				return
			}
			resourcesJson, err = repo.copyUploadableFiles(sourceDir, uploadDir)
		})

		if err != nil {
			apiResponse = net.NewApiResponseWithMessage(err.Error())
			return
		}

		fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
			if err != nil {
				apiResponse = net.NewApiResponseWithMessage(err.Error())
				return
			}

			err = repo.zipper.Zip(uploadDir, zipFile)
			if err != nil {
				apiResponse = net.NewApiResponseWithError("Error zipping application", err)
				return
			}

			apiResponse = repo.uploadBits(app, zipFile, resourcesJson)
			if apiResponse.IsNotSuccessful() {
				return
			}
		})
	})
	return
}
コード例 #27
0
ファイル: fake_route_repo.go プロジェクト: normalnorman/cli
func (repo *FakeRouteRepository) ListRoutes(cb func(models.Route) bool) (apiResponse net.ApiResponse) {
	if repo.ListErr {
		return net.NewApiResponseWithMessage("WHOOPSIE")
	}

	for _, route := range repo.Routes {
		if !cb(route) {
			break
		}
	}
	return
}
コード例 #28
0
ファイル: fake_domain_repo.go プロジェクト: normalnorman/cli
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
}
コード例 #29
0
ファイル: fake_quota_repo.go プロジェクト: nsnt/cli
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
}
コード例 #30
0
ファイル: fake_route_repo.go プロジェクト: jalateras/cli
func (repo *FakeRouteRepository) CreateInSpace(newRoute cf.Route, domain cf.Domain, space cf.Space) (createdRoute cf.Route, apiResponse net.ApiResponse) {
	repo.CreateInSpaceRoute = newRoute
	repo.CreateInSpaceDomain = domain
	repo.CreateInSpaceSpace = space

	if repo.CreateInSpaceErr {
		apiResponse = net.NewApiResponseWithMessage("Error")
	} else {
		createdRoute = repo.CreateInSpaceCreatedRoute
	}

	return
}