mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-27 10:19:35 +00:00
33 lines
886 B
Go
33 lines
886 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"path/filepath"
|
|
)
|
|
|
|
// pixiecoreHandler returns a handler that renders Boot Configs as JSON to
|
|
// implement the Pixiecore API specification.
|
|
// https://github.com/danderson/pixiecore/blob/master/README.api.md
|
|
func pixiecoreHandler(store Store) http.Handler {
|
|
fn := func(w http.ResponseWriter, req *http.Request) {
|
|
macAddr, err := parseMAC(filepath.Base(req.URL.Path))
|
|
if err != nil {
|
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
|
}
|
|
// pixiecore only provides MAC addresses
|
|
attrs := MachineAttrs{MAC: macAddr}
|
|
log.Infof("pixiecore boot config request for %+v", attrs)
|
|
|
|
config, err := store.BootConfig(attrs)
|
|
if err != nil {
|
|
http.NotFound(w, req)
|
|
return
|
|
}
|
|
if err := json.NewEncoder(w).Encode(config); err != nil {
|
|
log.Infof("error writing to response, %s", err)
|
|
}
|
|
}
|
|
return http.HandlerFunc(fn)
|
|
}
|