Skip to content

Commit

Permalink
Add option to configure .peppercache file
Browse files Browse the repository at this point in the history
  • Loading branch information
chnyda committed Oct 10, 2017
1 parent 0a02fcc commit 403dfee
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pepper/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -431,15 +438,15 @@ 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)
fdsc = os.open(token_file, os.O_WRONLY | os.O_CREAT, 0o600)
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:
Expand Down

0 comments on commit 403dfee

Please sign in to comment.