ValidateWebhookConfig will check if the template provided in nthConfig with parse and execute
(nthConfig config.Config)
| 130 | |
| 131 | // ValidateWebhookConfig will check if the template provided in nthConfig with parse and execute |
| 132 | func ValidateWebhookConfig(nthConfig config.Config) error { |
| 133 | if nthConfig.WebhookURL == "" { |
| 134 | return nil |
| 135 | } |
| 136 | |
| 137 | var webhookTemplateContent string |
| 138 | |
| 139 | if nthConfig.WebhookTemplateFile != "" { |
| 140 | content, err := os.ReadFile(nthConfig.WebhookTemplateFile) |
| 141 | if err != nil { |
| 142 | return fmt.Errorf("webhook error: could not read template file %w", err) |
| 143 | } |
| 144 | webhookTemplateContent = string(content) |
| 145 | } else { |
| 146 | webhookTemplateContent = nthConfig.WebhookTemplate |
| 147 | } |
| 148 | |
| 149 | webhookTemplate, err := template.New("message").Funcs(sprig.TxtFuncMap()).Parse(webhookTemplateContent) |
| 150 | if err != nil { |
| 151 | return fmt.Errorf("unable to parse webhook template: %w", err) |
| 152 | } |
| 153 | |
| 154 | var byteBuffer bytes.Buffer |
| 155 | err = webhookTemplate.Execute(&byteBuffer, &combinedDrainData{}) |
| 156 | if err != nil { |
| 157 | return fmt.Errorf("unable to execute webhook template: %w", err) |
| 158 | } |
| 159 | return nil |
| 160 | } |
no outgoing calls