env command now supports * wildcard for searching

This commit is contained in:
Jason Gerard DeRose 2008-11-14 22:21:36 -07:00
parent e3fec8f219
commit e059591d6b

View File

@ -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)