coremodels: Automatically generate coremodel registries (#50057)
* coremodel: Generate static registry * Actually make codegen work Also, remove the per-coremodel assignability test from generator set. * Make wire gen depend on cue gen This is necessary now that we're generating a wire set as part of coremodel registry generation. * Add wire inject bits to http server * s/staticregistry/registry/ * move to static and dynamic wording * Move registry type into registry package * Use static registry in http handler * Oi comments
This commit is contained in:
+13
-13
@@ -303,22 +303,22 @@ func (hs *HTTPServer) PostDashboard(c *models.ReqContext) response.Response {
|
||||
}
|
||||
|
||||
if hs.Features.IsEnabled(featuremgmt.FlagValidateDashboardsOnSave) {
|
||||
cm := hs.CoremodelStaticRegistry.Dashboard()
|
||||
|
||||
// Ideally, coremodel validation calls would be integrated into the web
|
||||
// framework. But this does the job for now.
|
||||
if cm, has := hs.CoremodelRegistry.Get("dashboard"); has {
|
||||
schv, err := cmd.Dashboard.Get("schemaVersion").Int()
|
||||
schv, err := cmd.Dashboard.Get("schemaVersion").Int()
|
||||
|
||||
// Only try to validate if the schemaVersion is at least the handoff version
|
||||
// (the minimum schemaVersion against which the dashboard schema is known to
|
||||
// work), or if schemaVersion is absent (which will happen once the Thema
|
||||
// schema becomes canonical).
|
||||
if err != nil || schv >= dashboard.HandoffSchemaVersion {
|
||||
// Can't fail, web.Bind() already ensured it's valid JSON
|
||||
b, _ := cmd.Dashboard.Bytes()
|
||||
v, _ := cuectx.JSONtoCUE("dashboard.json", b)
|
||||
if _, err := cm.CurrentSchema().Validate(v); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "invalid dashboard json", err)
|
||||
}
|
||||
// Only try to validate if the schemaVersion is at least the handoff version
|
||||
// (the minimum schemaVersion against which the dashboard schema is known to
|
||||
// work), or if schemaVersion is absent (which will happen once the Thema
|
||||
// schema becomes canonical).
|
||||
if err != nil || schv >= dashboard.HandoffSchemaVersion {
|
||||
// Can't fail, web.Bind() already ensured it's valid JSON
|
||||
b, _ := cmd.Dashboard.Bytes()
|
||||
v, _ := cuectx.JSONtoCUE("dashboard.json", b)
|
||||
if _, err := cm.CurrentSchema().Validate(v); err != nil {
|
||||
return response.Error(http.StatusBadRequest, "invalid dashboard json", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user