summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-11-14 22:21:36 -0700
committerJason Gerard DeRose <jderose@redhat.com>2008-11-14 22:21:36 -0700
commite059591d6b190cbc6c50d0b96e1f63fddb30a934 (patch)
tree675e9b170bc425ff572b907a1958096ac7d2f7c6 /ipalib
parente3fec8f2192019e9b16dcc8ef3e965bd13c1e1d4 (diff)
downloadfreeipa-e059591d6b190cbc6c50d0b96e1f63fddb30a934.tar.gz
freeipa-e059591d6b190cbc6c50d0b96e1f63fddb30a934.tar.xz
freeipa-e059591d6b190cbc6c50d0b96e1f63fddb30a934.zip
env command now supports * wildcard for searching
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/plugins/f_misc.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/ipalib/plugins/f_misc.py b/ipalib/plugins/f_misc.py
index 6988d6f87..b2f97c71a 100644
--- a/ipalib/plugins/f_misc.py
+++ b/ipalib/plugins/f_misc.py
@@ -21,9 +21,11 @@
Misc frontend plugins.
"""
+import re
from ipalib import api, LocalOrRemote
+
# FIXME: We should not let env return anything in_server
# when mode == 'production'. This would allow an attacker to see the
# configuration of the server, potentially revealing compromising
@@ -34,16 +36,25 @@ class env(LocalOrRemote):
takes_args = ('variables*',)
def __find_keys(self, variables):
- for key in variables:
- if key in self.env:
- yield (key, self.env[key])
+ keys = set()
+ for query in variables:
+ if '*' in query:
+ pat = re.compile(query.replace('*', '.*') + '$')
+ for key in self.env:
+ if pat.match(key):
+ keys.add(key)
+ elif query in self.env:
+ keys.add(query)
+ return sorted(keys)
def execute(self, variables, **options):
if variables is None:
- return tuple(
- (key, self.env[key]) for key in self.env
- )
- return tuple(self.__find_keys(variables))
+ keys = self.env
+ else:
+ keys = self.__find_keys(variables)
+ return tuple(
+ (key, self.env[key]) for key in keys
+ )
def output_for_cli(self, textui, result, variables, **options):
if len(result) == 0:
@@ -53,6 +64,6 @@ class env(LocalOrRemote):
return
textui.print_name(self.name)
textui.print_keyval(result)
- textui.print_count(result, '%d variable', '%d variables')
+ textui.print_count(result, '%d variables')
api.register(env)