forked from concourse/concourse
/
list_inputs.go
85 lines (70 loc) · 1.95 KB
/
list_inputs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package jobserver
import (
"encoding/json"
"net/http"
"github.com/pf-qiu/concourse/v6/atc"
"github.com/pf-qiu/concourse/v6/atc/api/present"
"github.com/pf-qiu/concourse/v6/atc/db"
)
func (s *Server) ListJobInputs(pipeline db.Pipeline) http.Handler {
logger := s.logger.Session("list-job-inputs")
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
jobName := r.FormValue(":job_name")
job, found, err := pipeline.Job(jobName)
if err != nil {
logger.Error("failed-to-get-job", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
resources, err := pipeline.Resources()
if err != nil {
logger.Error("failed-to-get-resources", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
buildInputs, found, err := job.GetFullNextBuildInputs()
if err != nil {
logger.Error("failed-to-get-next-build-inputs", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
jobConfig, err := job.Config()
if err != nil {
logger.Error("failed-to-get-job-config", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
jobInputs := jobConfig.Inputs()
inputs := make([]atc.BuildInput, len(buildInputs))
for i, input := range buildInputs {
var config atc.JobInputParams
for _, jobInput := range jobInputs {
if jobInput.Name == input.Name {
config = jobInput
break
}
}
resource, found := resources.Lookup(config.Resource)
if !found {
logger.Debug("resource-is-not-found")
w.WriteHeader(http.StatusInternalServerError)
return
}
inputs[i] = present.BuildInput(input, config, resource)
}
err = json.NewEncoder(w).Encode(inputs)
if err != nil {
logger.Error("failed-to-encode-build-inputs", err)
w.WriteHeader(http.StatusInternalServerError)
}
})
}