debian-forge-composer/cmd/osbuild-worker-executor/handler_result.go
Michael Vogt 372d9f07dd cmd/osbuild-worker-executor: import verbatim from mvo5/oaas
This commit imports the repository https://github.com/mvo5/oaas
without keeping the history. The history is largely unimportant
and can be looked up in https://github.com/mvo5/oaas/commits/main
if needed.
2024-06-05 18:26:08 +02:00

43 lines
1 KiB
Go

package main
import (
"io"
"net/http"
"os"
"path/filepath"
"github.com/sirupsen/logrus"
)
func handleResult(logger *logrus.Logger, config *Config) http.Handler {
return http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
logger.Debugf("handlerResult called on %s", r.URL.Path)
if r.Method != http.MethodGet {
http.Error(w, "result endpoint only supports Get", http.StatusMethodNotAllowed)
return
}
buildResult := newBuildResult(config)
switch {
case buildResult.Bad():
http.Error(w, "build failed", http.StatusBadRequest)
f, err := os.Open(filepath.Join(config.BuildDirBase, "build/build.log"))
if err != nil {
logger.Errorf("cannot open log: %v", err)
return
}
defer f.Close()
io.Copy(w, f)
return
case buildResult.Good():
// good result
default:
http.Error(w, "build still running", http.StatusTooEarly)
return
}
fss := http.FileServer(http.Dir(filepath.Join(config.BuildDirBase, "build/output")))
fss.ServeHTTP(w, r)
},
)
}