Allow reading RPC parameters from env

This commit is contained in:
Ben Wilson 2019-09-25 10:27:45 -04:00
parent 24cb60b7d8
commit 67e70e1271
1 changed files with 18 additions and 14 deletions

View File

@ -12,21 +12,25 @@ TIMEOUT = 600
#Default fee to use on network for txs.
DEFAULT_FEE = 0.01
zcashconf = os.path.expanduser('~/.zcash/zcash.conf')
# Try to get RPC parameters from environment
if 'RPCUSER' in os.environ and 'RPCPASSWORD' in os.environ:
RPCUSER = os.getenviron('RPCUSER')
RPCPASSWORD = os.getenviron('RPCPASSWORD')
else:
zcashconf = os.path.expanduser('~/.zcash/zcash.conf')
def read_config(filename):
f = open(filename)
for line in f:
if re.match('rpcuser', line):
user = line.strip('\n').split('=')[1]
if re.match('rpcpassword', line):
password = line.strip('\n').split('=')[1]
return (user, password)
def read_config(filename):
f = open(filename)
for line in f:
if re.match('rpcuser', line):
user = line.strip('\n').split('=')[1]
if re.match('rpcpassword', line):
password = line.strip('\n').split('=')[1]
return (user, password)
config = read_config(zcashconf)
# from zcash conf
RPCUSER = config[0]
RPCPASSWORD = config[1]
config = read_config(zcashconf)
# from zcash conf
RPCUSER = config[0]
RPCPASSWORD = config[1]
#TESTS
#for tests (sample data here - replace with your own)