env plugin now subclasses from RemoteOrLocal

This commit is contained in:
Jason Gerard DeRose 2008-11-14 21:58:39 -07:00
parent 36737c2d91
commit 9de56d43f0
3 changed files with 14 additions and 22 deletions

View File

@ -793,7 +793,7 @@ class LocalOrRemote(Command):
"""
takes_options = (
Param('server', type=ipa_types.Bool(), default=False,
Param('server?', type=ipa_types.Bool(), default=False,
doc='Forward to server instead of running locally',
),
)

View File

@ -21,44 +21,36 @@
Misc frontend plugins.
"""
from ipalib import api, Command, Param, Bool
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
# information. However, it's damn handy for testing/debugging.
class env(Command):
class env(LocalOrRemote):
"""Show environment variables"""
takes_args = ('variables*',)
takes_options = (
Param('server?', type=Bool(), default=False,
doc='Show environment variables of server',
),
)
def run(self, variables, **options):
if options['server'] and not self.env.in_server:
return self.forward(variables)
return self.execute(variables)
def find_keys(self, variables):
def __find_keys(self, variables):
for key in variables:
if key in self.env:
yield (key, self.env[key])
def execute(self, variables):
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))
return tuple(self.__find_keys(variables))
def output_for_cli(self, textui, result, variables, **options):
if len(result) == 0:
return
if len(result) == 1:
textui.print_keyval(result)
return
textui.print_name(self.name)
textui.print_keyval(result)
textui.print_count(result, '%d variable', '%d variables')

View File

@ -811,7 +811,7 @@ class test_LocalOrRemote(ClassChecker):
assert list(o.args) == []
assert list(o.options) == ['server']
op = o.options.server
assert op.required is True
assert op.required is False
assert op.default is False
def test_run(self):
@ -832,8 +832,8 @@ class test_LocalOrRemote(ClassChecker):
api.register(example)
api.finalize()
cmd = api.Command.example
assert cmd() == ('execute', (None,), dict(server=False))
assert cmd('var') == ('execute', (u'var',), dict(server=False))
assert cmd() == ('execute', (None,), dict(server=None))
assert cmd('var') == ('execute', (u'var',), dict(server=None))
assert cmd(server=True) == ('forward', (None,), dict(server=True))
assert cmd('var', server=True) == \
('forward', (u'var',), dict(server=True))
@ -843,8 +843,8 @@ class test_LocalOrRemote(ClassChecker):
api.register(example)
api.finalize()
cmd = api.Command.example
assert cmd() == ('execute', (None,), dict(server=False))
assert cmd('var') == ('execute', (u'var',), dict(server=False))
assert cmd() == ('execute', (None,), dict(server=None))
assert cmd('var') == ('execute', (u'var',), dict(server=None))
assert cmd(server=True) == ('execute', (None,), dict(server=True))
assert cmd('var', server=True) == \
('execute', (u'var',), dict(server=True))