summaryrefslogtreecommitdiffstats
path: root/ipalib/frontend.py
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2012-04-17 12:42:35 -0400
committerMartin Kosek <mkosek@redhat.com>2012-06-20 15:18:42 +0200
commit1235dfa7bf4b249eb6da8eab8d8a2c7b0eef98db (patch)
treea972262b4ebfdc10de052a05e94cb8961e827041 /ipalib/frontend.py
parent1484ccc4049dc42a5a8a71713253894ade401573 (diff)
downloadfreeipa-1235dfa7bf4b249eb6da8eab8d8a2c7b0eef98db.tar.gz
freeipa-1235dfa7bf4b249eb6da8eab8d8a2c7b0eef98db.tar.xz
freeipa-1235dfa7bf4b249eb6da8eab8d8a2c7b0eef98db.zip
Fail on unknown Command options
When unknown keyword arguments are passed to a Command, raise an error instead of ignoring them. Options used when IPA calls its commands internally are listed in a new Command attribute called internal_options, and allowed. Previous patches (0b01751c, c45174d6, c5689e7f) made IPA not use unknown keyword arguments in its own commands and tests, but since that some violations were reintroduced in permission_find and tests. Fix those. Tests included; both a frontend unittest and a XML-RPC test via the ping plugin (which was untested previously). https://fedorahosted.org/freeipa/ticket/2509
Diffstat (limited to 'ipalib/frontend.py')
-rw-r--r--ipalib/frontend.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index 10087ba24..c28fa54ae 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -29,7 +29,8 @@ from parameters import create_param, parse_param_spec, Param, Str, Flag, Passwor
from output import Output, Entry, ListOfEntries
from text import _, ngettext
-from errors import ZeroArgumentError, MaxArgumentError, OverlapError, RequiresRoot, VersionError, RequirementError
+from errors import (ZeroArgumentError, MaxArgumentError, OverlapError,
+ RequiresRoot, VersionError, RequirementError, OptionError)
from errors import InvocationError
from constants import TYPE_ERROR
from ipapython.version import API_VERSION
@@ -404,6 +405,8 @@ class Command(HasParam):
output_params = Plugin.finalize_attr('output_params')
has_output_params = tuple()
+ internal_options = tuple()
+
msg_summary = None
msg_truncated = _('Results are truncated, try a more specific search')
@@ -520,7 +523,13 @@ class Command(HasParam):
def __options_2_params(self, options):
for name in self.params:
if name in options:
- yield (name, options[name])
+ yield (name, options.pop(name))
+ # If any options remain, they are either internal or unknown
+ unused_keys = set(options).difference(self.internal_options)
+ unused_keys.discard('version')
+ if unused_keys:
+ raise OptionError(_('Unknown option: %(option)s'),
+ option=unused_keys.pop())
def args_options_2_entry(self, *args, **options):
"""