PR comments config

This commit is contained in:
Till Faelligen 2022-05-04 13:47:08 +02:00
parent e0cdf64c33
commit dc8cea6d57

View file

@ -288,37 +288,39 @@ func (c *UserConsentOptions) Defaults() {
} }
func (c *UserConsentOptions) Verify(configErrors *ConfigErrors, isMonolith bool) { func (c *UserConsentOptions) Verify(configErrors *ConfigErrors, isMonolith bool) {
if c.Enabled { if !c.Enabled {
checkNotEmpty(configErrors, "template_dir", c.TemplateDir) return
checkNotEmpty(configErrors, "version", c.Version) }
checkNotEmpty(configErrors, "policy_name", c.PolicyName)
checkNotEmpty(configErrors, "form_secret", c.FormSecret)
checkNotEmpty(configErrors, "base_url", c.BaseURL)
if len(*configErrors) > 0 {
return
}
p, err := filepath.Abs(c.TemplateDir) checkNotEmpty(configErrors, "template_dir", c.TemplateDir)
if err != nil { checkNotEmpty(configErrors, "version", c.Version)
configErrors.Add("unable to get template directory") checkNotEmpty(configErrors, "policy_name", c.PolicyName)
return checkNotEmpty(configErrors, "form_secret", c.FormSecret)
} checkNotEmpty(configErrors, "base_url", c.BaseURL)
if len(*configErrors) > 0 {
return
}
c.TextTemplates = textTemplate.Must(textTemplate.New("blockEventsError").Parse(c.BlockEventsError)) p, err := filepath.Abs(c.TemplateDir)
c.TextTemplates = textTemplate.Must(c.TextTemplates.New("serverNoticeTemplate").Parse(c.ServerNoticeContent.Body)) if err != nil {
configErrors.Add("unable to get template directory")
return
}
// Read all defined *.gohtml templates c.TextTemplates = textTemplate.Must(textTemplate.New("blockEventsError").Parse(c.BlockEventsError))
t, err := template.ParseGlob(filepath.Join(p, "*.gohtml")) c.TextTemplates = textTemplate.Must(c.TextTemplates.New("serverNoticeTemplate").Parse(c.ServerNoticeContent.Body))
if err != nil || t == nil {
configErrors.Add(fmt.Sprintf("unable to read consent templates: %+v", err)) // Read all defined *.gohtml templates
return t, err := template.ParseGlob(filepath.Join(p, "*.gohtml"))
} if err != nil || t == nil {
c.Templates = t configErrors.Add(fmt.Sprintf("unable to read consent templates: %+v", err))
// Verify we've got a template for the defined version return
versionTemplate := c.Templates.Lookup(c.Version + ".gohtml") }
if versionTemplate == nil { c.Templates = t
configErrors.Add(fmt.Sprintf("unable to load defined '%s' policy template", c.Version)) // Verify we've got a template for the defined version
} versionTemplate := c.Templates.Lookup(c.Version + ".gohtml")
if versionTemplate == nil {
configErrors.Add(fmt.Sprintf("unable to load defined '%s' policy template", c.Version))
} }
} }