Files
matchbox/bootcfg/api/pixiecore.go
Dalton Hubble 0d148581b9 bootcfg/api: Switch from api types to storagepb types
* Remove api.Store and use storagepb.Store instead
* Remove api.Spec and use storagepb.Profile instead
* Switch from api.Group to storagepb.Group
* Move api.Group to config for YAML config decoding only
2016-03-10 18:32:57 -08:00

36 lines
953 B
Go

package api
import (
"net/http"
"path/filepath"
"github.com/coreos/coreos-baremetal/bootcfg/storage"
)
// pixiecoreHandler returns a handler that renders the boot config JSON for
// the requester, to implement the Pixiecore API specification.
// https://github.com/danderson/pixiecore/blob/master/README.api.md
func pixiecoreHandler(gr *groupsResource, store storage.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 := map[string]string{"mac": macAddr.String()}
group, err := gr.findMatch(attrs)
if err != nil {
http.NotFound(w, req)
return
}
profile, err := store.ProfileGet(group.Profile)
if err != nil {
http.NotFound(w, req)
return
}
renderJSON(w, profile.Boot)
}
return http.HandlerFunc(fn)
}