mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Improve IP address handling in IPA option parser
Implements a way to pass match_local and parse_netmask parameters to IP option checker. Now, there is just one common option type "ip" with new optional attributes "ip_local" and "ip_netmask" which can be used to pass IP address validation parameters. https://fedorahosted.org/freeipa/ticket/1333
This commit is contained in:
committed by
Rob Crittenden
parent
79ce958a3c
commit
d9808498a8
@@ -49,8 +49,11 @@ class IPAFormatter(IndentedHelpFormatter):
|
||||
|
||||
def check_ip_option(option, opt, value):
|
||||
from ipapython.ipautil import CheckedIPAddress
|
||||
|
||||
ip_local = option.ip_local is True
|
||||
ip_netmask = option.ip_netmask is True
|
||||
try:
|
||||
return CheckedIPAddress(value, parse_netmask=(option.type == "ipnet"))
|
||||
return CheckedIPAddress(value, parse_netmask=ip_netmask, match_local=ip_local)
|
||||
except Exception as e:
|
||||
raise OptionValueError("option %s: invalid IP address %s: %s" % (opt, value, e))
|
||||
|
||||
@@ -59,10 +62,10 @@ class IPAOption(Option):
|
||||
optparse.Option subclass with support of options labeled as
|
||||
security-sensitive such as passwords.
|
||||
"""
|
||||
ATTRS = Option.ATTRS + ["sensitive"]
|
||||
TYPES = Option.TYPES + ("ipaddr", "ipnet")
|
||||
ATTRS = Option.ATTRS + ["sensitive", "ip_local", "ip_netmask"]
|
||||
TYPES = Option.TYPES + ("ip",)
|
||||
TYPE_CHECKER = copy(Option.TYPE_CHECKER)
|
||||
TYPE_CHECKER["ipaddr"] = TYPE_CHECKER["ipnet"] = check_ip_option
|
||||
TYPE_CHECKER["ip"] = check_ip_option
|
||||
|
||||
class IPAOptionParser(OptionParser):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user