@@ -27,31 +27,33 @@ class JinjaExpertBot(ExpertBot):
27
27
extra.somejinjaoutput: file:///etc/intelmq/somejinjatemplate.j2
28
28
"""
29
29
30
- fields : Dict [str , Union [str , Template ]] = {}
30
+ fields : Dict [str , str ] = {}
31
+ _templates : Dict [str , Union [str , Template ]] = {}
31
32
overwrite : bool = False
32
33
33
34
def init (self ):
34
35
if not Template :
35
36
raise MissingDependencyError ("jinja2" )
36
37
37
38
for field , template in self .fields .items ():
38
- if template .startswith ("file:///" ):
39
- templatefile = pathlib .Path (template [7 :])
40
- if templatefile .exists () and os .access (templatefile , os .R_OK ):
41
- self .fields [field ] = templatefile .read_text ()
42
- else :
43
- raise ValueError (f"Jinja Template { templatefile } does not exist or is not readable." )
39
+ if not template .startswith ("file:///" ):
40
+ continue
41
+
42
+ templatefile = pathlib .Path (template [7 :])
43
+ if not (templatefile .exists () and os .access (templatefile , os .R_OK )):
44
+ raise ValueError (f"Jinja Template { templatefile } does not exist or is not readable." )
45
+ self .fields [field ] = templatefile .read_text ()
44
46
45
47
for field , template in self .fields .items ():
46
48
try :
47
- self .fields [field ] = Template (template )
49
+ self ._templates [field ] = Template (template )
48
50
except TemplateError as msg :
49
51
raise ValueError (f"Error parsing Jinja Template for '{ field } ': { msg } " )
50
52
51
53
def process (self ):
52
54
msg = self .receive_message ()
53
55
54
- for field , template in self .fields .items ():
56
+ for field , template in self ._templates .items ():
55
57
msg .add (field , template .render (msg = msg ), overwrite = self .overwrite )
56
58
57
59
self .send_message (msg )
0 commit comments