MCPcopy Create free account
hub / github.com/aws/aws-node-termination-handler / ValidateWebhookConfig

Function ValidateWebhookConfig

pkg/webhook/webhook.go:132–160  ·  view source on GitHub ↗

ValidateWebhookConfig will check if the template provided in nthConfig with parse and execute

(nthConfig config.Config)

Source from the content-addressed store, hash-verified

130
131// ValidateWebhookConfig will check if the template provided in nthConfig with parse and execute
132func 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}

Callers 2

mainFunction · 0.92

Calls

no outgoing calls

Tested by 1