Skip to content

Commit

Permalink
Merge pull request #25449 from ruzarowski/2015.8-minion_keys_exclude_…
Browse files Browse the repository at this point in the history
…dotfiles_and_dirs

Exclude dotfiles and directories from minion key lists (Fixes #25448)
  • Loading branch information
Mike Place committed Jul 15, 2015
2 parents 0b4ca8d + b02f77a commit 279d0f1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 21 deletions.
20 changes: 12 additions & 8 deletions salt/key.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,23 +687,27 @@ def list_status(self, match):
if match.startswith('acc'):
ret[os.path.basename(acc)] = []
for fn_ in salt.utils.isorted(os.listdir(acc)):
if os.path.isfile(os.path.join(acc, fn_)):
ret[os.path.basename(acc)].append(fn_)
if not fn_.startswith('.'):
if os.path.isfile(os.path.join(acc, fn_)):
ret[os.path.basename(acc)].append(fn_)
elif match.startswith('pre') or match.startswith('un'):
ret[os.path.basename(pre)] = []
for fn_ in salt.utils.isorted(os.listdir(pre)):
if os.path.isfile(os.path.join(pre, fn_)):
ret[os.path.basename(pre)].append(fn_)
if not fn_.startswith('.'):
if os.path.isfile(os.path.join(pre, fn_)):
ret[os.path.basename(pre)].append(fn_)
elif match.startswith('rej'):
ret[os.path.basename(rej)] = []
for fn_ in salt.utils.isorted(os.listdir(rej)):
if os.path.isfile(os.path.join(rej, fn_)):
ret[os.path.basename(rej)].append(fn_)
if not fn_.startswith('.'):
if os.path.isfile(os.path.join(rej, fn_)):
ret[os.path.basename(rej)].append(fn_)
elif match.startswith('den'):
ret[os.path.basename(den)] = []
for fn_ in salt.utils.isorted(os.listdir(den)):
if os.path.isfile(os.path.join(den, fn_)):
ret[os.path.basename(den)].append(fn_)
if not fn_.startswith('.'):
if os.path.isfile(os.path.join(den, fn_)):
ret[os.path.basename(den)].append(fn_)
elif match.startswith('all'):
return self.all_keys()
return ret
Expand Down
46 changes: 33 additions & 13 deletions salt/utils/minions.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,10 @@ def _check_glob_minions(self, expr, greedy): # pylint: disable=unused-argument
'''
pki_dir = os.path.join(self.opts['pki_dir'], self.acc)
try:
files = os.listdir(pki_dir)
files = []
for fn_ in salt.utils.isorted(os.listdir(pki_dir)):
if not fn_.startswith('.') and os.path.isfile(os.path.join(pki_dir, fn_)):
files.append(fn_)
return fnmatch.filter(files, expr)
except OSError:
return []
Expand All @@ -194,7 +197,10 @@ def _check_pcre_minions(self, expr, greedy): # pylint: disable=unused-argument
Return the minions found by looking via regular expressions
'''
try:
minions = os.listdir(os.path.join(self.opts['pki_dir'], self.acc))
minions = []
for fn_ in salt.utils.isorted(os.listdir(os.path.join(self.opts['pki_dir'], self.acc))):
if not fn_.startswith('.') and os.path.isfile(os.path.join(self.opts['pki_dir'], self.acc, fn_)):
minions.append(fn_)
reg = re.compile(expr)
return [m for m in minions if reg.match(m)]
except OSError:
Expand All @@ -213,9 +219,11 @@ def _check_cache_minions(self,
cache_enabled = self.opts.get('minion_data_cache', False)

if greedy:
minions = set(
os.listdir(os.path.join(self.opts['pki_dir'], self.acc))
)
mlist = []
for fn_ in salt.utils.isorted(os.listdir(os.path.join(self.opts['pki_dir'], self.acc))):
if not fn_.startswith('.') and os.path.isfile(os.path.join(self.opts['pki_dir'], self.acc, fn_)):
mlist.append(fn_)
minions = set(mlist)
elif cache_enabled:
minions = os.listdir(os.path.join(self.opts['cachedir'], 'minions'))
else:
Expand Down Expand Up @@ -293,9 +301,11 @@ def _check_ipcidr_minions(self, expr, greedy):
cache_enabled = self.opts.get('minion_data_cache', False)

if greedy:
minions = set(
os.listdir(os.path.join(self.opts['pki_dir'], self.acc))
)
mlist = []
for fn_ in salt.utils.isorted(os.listdir(os.path.join(self.opts['pki_dir'], self.acc))):
if not fn_.startswith('.') and os.path.isfile(os.path.join(self.opts['pki_dir'], self.acc, fn_)):
mlist.append(fn_)
minions = set(mlist)
elif cache_enabled:
minions = os.listdir(os.path.join(self.opts['cachedir'], 'minions'))
else:
Expand Down Expand Up @@ -364,7 +374,11 @@ def _check_range_minions(self, expr, greedy):
)
cache_enabled = self.opts.get('minion_data_cache', False)
if greedy:
return os.listdir(os.path.join(self.opts['pki_dir'], self.acc))
mlist = []
for fn_ in salt.utils.isorted(os.listdir(os.path.join(self.opts['pki_dir'], self.acc))):
if not fn_.startswith('.') and os.path.isfile(os.path.join(self.opts['pki_dir'], self.acc, fn_)):
mlist.append(fn_)
return mlist
elif cache_enabled:
return os.listdir(os.path.join(self.opts['cachedir'], 'minions'))
else:
Expand Down Expand Up @@ -393,9 +407,11 @@ def _check_compound_minions(self,
if not isinstance(expr, six.string_types) and not isinstance(expr, (list, tuple)):
log.error('Compound target that is neither string, list nor tuple')
return []
minions = set(
os.listdir(os.path.join(self.opts['pki_dir'], self.acc))
)
mlist = []
for fn_ in salt.utils.isorted(os.listdir(os.path.join(self.opts['pki_dir'], self.acc))):
if not fn_.startswith('.') and os.path.isfile(os.path.join(self.opts['pki_dir'], self.acc, fn_)):
mlist.append(fn_)
minions = set(mlist)
log.debug('minions: {0}'.format(minions))

if self.opts.get('minion_data_cache', False):
Expand Down Expand Up @@ -565,7 +581,11 @@ def _all_minions(self, expr=None):
'''
Return a list of all minions that have auth'd
'''
return os.listdir(os.path.join(self.opts['pki_dir'], self.acc))
mlist = []
for fn_ in salt.utils.isorted(os.listdir(os.path.join(self.opts['pki_dir'], self.acc))):
if not fn_.startswith('.') and os.path.isfile(os.path.join(self.opts['pki_dir'], self.acc, fn_)):
mlist.append(fn_)
return mlist

def check_minions(self,
expr,
Expand Down

0 comments on commit 279d0f1

Please sign in to comment.