Files
matchbox/api/server.go
Dalton Hubble 2dd017e850 api: Require "mac" matcher reqs to use normalized MAC addresses
* Cause a parse error if user defined matchers use a mac tag that is
not a normalized MAC address. This prevents users from silently defining
tags which will never match a machine.
* Fixes #25
2016-01-14 15:31:23 -08:00

59 lines
1.4 KiB
Go

package api
import (
"net/http"
"github.com/coreos/pkg/capnslog"
)
const (
// APIVersion of the api server and its config types.
APIVersion = "v1alpha1"
)
var log = capnslog.NewPackageLogger("github.com/coreos/coreos-baremetal", "api")
// Config configures the api Server.
type Config struct {
// Store for configs
Store Store
// Path to static assets
AssetsPath string
}
// Server serves matches boot and configuration settings to machines.
type Server struct {
store Store
assetsPath string
}
// NewServer returns a new Server.
func NewServer(config *Config) *Server {
return &Server{
store: config.Store,
assetsPath: config.AssetsPath,
}
}
// HTTPHandler returns a HTTP handler for the server.
func (s *Server) HTTPHandler() http.Handler {
mux := http.NewServeMux()
// iPXE
mux.Handle("/boot.ipxe", logRequests(ipxeInspect()))
mux.Handle("/boot.ipxe.0", logRequests(ipxeInspect()))
mux.Handle("/ipxe", logRequests(ipxeHandler(s.store)))
// Pixiecore
mux.Handle("/pixiecore/v1/boot/", logRequests(pixiecoreHandler(s.store)))
// cloud configs
mux.Handle("/cloud", logRequests(cloudHandler(s.store)))
// ignition configs
mux.Handle("/ignition", logRequests(ignitionHandler(s.store)))
// API Resources
// specs
newSpecResource(mux, "/spec/", s.store)
// kernel, initrd, and TLS assets
mux.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir(s.assetsPath))))
return mux
}