mirror of
https://github.com/outbackdingo/matchbox.git
synced 2026-01-27 18:19:36 +00:00
* Add gRPC SelectGroup and SelectProfile service endpoints * HTTP and gRPC servers should both allow labels to be resolved to the matching Group or Profile. Move logic to bootcfg core server. * Add gRPC wrapper selectServer to avoid cluttering core server with response types which are currently only useful for gRPC
39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
"github.com/coreos/coreos-baremetal/bootcfg/server"
|
|
pb "github.com/coreos/coreos-baremetal/bootcfg/server/serverpb"
|
|
)
|
|
|
|
// 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(srv server.Server) ContextHandler {
|
|
fn := func(ctx context.Context, 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 := srv.SelectGroup(ctx, &pb.SelectGroupRequest{Labels: attrs})
|
|
if err != nil {
|
|
http.NotFound(w, req)
|
|
return
|
|
}
|
|
resp, err := srv.ProfileGet(ctx, &pb.ProfileGetRequest{Id: group.Profile})
|
|
if err != nil {
|
|
http.NotFound(w, req)
|
|
return
|
|
}
|
|
renderJSON(w, resp.Profile.Boot)
|
|
}
|
|
return ContextHandlerFunc(fn)
|
|
}
|