Files
matchbox/api/pixiecore.go
Dalton Hubble ccd3c7a839 api: Associate machines' attribute labels to specs by group matchers
* Use YAML group config to match machine labels to groups of zero or
more machines sharing a Specification
* Discontinue using machine.json resources representations which are
repetitive, don't support groups, and don't allow label matching
* Previous "default" special case now handled by a Group with an empty
matcher
2016-01-07 23:24:05 -08:00

29 lines
766 B
Go

package api
import (
"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)
return
}
// pixiecore only provides MAC addresses
attrs := LabelSet(map[string]string{"mac": macAddr.String()})
spec, err := getMatchingSpec(store, attrs)
if err != nil {
http.NotFound(w, req)
return
}
renderJSON(w, spec.BootConfig)
}
return http.HandlerFunc(fn)
}