@@ -206,8 +206,8 @@ def load_all_remediations(self, benchmark):
206206 def generate_profile_remediation_script (self , profile_el ):
207207 if self .language == "ansible" :
208208 output = self .create_output_ansible (profile_el )
209- elif self . language == "bash" or self . language == "hummingbird" :
210- output = self .create_output_bash (profile_el )
209+ else :
210+ output = self .create_output_linear (profile_el )
211211 file_path = self .get_output_file_path (profile_el )
212212 with open (file_path , "wb" ) as f :
213213 f .write (output .encode ("utf-8" ))
@@ -254,7 +254,7 @@ def collect_ansible_vars_and_tasks(self, profile_el):
254254 all_tasks .extend (rule_tasks )
255255 return (all_vars , all_tasks )
256256
257- def create_output_bash (self , profile ):
257+ def create_output_linear (self , profile ):
258258 output = []
259259 selected_rules = get_selected_rules (profile )
260260 refinements = get_value_refinenements (profile )
@@ -266,8 +266,12 @@ def create_output_bash(self, profile):
266266 if rule_id not in selected_rules :
267267 continue
268268 status = (current , total )
269- rule_remediation = self .generate_bash_rule_remediation (
270- rule_id , status , refinements )
269+ if self .language == "bash" :
270+ rule_remediation = self .generate_bash_rule_remediation (
271+ rule_id , status , refinements )
272+ elif self .language == "hummingbird" :
273+ rule_remediation = self .generate_hummingbird_rule_remediation (
274+ rule_id , refinements )
271275 output .append (rule_remediation )
272276 current += 1
273277 return "" .join (output )
@@ -295,6 +299,13 @@ def create_header(self, profile):
295299 commented_profile_description = comment (description )
296300 xccdf_version_name = "1.2"
297301 profile_id = profile .get ("id" )
302+ if self .language == "bash" :
303+ generation_text = (
304+ "# This file can be generated by OpenSCAP using:\n "
305+ "# $ oscap xccdf generate fix --profile %s --fix-type %s %s\n "
306+ "#\n " % (profile_id , self .language , self .ds_file_name ))
307+ else :
308+ generation_text = ""
298309 fix_header = (
299310 "%s"
300311 "%s\n "
@@ -309,9 +320,7 @@ def create_header(self, profile):
309320 "# Benchmark Version: %s\n "
310321 "# XCCDF Version: %s\n "
311322 "#\n "
312- "# This file can be generated by OpenSCAP using:\n "
313- "# $ oscap xccdf generate fix --profile %s --fix-type %s %s\n "
314- "#\n "
323+ "%s"
315324 "# This %s is generated from an XCCDF profile without"
316325 " preliminary evaluation.\n "
317326 "# It attempts to fix every selected rule, even if the system is"
@@ -324,7 +333,7 @@ def create_header(self, profile):
324333 shebang_with_newline , HASH_ROW , remediation_type ,
325334 profile_title , commented_profile_description , profile_id ,
326335 self .benchmark_id , self .benchmark_version , xccdf_version_name ,
327- profile_id , self . language , self . ds_file_name ,
336+ generation_text ,
328337 remediation_type , remediation_type , how_to_apply , HASH_ROW ))
329338 return fix_header
330339
@@ -355,6 +364,27 @@ def generate_bash_rule_remediation(self, rule_id, status, refinements):
355364 output .append (end_msg )
356365 return "" .join (output )
357366
367+
368+ def generate_hummingbird_rule_remediation (self , rule_id , refinements ):
369+ fix_el = self .remediations [rule_id ]
370+ if fix_el is None :
371+ return ""
372+ expanded_remediation = expand_variables (
373+ fix_el , refinements , self .variables )
374+ if expanded_remediation is None :
375+ return ""
376+ output = []
377+ header = (
378+ "%s\n "
379+ "# BEGIN fix for '%s'\n "
380+ "%s\n " % (HASH_ROW , rule_id , HASH_ROW ))
381+ output .append (header )
382+ output .append (expanded_remediation )
383+ end_msg = "\n # END fix for '%s'\n \n " % (rule_id )
384+ output .append (end_msg )
385+ return "" .join (output )
386+
387+
358388 def generate_ansible_rule_remediation (self , fix_el , refinements ):
359389 rule_vars = {}
360390 tasks = []
0 commit comments