@@ -203,6 +203,13 @@ def add_authopts(self):
203203 generated and made available for the period defined in the Salt
204204 Master.""" ))
205205
206+ optgroup .add_option ('-x' , dest = 'cache' ,
207+ default = os .environ .get ('PEPPERCACHE' ,
208+ os .path .join (os .path .expanduser ('~' ), '.peppercache' )),
209+ help = textwrap .dedent ('''\
210+ Cache file location. Default is a file path in the
211+ "PEPPERCACHE" environment variable or ~/.peppercache.''' ))
212+
206213 return optgroup
207214
208215 def get_login_details (self ):
@@ -421,7 +428,7 @@ def run(self):
421428 debug_http = self .options .debug_http ,
422429 ignore_ssl_errors = self .options .ignore_ssl_certificate_errors )
423430 if self .options .mktoken :
424- token_file = os . path . join ( os . path . expanduser ( '~' ), '.peppercache' )
431+ token_file = self . options . cache
425432 try :
426433 with open (token_file , 'rt' ) as f :
427434 api .auth = json .load (f )
@@ -431,15 +438,15 @@ def run(self):
431438 api .req ('/stats' )
432439 except Exception as e :
433440 if e .args [0 ] is not 2 :
434- logger .error ('Unable to load login token from ~/.peppercache ' + str (e ))
441+ logger .error ('Unable to load login token from {0} {1}' . format ( token_file , str (e ) ))
435442 auth = api .login (* self .parse_login ())
436443 try :
437444 oldumask = os .umask (0 )
438445 fdsc = os .open (token_file , os .O_WRONLY | os .O_CREAT , 0o600 )
439446 with os .fdopen (fdsc , 'wt' ) as f :
440447 json .dump (auth , f )
441448 except Exception as e :
442- logger .error ('Unable to save token to ~/.pepperache ' + str (e ))
449+ logger .error ('Unable to save token to {0} {1}' . format ( token_file , str (e ) ))
443450 finally :
444451 os .umask (oldumask )
445452 else :
0 commit comments