Esempio n. 1
0
File: hijack.go Progetto: mmb/fly
func constructRequest(reqGenerator *rata.RequestGenerator, spec atc.HijackProcessSpec, id string, token *rc.TargetToken) *http.Request {
	payload, err := json.Marshal(spec)
	if err != nil {
		log.Fatalln("failed to marshal process spec:", err)
	}

	hijackReq, err := reqGenerator.CreateRequest(
		atc.HijackContainer,
		rata.Params{"id": id},
		bytes.NewBuffer(payload),
	)
	if err != nil {
		log.Fatalln("failed to create hijack request:", err)
	}

	if token != nil {
		hijackReq.Header.Add("Authorization", token.Type+" "+token.Value)
	}

	return hijackReq
}
Esempio n. 2
0
func constructRequest(reqGenerator *rata.RequestGenerator, spec atc.HijackProcessSpec, reqValues url.Values) *http.Request {
	payload, err := json.Marshal(spec)
	if err != nil {
		log.Fatalln("failed to marshal process spec:", err)
	}

	hijackReq, err := reqGenerator.CreateRequest(
		atc.Hijack,
		rata.Params{},
		bytes.NewBuffer(payload),
	)
	if err != nil {
		log.Fatalln("failed to create hijack request:", err)
	}

	if hijackReq.URL.User != nil {
		hijackReq.Header.Add("Authorization", basicAuth(hijackReq.URL.User))
		hijackReq.URL.User = nil
	}

	hijackReq.URL.RawQuery = reqValues.Encode()

	return hijackReq
}
Esempio n. 3
0
							},
						},
					},
				},
			},
		}
	})

	Describe("GET /api/v1/pipelines/:name/config", func() {
		var (
			response *http.Response
		)

		JustBeforeEach(func() {
			req, err := requestGenerator.CreateRequest(atc.GetConfig, rata.Params{
				"pipeline_name": "something-else",
			}, nil)
			Expect(err).NotTo(HaveOccurred())

			response, err = client.Do(req)
			Expect(err).NotTo(HaveOccurred())
		})

		Context("when authenticated", func() {
			BeforeEach(func() {
				authValidator.IsAuthenticatedReturns(true)
			})

			Context("when the config can be loaded", func() {
				BeforeEach(func() {
					configDB.GetConfigReturns(config, 1, nil)
Esempio n. 4
0
		})

		AfterEach(func() {
			cliRunner.StopAPIServer()
		})

		Context("when the store is fresh", func() {
			BeforeEach(func() {
				simulator.Tick(simulator.TicksToAttainFreshness)
				cliRunner.StartAPIServer(simulator.currentTimestamp)
			})

			It("returns the apps", func() {
				getAppstatus, err := requestGenerator.CreateRequest(
					"bulk_app_state",
					nil,
					bytes.NewBufferString(validRequest),
				)
				Expect(err).NotTo(HaveOccurred())

				getAppstatus.SetBasicAuth(username, password)
				response, err := httpClient.Do(getAppstatus)
				Expect(err).NotTo(HaveOccurred())
				defer response.Body.Close()

				Expect(response.StatusCode).To(Equal(http.StatusOK))

				bodyBytes, err := ioutil.ReadAll(response.Body)
				Expect(err).NotTo(HaveOccurred())
				bodyString := string(bodyBytes)
Esempio n. 5
0
				instanceKey0 := models.NewActualLRPInstanceKey("some-instance-guid-0", "cell-id")

				err := bbsClient.ClaimActualLRP("some-process-guid", 0, &instanceKey0)
				Expect(err).NotTo(HaveOccurred())

				lrpKey1 := models.NewActualLRPKey("some-process-guid", 1, "some-domain")
				instanceKey1 := models.NewActualLRPInstanceKey("some-instance-guid-1", "cell-id")
				netInfo := models.NewActualLRPNetInfo("1.2.3.4", models.NewPortMapping(65100, 8080))
				err = bbsClient.StartActualLRP(&lrpKey1, &instanceKey1, &netInfo)
				Expect(err).NotTo(HaveOccurred())
			})

			It("reports the state of the given process guid's instances", func() {
				getLRPs, err := requestGenerator.CreateRequest(
					tps.LRPStatus,
					rata.Params{"guid": "some-process-guid"},
					nil,
				)
				Expect(err).NotTo(HaveOccurred())

				response, err := httpClient.Do(getLRPs)
				Expect(err).NotTo(HaveOccurred())

				var lrpInstances []cc_messages.LRPInstance
				err = json.NewDecoder(response.Body).Decode(&lrpInstances)
				Expect(err).NotTo(HaveOccurred())

				Expect(lrpInstances).To(HaveLen(3))
				for i, _ := range lrpInstances {
					Expect(lrpInstances[i]).NotTo(BeZero())
					lrpInstances[i].Since = 0
Esempio n. 6
0
func getBuild(client *http.Client, reqGenerator *rata.RequestGenerator, jobName string, buildName string, pipelineName string) atc.Build {
	if pipelineName != "" && jobName == "" {
		fmt.Fprintln(os.Stderr, "job must be specified if pipeline is specified")
		os.Exit(1)
	}

	if pipelineName == "" {
		pipelineName = atc.DefaultPipelineName
	}

	if buildName != "" {
		var buildReq *http.Request
		var err error

		if jobName != "" {
			buildReq, err = reqGenerator.CreateRequest(
				atc.GetJobBuild,
				rata.Params{
					"job_name":      jobName,
					"build_name":    buildName,
					"pipeline_name": pipelineName,
				},
				nil,
			)
		} else {
			buildReq, err = reqGenerator.CreateRequest(
				atc.GetBuild,
				rata.Params{"build_id": buildName},
				nil,
			)
		}

		if err != nil {
			log.Fatalln("failed to create request", err)
		}

		buildResp, err := client.Do(buildReq)
		if err != nil {
			log.Fatalln("failed to get builds:", err)
		}

		if buildResp.StatusCode != http.StatusOK {
			log.Println("bad response when getting build:")
			buildResp.Body.Close()
			buildResp.Write(os.Stderr)
			os.Exit(1)
		}

		var build atc.Build
		err = json.NewDecoder(buildResp.Body).Decode(&build)
		if err != nil {
			log.Fatalln("failed to decode job:", err)
		}

		return build
	} else if jobName != "" {
		jobReq, err := reqGenerator.CreateRequest(
			atc.GetJob,
			rata.Params{"job_name": jobName, "pipeline_name": pipelineName},
			nil,
		)
		if err != nil {
			log.Fatalln("failed to create request", err)
		}

		jobResp, err := client.Do(jobReq)
		if err != nil {
			log.Fatalln("failed to get builds:", err)
		}

		if jobResp.StatusCode != http.StatusOK {
			log.Println("bad response when getting job:")
			jobResp.Body.Close()
			jobResp.Write(os.Stderr)
			os.Exit(1)
		}

		var job atc.Job
		err = json.NewDecoder(jobResp.Body).Decode(&job)
		if err != nil {
			log.Fatalln("failed to decode job:", err)
		}

		if job.NextBuild != nil {
			return *job.NextBuild
		} else if job.FinishedBuild != nil {
			return *job.FinishedBuild
		} else {
			println("job has no builds")
			os.Exit(1)
		}
	} else {
		buildsReq, err := reqGenerator.CreateRequest(
			atc.ListBuilds,
			nil,
			nil,
		)
		if err != nil {
			log.Fatalln("failed to create request", err)
		}

		buildsResp, err := client.Do(buildsReq)
		if err != nil {
			log.Fatalln("failed to get builds:", err)
		}

		if buildsResp.StatusCode != http.StatusOK {
			log.Println("bad response when getting builds:")
			buildsResp.Body.Close()
			buildsResp.Write(os.Stderr)
			os.Exit(1)
		}

		var builds []atc.Build
		err = json.NewDecoder(buildsResp.Body).Decode(&builds)
		if err != nil {
			log.Fatalln("failed to decode builds:", err)
		}

		for _, build := range builds {
			if build.JobName == "" {
				return build
			}
		}

		println("no builds")
		os.Exit(1)
	}

	panic("unreachable")
}
Esempio n. 7
0
					err = desireTaskRequest.Unmarshal(data)
					Expect(err).NotTo(HaveOccurred())

					Expect(desireTaskRequest.TaskDefinition.MemoryMb).To(Equal(int32(1024)))
					Expect(desireTaskRequest.TaskDefinition.DiskMb).To(Equal(int32(128)))
					Expect(desireTaskRequest.TaskDefinition.CompletionCallbackUrl).To(Equal(callbackURL))
				})

				req, err := requestGenerator.CreateRequest(stager.StageRoute, rata.Params{"staging_guid": "my-task-guid"}, strings.NewReader(`{
					"app_id":"my-app-guid",
					"file_descriptors":3,
					"memory_mb" : 1024,
					"disk_mb" : 128,
					"environment" : [],
					"lifecycle": "buildpack",
					"lifecycle_data": {
					  "buildpacks" : [],
						"stack":"linux",
					  "app_bits_download_uri":"http://example.com/app_bits"
					}
				}`))
				Expect(err).NotTo(HaveOccurred())
				req.Header.Set("Content-Type", "application/json")

				resp, err := httpClient.Do(req)
				Expect(err).NotTo(HaveOccurred())
				Expect(resp.StatusCode).To(Equal(http.StatusAccepted))

				Eventually(fakeBBS.ReceivedRequests).Should(HaveLen(1))
				Consistently(runner.Session()).ShouldNot(gexec.Exit())
Esempio n. 8
0
		process ifrit.Process
	)

	requestDesireWithInstances := func(nInstances int) (*http.Response, error) {
		req, err := requestGenerator.CreateRequest(nsync.DesireAppRoute, rata.Params{"process_guid": "the-guid"}, strings.NewReader(`{
        "process_guid": "the-guid",
        "droplet_uri": "http://the-droplet.uri.com",
        "start_command": "the-start-command",
        "execution_metadata": "execution-metadata-1",
        "memory_mb": 128,
        "disk_mb": 512,
        "file_descriptors": 32,
        "num_instances": `+strconv.Itoa(nInstances)+`,
        "stack": "some-stack",
        "log_guid": "the-log-guid",
        "health_check_timeout_in_seconds": 123456,
        "ports": [8080,5222],
        "etag": "2.1",
        "routing_info": {
			"http_routes": [
			{"hostname": "route-1"}
			],
			"tcp_routes": [
			{"router_group_guid": "guid-1", "external_port":5222, "container_port":60000}
			]
		}
			}`))
		Expect(err).NotTo(HaveOccurred())
		req.Header.Set("Content-Type", "application/json")

		return httpClient.Do(req)