Permalink
Browse files

adding the option to delete all keys using salt-key option

  • Loading branch information...
1 parent 25981d2 commit e02197baefce111ed6fd8574aa47136b42c2dcba @benhosmer committed Feb 22, 2012
Showing with 28 additions and 8 deletions.
  1. +8 −0 salt/cli/__init__.py
  2. +20 −8 salt/cli/key.py
View
@@ -478,6 +478,13 @@ def __parse(self):
dest='delete',
default='',
help='Delete the named key')
+
+ parser.add_option('-D',
+ '--delete-all',
+ dest='delete_all',
+ default=False,
+ action='store_true',
+ help='Delete all keys')
parser.add_option('-q',
'--quiet',
@@ -536,6 +543,7 @@ def __parse(self):
opts['print'] = options.print_
opts['print_all'] = options.print_all
opts['delete'] = options.delete
+ opts['delete_all'] = options.delete_all
opts['gen_keys'] = options.gen_keys
opts['gen_keys_dir'] = options.gen_keys_dir
if options.keysize < 2048:
View
@@ -143,28 +143,38 @@ def _accept_all(self):
for key in os.listdir(minions_pre):
self._accept(key)
- def _delete_key(self):
+ def _delete_key(self, delete=None):
'''
Delete a key
'''
(minions_accepted,
minions_pre,
minions_rejected) = self._check_minions_directories()
- pre = os.path.join(minions_pre, self.opts['delete'])
- acc = os.path.join(minions_accepted, self.opts['delete'])
- rej= os.path.join(minions_rejected, self.opts['delete'])
+ if delete == None:
+ delete = self.opts['delete']
+ pre = os.path.join(minions_pre, delete)
+ acc = os.path.join(minions_accepted, delete)
+ rej = os.path.join(minions_rejected, delete)
if os.path.exists(pre):
os.remove(pre)
- self._log('Removed pending key %s' % self.opts['delete'],
+ self._log('Removed pending key %s' % delete,
level='info')
if os.path.exists(acc):
os.remove(acc)
- self._log('Removed accepted key %s' % self.opts['delete'],
+ self._log('Removed accepted key %s' % delete,
level='info')
if os.path.exists(rej):
os.remove(rej)
- self._log('Removed rejected key %s' % self.opts['delete'],
+ self._log('Removed rejected key %s' % delete,
level='info')
+ def _delete_all(self):
+ '''
+ Delete all keys
+ '''
+ for dir in ("acc", "rej", "pre"):
+ for key in self._keys(dir):
+ self._delete_key(key)
+
def _reject(self, key):
'''
@@ -234,5 +244,7 @@ def run(self):
self._reject_all()
elif self.opts['delete']:
self._delete_key()
+ elif self.opts['delete_all']:
+ self._delete_all()
else:
- self._list_all()
+ self._list_all()

0 comments on commit e02197b

Please sign in to comment.