Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

2 participants

Ben Hosmer Thomas S Hatch
Ben Hosmer

This might be half done, but my knowledge of py is somewhat limited. I know it would be a good idea to prompt for confirmation before doing this.

Thomas S Hatch thatch45 merged commit b65310a into from
Thomas S Hatch
Owner

Looks good, I will make a few modifications but all in all this looks great!

Ben Hosmer

Thanks. I'm glad it was useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 28 additions and 8 deletions.
  1. +8 −0 salt/cli/__init__.py
  2. +20 −8 salt/cli/key.py
8 salt/cli/__init__.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:
28 salt/cli/key.py
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()
Something went wrong with that request. Please try again.