summaryrefslogtreecommitdiffstats
path: root/ipalib/dns.py
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2016-04-28 10:32:00 +0200
committerJan Cholasta <jcholast@redhat.com>2016-06-20 16:39:12 +0200
commit234270dc753ef39cd5c0ada17e88ef7f512a8cd0 (patch)
tree52833b90d580b1a4275fb7a5c402a935a6ab07ec /ipalib/dns.py
parentade8d425254864dd0155719714b81ef444bbb57b (diff)
downloadfreeipa-234270dc753ef39cd5c0ada17e88ef7f512a8cd0.tar.gz
freeipa-234270dc753ef39cd5c0ada17e88ef7f512a8cd0.tar.xz
freeipa-234270dc753ef39cd5c0ada17e88ef7f512a8cd0.zip
dns: do not rely on custom param fields in record attributes
Obtain the information provided by the `hint` kwarg and `dnsrecord_part` and `dnsrecord_extra` flags by other means. https://fedorahosted.org/freeipa/ticket/4739 Reviewed-By: David Kupka <dkupka@redhat.com>
Diffstat (limited to 'ipalib/dns.py')
-rw-r--r--ipalib/dns.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/ipalib/dns.py b/ipalib/dns.py
index 55e45a094..95c7989b6 100644
--- a/ipalib/dns.py
+++ b/ipalib/dns.py
@@ -26,6 +26,8 @@ from ipalib import errors
# dnsrecord param name formats
record_name_format = '%srecord'
+part_name_format = "%s_part_%s"
+extra_name_format = "%s_extra_%s"
def get_record_rrtype(name):
@@ -36,6 +38,22 @@ def get_record_rrtype(name):
return match.group(1).upper()
+def get_part_rrtype(name):
+ match = re.match('([^_]+)_part_.*$', name)
+ if match is None:
+ return None
+
+ return match.group(1).upper()
+
+
+def get_extra_rrtype(name):
+ match = re.match('([^_]+)_extra_.*$', name)
+ if match is None:
+ return None
+
+ return match.group(1).upper()
+
+
def has_cli_options(cmd, options, no_option_msg, allow_empty_attrs=False):
sufficient = ('setattr', 'addattr', 'delattr', 'rename')
if any(k in options for k in sufficient):
@@ -43,9 +61,8 @@ def has_cli_options(cmd, options, no_option_msg, allow_empty_attrs=False):
has_options = False
for attr in options.keys():
- obj_params = [
- p.name for p in cmd.params()
- if get_record_rrtype(p.name) or 'dnsrecord_part' in p.flags]
+ obj_params = [n for n in cmd.params
+ if get_record_rrtype(n) or get_part_rrtype(n)]
if attr in obj_params:
if options[attr] or allow_empty_attrs:
has_options = True
@@ -65,13 +82,14 @@ def get_rrparam_from_part(cmd, part_name):
try:
param = cmd.params[part_name]
- if not any(flag in param.flags for flag in
- ('dnsrecord_part', 'dnsrecord_extra')):
+ rrtype = (get_part_rrtype(param.name) or
+ get_extra_rrtype(param.name))
+ if not rrtype:
return None
# All DNS record part or extra parameters contain a name of its
# parent RR parameter in its hint attribute
- rrparam = cmd.params[param.hint]
+ rrparam = cmd.params[record_name_format % rrtype.lower()]
except (KeyError, AttributeError):
return None
@@ -94,7 +112,7 @@ def iterate_rrparams_by_parts(cmd, kw, skip_extra=False):
if rrparam is None:
continue
- if skip_extra and 'dnsrecord_extra' in cmd.params[opt].flags:
+ if skip_extra and get_extra_rrtype(opt):
continue
if rrparam.name not in processed: