Name: "arvados-controller",
}
h.cache = map[string]*cacheEnt{
- "/discovery/v1/apis/arvados/v1/rest": &cacheEnt{validateDD: true},
+ "/discovery/v1/apis/arvados/v1/rest": &cacheEnt{validate: validateDiscoveryDoc},
}
go h.trashSweepWorker()
// cacheEnt implements a basic stale-while-revalidate cache, suitable
// for the Arvados discovery document.
type cacheEnt struct {
- validateDD bool
+ validate func(body []byte) error
mtx sync.Mutex
header http.Header
body []byte
header[k] = v
}
}
- if ent.validateDD {
- var dd arvados.DiscoveryDocument
- if err := json.Unmarshal(body, &dd); err != nil {
- return nil, nil, fmt.Errorf("error decoding JSON response: %w", err)
- } else if dd.BasePath == "" {
- return nil, nil, errors.New("error in discovery document: no value for basePath")
+ if ent.validate != nil {
+ if err := ent.validate(body); err != nil {
+ return nil, nil, err
}
} else if mediatype, _, err := mime.ParseMediaType(header.Get("Content-Type")); err == nil && mediatype == "application/json" {
if !json.Valid(body) {
}
return best, cluster.TLS.Insecure, nil
}
+
+func validateDiscoveryDoc(body []byte) error {
+ var dd arvados.DiscoveryDocument
+ err := json.Unmarshal(body, &dd)
+ if err != nil {
+ return fmt.Errorf("error decoding JSON response: %w", err)
+ }
+ if dd.BasePath == "" {
+ return errors.New("error in discovery document: no value for basePath")
+ }
+ return nil
+}