Skip to content

Commit

Permalink
Normalize template context for external_template
Browse files Browse the repository at this point in the history
Update the template context for the external_template so that it has the
same context as the built-in templates.

Fixes tierpod#46
  • Loading branch information
moorereason committed Apr 5, 2024
1 parent b4ccc49 commit f2b1d49
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions cmd/dmarc-report-converter/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bytes"
"encoding/json"
"encoding/xml"
"fmt"
"io"
"log"
Expand Down Expand Up @@ -65,12 +66,28 @@ func (o *output) do(d dmarc.Report) error {
}

func (o *output) template(d dmarc.Report) error {
err := o.cfg.Output.template.Execute(o.w, d)
if err != nil {
return err
data := struct {
AssetsPath string
Report dmarc.Report

// Deprecated
XMLName xml.Name
ReportMetadata dmarc.ReportMetadata
PolicyPublished dmarc.PolicyPublished
Records []dmarc.Record
MessagesStats dmarc.MessagesStats
}{
o.cfg.Output.AssetsPath,
d,

d.XMLName,
d.ReportMetadata,
d.PolicyPublished,
d.Records,
d.MessagesStats,
}

return nil
return o.cfg.Output.template.Execute(o.w, data)
}

func (o *output) templateHTML(d dmarc.Report) error {
Expand All @@ -79,12 +96,7 @@ func (o *output) templateHTML(d dmarc.Report) error {
Report dmarc.Report
}{o.cfg.Output.AssetsPath, d}

err := o.cfg.Output.template.Execute(o.w, data)
if err != nil {
return err
}

return nil
return o.cfg.Output.template.Execute(o.w, data)
}

func (o *output) json(d dmarc.Report) error {
Expand Down

0 comments on commit f2b1d49

Please sign in to comment.