1
+ #!/usr/bin/env python3
2
+ __author__ = "Munir Njiru"
3
+ __email__ = "munir@alien-within.com"
4
+ __status__ = "Production"
5
+ '''
6
+ This script takes a minified bean shell script from the Sailpoint API and
7
+ parses it into a neat java file to allow editing later.
8
+ '''
9
+ import argparse
10
+ import random
11
+ import string
12
+ global clean_shell ,output_file , bmr_string , bmr_file
13
+ parser = argparse .ArgumentParser ()
14
+ parser .add_argument ('-f' , '--file' , help = 'Load a text file with the beanshell code' )
15
+ parser .add_argument ('-s' , '--string' , help = 'Paste a string the beanshell code' )
16
+ args = parser .parse_args ()
17
+ def from_string (bmr_string ):
18
+ clean_shell = bmr_string .replace ('\" ' ,'"' ).replace ('\\ n' , '\n ' ).replace ('\\ t' , '\t ' )
19
+ file_name = '' .join (random .choice (string .ascii_letters ) for i in range (10 ))+ ".bsh"
20
+ output_file = open (str (file_name ), "a" )
21
+ output_file .write (clean_shell )
22
+ output_file .close ()
23
+ print ("output written to: " + str (file_name ))
24
+
25
+ if args .file is not None :
26
+ bmr_file = args .file
27
+ beanshell_dirty = open (bmr_file )
28
+ bmr_string = beanshell_dirty .read ().replace ('\" ' ,'"' )
29
+ beanshell_dirty .close ()
30
+ from_string (str (bmr_string ))
31
+ elif args .string is not None :
32
+ bmr_string = args .string
33
+ from_string (bmr_string )
0 commit comments