forked from vmware-archive/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
91 lines (76 loc) · 2.13 KB
/
get.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
86
87
88
89
90
91
package configserver
import (
"encoding/json"
"fmt"
"net/http"
"code.cloudfoundry.org/lager"
"github.com/concourse/atc"
"github.com/tedsuo/rata"
)
func (s *Server) GetConfig(w http.ResponseWriter, r *http.Request) {
logger := s.logger.Session("get-config")
pipelineName := rata.Param(r, "pipeline_name")
teamName := rata.Param(r, "team_name")
team, found, err := s.teamFactory.FindTeam(teamName)
if err != nil {
logger.Error("failed-to-find-team", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
logger.Debug("team-not-found", lager.Data{"team": teamName})
w.WriteHeader(http.StatusNotFound)
return
}
pipeline, found, err := team.Pipeline(pipelineName)
if err != nil {
logger.Error("failed-to-find-pipeline", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
logger.Debug("pipeline-not-found", lager.Data{"pipeline": pipelineName})
w.WriteHeader(http.StatusNotFound)
return
}
jobs, err := pipeline.Jobs()
if err != nil {
logger.Error("failed-to-get-jobs", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
resources, err := pipeline.Resources()
if err != nil {
logger.Error("failed-to-get-resources", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
resourceTypes, err := pipeline.ResourceTypes()
if err != nil {
logger.Error("failed-to-get-resourceTypes", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
config := atc.Config{
Groups: pipeline.Groups(),
Resources: resources.Configs(),
ResourceTypes: resourceTypes.Configs(),
Jobs: jobs.Configs(),
}
rawConfig, err := json.Marshal(config)
if err != nil {
logger.Error("failed-to-marshal-config", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Set(atc.ConfigVersionHeader, fmt.Sprintf("%d", pipeline.ConfigVersion()))
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(atc.ConfigResponse{
Config: &config,
RawConfig: atc.RawConfig(rawConfig),
})
if err != nil {
logger.Error("failed-to-encode-config", err)
w.WriteHeader(http.StatusInternalServerError)
}
}