Enforce generated text report identity
This commit is contained in:
@@ -28,6 +28,7 @@ type validator func([]byte) (any, []byte, error)
|
||||
type renderContextBuilder func(report.ID, string, briefing.Metadata, module.Snapshot, facts.CollectedFacts, facts.DerivedFacts, any) (any, error)
|
||||
|
||||
type catalogEntry struct {
|
||||
reportID report.ID
|
||||
schemaID string
|
||||
templateID string
|
||||
validate validator
|
||||
@@ -44,24 +45,28 @@ type Handler struct {
|
||||
|
||||
var catalog = []catalogEntry{
|
||||
{
|
||||
reportID: report.Hourly,
|
||||
schemaID: schemaIDHourly,
|
||||
templateID: templateIDHourly,
|
||||
validate: validateHourly,
|
||||
renderContextBuilder: buildHourlyContext,
|
||||
},
|
||||
{
|
||||
reportID: report.Daily,
|
||||
schemaID: schemaIDDaily,
|
||||
templateID: templateIDDaily,
|
||||
validate: validateDaily,
|
||||
renderContextBuilder: buildDailyContext,
|
||||
},
|
||||
{
|
||||
reportID: report.Today,
|
||||
schemaID: schemaIDToday,
|
||||
templateID: templateIDToday,
|
||||
validate: validateToday,
|
||||
renderContextBuilder: buildTodayContext,
|
||||
},
|
||||
{
|
||||
reportID: report.Tomorrow,
|
||||
schemaID: schemaIDTomorrow,
|
||||
templateID: templateIDTomorrow,
|
||||
validate: validateTomorrow,
|
||||
@@ -70,8 +75,7 @@ var catalog = []catalogEntry{
|
||||
}
|
||||
|
||||
func LookupDefinition(definition report.Definition) (Handler, error) {
|
||||
|
||||
var schemaKnown, templateKnown bool
|
||||
var schemaKnown, templateKnown, pairKnown bool
|
||||
for _, entry := range catalog {
|
||||
if entry.schemaID == definition.GeneratedTextSchemaID {
|
||||
schemaKnown = true
|
||||
@@ -80,8 +84,12 @@ func LookupDefinition(definition report.Definition) (Handler, error) {
|
||||
templateKnown = true
|
||||
}
|
||||
if entry.schemaID == definition.GeneratedTextSchemaID && entry.templateID == definition.TemplateID {
|
||||
pairKnown = true
|
||||
if entry.reportID != definition.ID {
|
||||
continue
|
||||
}
|
||||
return Handler{
|
||||
reportID: definition.ID,
|
||||
reportID: entry.reportID,
|
||||
schemaID: entry.schemaID,
|
||||
templateID: entry.templateID,
|
||||
validate: entry.validate,
|
||||
@@ -95,6 +103,9 @@ func LookupDefinition(definition report.Definition) (Handler, error) {
|
||||
if !templateKnown {
|
||||
return Handler{}, fmt.Errorf("report template %q is not supported for report %q", definition.TemplateID, definition.ID)
|
||||
}
|
||||
if pairKnown {
|
||||
return Handler{}, fmt.Errorf("generated text schema %q and report template %q do not belong to report %q", definition.GeneratedTextSchemaID, definition.TemplateID, definition.ID)
|
||||
}
|
||||
return Handler{}, fmt.Errorf("generated text schema %q and report template %q are not supported together for report %q", definition.GeneratedTextSchemaID, definition.TemplateID, definition.ID)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user