17
17
OPTIONS:
18
18
-u USER[:PASS] specify USER and optionally PASS on command line
19
19
-d passfd specify open fd to read PASS
20
+ -f passfile specify path to file to open and read PASS
20
21
-e ENDPOINT specify REST endpoint
21
22
22
23
PASS for USER is taken from the first of:
23
24
1. -u USER:PASS
24
25
2. -d passfd (read from fd)
25
- 3. read from $PASS env var
26
+ 3. -f passfile (read from file)
27
+ 4. read from $PASS env var
26
28
27
29
ENDPOINT defaults to {ENDPOINT}
28
30
"""
@@ -45,11 +47,13 @@ class Options:
45
47
options = Options ()
46
48
47
49
48
- def getpw (user , passfd = None ):
50
+ def getpw (user , passfd , passfile ):
49
51
if ':' in user :
50
52
user , pw = user .split (':' , 1 )
51
53
elif passfd is not None :
52
54
pw = os .fdopen (passfd ).readline ().rstrip ('\n ' )
55
+ elif passfile is not None :
56
+ pw = open (passfile ).readline ().rstrip ('\n ' )
53
57
elif 'PASS' in os .environ :
54
58
pw = os .environ ['PASS' ]
55
59
else :
@@ -140,13 +144,15 @@ def parse_options(args):
140
144
usage ("Extra arguments: %s" % repr (args ))
141
145
142
146
passfd = None
147
+ passfile = None
143
148
144
149
for op , arg in ops :
145
150
if op == '-u' : options .user = arg
146
151
if op == '-d' : passfd = int (arg )
152
+ if op == '-f' : passfile = arg
147
153
if op == '-e' : options .endpoint = arg
148
154
149
- options .user , passwd = getpw (options .user , passfd )
155
+ options .user , passwd = getpw (options .user , passfd , passfile )
150
156
options .authstr = mkauthstr (options .user , passwd )
151
157
152
158
0 commit comments