Skip to content
This repository

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

Merged
merged 1 commit into from about 2 years ago

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 February 22, 2012
Thomas S Hatch thatch45 closed this February 22, 2012
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

Showing 1 unique commit by 1 author.

Feb 22, 2012
Ben Hosmer adding the option to delete all keys using salt-key option e02197b
This page is out of date. Refresh to see the latest.
8  salt/cli/__init__.py
@@ -478,6 +478,13 @@ def __parse(self):
478 478
                 dest='delete',
479 479
                 default='',
480 480
                 help='Delete the named key')
  481
+        
  482
+        parser.add_option('-D',
  483
+                '--delete-all',
  484
+                dest='delete_all',
  485
+                default=False,
  486
+                action='store_true',
  487
+                help='Delete all keys')
481 488
 
482 489
         parser.add_option('-q',
483 490
                 '--quiet',
@@ -536,6 +543,7 @@ def __parse(self):
536 543
         opts['print'] = options.print_
537 544
         opts['print_all'] = options.print_all
538 545
         opts['delete'] = options.delete
  546
+        opts['delete_all'] = options.delete_all
539 547
         opts['gen_keys'] = options.gen_keys
540 548
         opts['gen_keys_dir'] = options.gen_keys_dir
541 549
         if options.keysize < 2048:
28  salt/cli/key.py
@@ -143,28 +143,38 @@ def _accept_all(self):
143 143
         for key in os.listdir(minions_pre):
144 144
             self._accept(key)
145 145
 
146  
-    def _delete_key(self):
  146
+    def _delete_key(self, delete=None):
147 147
         '''
148 148
         Delete a key
149 149
         '''
150 150
         (minions_accepted,
151 151
          minions_pre,
152 152
          minions_rejected) = self._check_minions_directories()
153  
-        pre = os.path.join(minions_pre, self.opts['delete'])
154  
-        acc = os.path.join(minions_accepted, self.opts['delete'])
155  
-        rej= os.path.join(minions_rejected, self.opts['delete'])
  153
+        if delete == None:
  154
+            delete = self.opts['delete']
  155
+        pre = os.path.join(minions_pre, delete)
  156
+        acc = os.path.join(minions_accepted, delete)
  157
+        rej = os.path.join(minions_rejected, delete)
156 158
         if os.path.exists(pre):
157 159
             os.remove(pre)
158  
-            self._log('Removed pending key %s' % self.opts['delete'], 
  160
+            self._log('Removed pending key %s' % delete, 
159 161
                          level='info')
160 162
         if os.path.exists(acc):
161 163
             os.remove(acc)
162  
-            self._log('Removed accepted key %s' % self.opts['delete'], 
  164
+            self._log('Removed accepted key %s' % delete, 
163 165
                          level='info')
164 166
         if os.path.exists(rej):
165 167
             os.remove(rej)
166  
-            self._log('Removed rejected key %s' % self.opts['delete'], 
  168
+            self._log('Removed rejected key %s' % delete, 
167 169
                          level='info')
  170
+    def _delete_all(self):
  171
+        '''
  172
+        Delete all keys 
  173
+        '''
  174
+        for dir in ("acc", "rej", "pre"):
  175
+            for key in self._keys(dir):
  176
+                self._delete_key(key)
  177
+
168 178
 
169 179
     def _reject(self, key):
170 180
         '''
@@ -234,5 +244,7 @@ def run(self):
234 244
             self._reject_all()
235 245
         elif self.opts['delete']:
236 246
             self._delete_key()
  247
+        elif self.opts['delete_all']:
  248
+            self._delete_all()
237 249
         else:
238  
-            self._list_all()
  250
+            self._list_all()
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.