Exemplo n.º 1
0
func (db *SQLDB) GetConfig(teamName, pipelineName string) (atc.Config, atc.RawConfig, ConfigVersion, error) {
	var configBlob []byte
	var version int
	err := db.conn.QueryRow(`
		SELECT config, version
		FROM pipelines
		WHERE name = $1 AND team_id = (
			SELECT id
			FROM teams
			WHERE name = $2
		)
	`, pipelineName, teamName).Scan(&configBlob, &version)
	if err != nil {
		if err == sql.ErrNoRows {
			return atc.Config{}, atc.RawConfig(""), 0, nil
		}
		return atc.Config{}, atc.RawConfig(""), 0, err
	}

	var config atc.Config
	err = json.Unmarshal(configBlob, &config)
	if err != nil {
		return atc.Config{}, atc.RawConfig(string(configBlob)), ConfigVersion(version), atc.MalformedConfigError{err}
	}

	return config, atc.RawConfig(string(configBlob)), ConfigVersion(version), nil
}
Exemplo n.º 2
0
func (team *team) PipelineConfig(pipelineName string) (atc.Config, atc.RawConfig, string, bool, error) {
	params := rata.Params{
		"pipeline_name": pipelineName,
		"team_name":     team.name,
	}

	var configResponse atc.ConfigResponse

	responseHeaders := http.Header{}
	response := internal.Response{
		Headers: &responseHeaders,
		Result:  &configResponse,
	}
	err := team.connection.Send(internal.Request{
		RequestName: atc.GetConfig,
		Params:      params,
	}, &response)

	switch err.(type) {
	case nil:
		version := responseHeaders.Get(atc.ConfigVersionHeader)

		if len(configResponse.Errors) > 0 {
			return atc.Config{}, configResponse.RawConfig, version, false, PipelineConfigError{configResponse.Errors}
		}

		return *configResponse.Config, configResponse.RawConfig, version, true, nil
	case internal.ResourceNotFoundError:
		return atc.Config{}, atc.RawConfig(""), "", false, nil
	default:
		return atc.Config{}, atc.RawConfig(""), "", false, err
	}
}
Exemplo n.º 3
0
							var printedConfig atc.Config
							err = json.Unmarshal(sess.Out.Contents(), &printedConfig)
							Expect(err).NotTo(HaveOccurred())

							Expect(printedConfig).To(Equal(config))
						})
					})
				})

				Context("when atc returns an error loading config", func() {
					BeforeEach(func() {
						configResponse := atc.ConfigResponse{
							Errors: []string{"invalid-config"},
							RawConfig: atc.RawConfig(`{
								"foo":{"bar": [1, 2, 3]},
								"baz":"quux"
							}`),
						}
						atcServer.AppendHandlers(
							ghttp.CombineHandlers(
								ghttp.VerifyRequest("GET", path),
								ghttp.RespondWithJSONEncoded(200, configResponse, http.Header{atc.ConfigVersionHeader: {"42"}}),
							),
						)
					})

					It("prints raw config as yaml with error", func() {
						flyCmd := exec.Command(flyPath, "-t", targetName, "get-pipeline", "--pipeline", "some-pipeline")

						sess, err := gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
						Expect(err).NotTo(HaveOccurred())
Exemplo n.º 4
0
					Jobs: atc.JobConfigs{
						{
							Name:   "some-job",
							Public: true,
							Serial: true,
						},
						{
							Name: "some-other-job",
						},
					},
				}

				expectedVersion = "42"

				expectedRawConfig = atc.RawConfig("raw-config")

				configResponse := atc.ConfigResponse{
					Config:    &expectedConfig,
					RawConfig: expectedRawConfig,
				}

				atcServer.AppendHandlers(
					ghttp.CombineHandlers(
						ghttp.VerifyRequest("GET", expectedURL),
						ghttp.RespondWithJSONEncoded(http.StatusOK, configResponse, http.Header{atc.ConfigVersionHeader: {expectedVersion}}),
					),
				)
			})

			It("returns the given config and version for that pipeline", func() {