func parseTemplate()

in lib/notifiers/notifiers.go [297:318]


func parseTemplate(ctx context.Context, tmpl *Template, grf gcsReaderFactory) (string, error) {
	templateString := ""
	if tmpl != nil {
		if _, ok := allowedTemplateTypes[tmpl.Type]; !ok {
			return "", fmt.Errorf("got invalid Template Type: %v", tmpl.Type)
		}
		if tmpl.URI != "" {
			parsed, err := getGCSTemplate(ctx, grf, tmpl.URI)
			if err != nil {
				return "", fmt.Errorf("failed to get template from GCS: %w", err)
			}
			templateString = parsed
		} else {
			templateString = tmpl.Content
		}
		if err := validateTemplate(templateString); err != nil {
			return "", fmt.Errorf("got invalid template from path %q: %w", tmpl.URI, err)
		}
	}
	return templateString, nil

}