Skip to content

Instantly share code, notes, and snippets.

@elliottcordo
Last active October 16, 2015 15:03
Show Gist options
  • Save elliottcordo/d5e032a5bb3c6038b4e2 to your computer and use it in GitHub Desktop.
Save elliottcordo/d5e032a5bb3c6038b4e2 to your computer and use it in GitHub Desktop.
simple python config file encrypter with sample config file and config file reader

#simple example of encryption usage with python config

  • yeah, base64 isn't very secure
  • you probably also wanna compile to an executable to obscure the code..
import ConfigParser
import base64
config = ConfigParser.ConfigParser()
config.read('tab.cfg')
tab_user = config.get('tableau','user_name')
tab_pwd_crypt = config.get('tableau','password')
report_list = config.get('tableau', 'report_list').split(' ') # split on space delims
print tab_user
tab_pwd = base64.b64decode(tab_pwd_crypt)
print tab_pwd
print report_list
#!/usr/bin/env python
# -----------
# for help and params: python encrypt_pwd.py -h
# sample with defaults: python encrypt_pwd.py -v yipee1!
# -----------
import ConfigParser
import argparse
import base64
parser = argparse.ArgumentParser()
parser.add_argument('-c','--file', default='tab.cfg', help ="""enter config file path, default is tab.cfg """)
parser.add_argument('-s','--section', default='tableau', help ="""enter config section, default is tableau """)
parser.add_argument('-p', '--param', default='password', help ="""enter specific param name, default is password """)
parser.add_argument('-v', '--value', help ="""enter specific param name, no default, required """)
try:
args = parser.parse_args()
value_encrypt = base64.b64encode(args.value)
config = ConfigParser.ConfigParser()
config.read(args.file)
config.set(args.section, args.param, value_encrypt)
tab_pwd = config.write(open(args.file, 'wr'))
print value_encrypt
print "success!"
except:
print "\n\nsomething wrong, did you enter the required params?"
print """run "python encrypt_pwd.py -h" for more info"""
exit(1)
[tableau]
user_name = bala
password = eWlwZWUyIQ==
report_list = url1/coval url2/mpi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment