Files
matchbox/api/cloud.go
Dalton Hubble bb976840e1 Documentation: Add group matcher docs, improve docs and examples
* Remove Machine docs since machine resources are no longer used
2016-01-08 12:12:48 -08:00

34 lines
726 B
Go

package api
import (
"net/http"
"strings"
"time"
)
// CloudConfig defines a cloud-init config.
type CloudConfig struct {
Content string
}
// cloudHandler returns a handler that responds with the cloud config for the
// requester.
func cloudHandler(store Store) http.Handler {
fn := func(w http.ResponseWriter, req *http.Request) {
attrs := labelsFromRequest(req)
spec, err := getMatchingSpec(store, attrs)
if err != nil || spec.CloudConfig == "" {
http.NotFound(w, req)
return
}
config, err := store.CloudConfig(spec.CloudConfig)
if err != nil {
http.NotFound(w, req)
return
}
http.ServeContent(w, req, "", time.Time{}, strings.NewReader(config.Content))
}
return http.HandlerFunc(fn)
}