forked from vmware-archive/atc
/
preparation.go
35 lines (29 loc) · 891 Bytes
/
preparation.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
package buildserver
import (
"encoding/json"
"net/http"
"code.cloudfoundry.org/lager"
"github.com/concourse/atc/api/present"
"github.com/concourse/atc/db"
)
func (s *Server) GetBuildPreparation(build db.Build) http.Handler {
logger := s.logger.Session("build-preparation", lager.Data{"build-id": build.ID()})
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
prep, found, err := build.Preparation()
if err != nil {
logger.Error("cannot-find-build-preparation", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if !found {
w.WriteHeader(http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(present.BuildPreparation(prep))
if err != nil {
logger.Error("failed-to-encode-build-preparation", err)
w.WriteHeader(http.StatusInternalServerError)
}
})
}