Skip to content

Commit e3aee65

Browse files
authored
client_conf: recognize NDN_CLIENT_* environment variables (#12)
Ref: https://named-data.net/doc/ndn-cxx/0.7.0/manpages/ndn-client.conf.html
1 parent cd5f899 commit e3aee65

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/ndn/client_conf.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def get_path():
3939
if os.path.exists(path):
4040
return path
4141

42-
def resolve_loaction(value):
42+
def resolve_location(value):
4343
nonlocal path
4444
sp = value.split(':')
4545
if len(sp) == 1:
@@ -48,7 +48,7 @@ def resolve_loaction(value):
4848
else:
4949
schema, loc = sp
5050
if not loc or not os.path.exists(loc):
51-
if loc:
51+
if loc and (path is not None):
5252
loc = os.path.join(os.path.dirname(path), loc)
5353
if not loc or not os.path.exists(loc):
5454
loc = '~/.ndn/ndnsec-key-file' if schema == 'tpm-file' else '~/.ndn'
@@ -67,13 +67,18 @@ def resolve_loaction(value):
6767
with open(path) as f:
6868
text += f.read()
6969
parser.read_string(text)
70-
for key in ['transport', 'pib', 'tpm']:
70+
for key in ret.keys():
7171
try:
7272
ret[key] = parser['DEFAULT'][key]
7373
except KeyError:
7474
pass
75+
for key in ret.keys():
76+
try:
77+
ret[key] = os.environ[f'NDN_CLIENT_{key.upper()}']
78+
except KeyError:
79+
pass
7580
for key in ['pib', 'tpm']:
76-
ret[key] = resolve_loaction(ret[key])
81+
ret[key] = resolve_location(ret[key])
7782
return ret
7883

7984

0 commit comments

Comments
 (0)