From 403dfee601e90269c187bf3a78e624c7ade5c4d1 Mon Sep 17 00:00:00 2001 From: chnyda Date: Mon, 9 Oct 2017 16:59:00 +0200 Subject: [PATCH] Add option to configure .peppercache file --- pepper/cli.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pepper/cli.py b/pepper/cli.py index 6160df4..82eea31 100644 --- a/pepper/cli.py +++ b/pepper/cli.py @@ -203,6 +203,13 @@ def add_authopts(self): generated and made available for the period defined in the Salt Master.""")) + optgroup.add_option('-x', dest='cache', + default=os.environ.get('PEPPERCACHE', + os.path.join(os.path.expanduser('~'), '.peppercache')), + help=textwrap.dedent('''\ + Cache file location. Default is a file path in the + "PEPPERCACHE" environment variable or ~/.peppercache.''')) + return optgroup def get_login_details(self): @@ -421,7 +428,7 @@ def run(self): debug_http=self.options.debug_http, ignore_ssl_errors=self.options.ignore_ssl_certificate_errors) if self.options.mktoken: - token_file = os.path.join(os.path.expanduser('~'), '.peppercache') + token_file = self.options.cache try: with open(token_file, 'rt') as f: api.auth = json.load(f) @@ -431,7 +438,7 @@ def run(self): api.req('/stats') except Exception as e: if e.args[0] is not 2: - logger.error('Unable to load login token from ~/.peppercache '+str(e)) + logger.error('Unable to load login token from {0} {1}'.format(token_file, str(e))) auth = api.login(*self.parse_login()) try: oldumask = os.umask(0) @@ -439,7 +446,7 @@ def run(self): with os.fdopen(fdsc, 'wt') as f: json.dump(auth, f) except Exception as e: - logger.error('Unable to save token to ~/.pepperache '+str(e)) + logger.error('Unable to save token to {0} {1}'.format(token_file, str(e))) finally: os.umask(oldumask) else: