jcholast's pull request #34: " dns: prompt for missing record parts in CLI" was synchronize
See the full pull-request at https://github.com/freeipa/freeipa/pull/34 ... or pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/34/head:pr34 git checkout pr34
From 5f3ccad67bb5eb9d3ed9b60bcaedcc8ebb3a31b9 Mon Sep 17 00:00:00 2001 From: Jan Cholasta <jchol...@redhat.com> Date: Mon, 29 Aug 2016 12:34:25 +0200 Subject: [PATCH 1/2] dns: prompt for missing record parts in CLI Fix the code which determines if a record part is required and thus should be prompted not to wrongfully consider all record parts to be optional. https://fedorahosted.org/freeipa/ticket/6203 --- ipaclient/plugins/dns.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ipaclient/plugins/dns.py b/ipaclient/plugins/dns.py index e17c282..18903cd 100644 --- a/ipaclient/plugins/dns.py +++ b/ipaclient/plugins/dns.py @@ -45,11 +45,21 @@ _rev_top_record_types = ('PTR', ) _zone_top_record_types = ('NS', 'MX', 'LOC', ) +_optional_part_params = { + 'loc_part_lat_min', + 'loc_part_lat_sec', + 'loc_part_lon_min', + 'loc_part_lon_sec', + 'loc_part_size', + 'loc_part_h_precision', + 'loc_part_v_precision', +} + def __get_part_param(cmd, part, output_kw, default=None): name = part.name label = unicode(part.label) - optional = not part.required + optional = name in _optional_part_params output_kw[name] = cmd.prompt_param(part, optional=optional, @@ -91,7 +101,7 @@ def prompt_missing_parts(rrtype, cmd, kw, prompt_optional=False): if name in kw: continue - optional = not part.required + optional = name in _optional_part_params if optional and not prompt_optional: continue From 8484092d72a75e9f8fe043b9bcb6558478c87e41 Mon Sep 17 00:00:00 2001 From: Jan Cholasta <jchol...@redhat.com> Date: Tue, 23 Aug 2016 12:53:39 +0200 Subject: [PATCH 2/2] dns: fix crash in interactive mode against old servers Add a client-side fallback of the dnsrecord_split_parts command for old servers to avoid CommandError in dnsrecord_add and dnsrecord_mod CLI interactive mode. https://fedorahosted.org/freeipa/ticket/6203 --- ipaclient/plugins/dns.py | 61 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/ipaclient/plugins/dns.py b/ipaclient/plugins/dns.py index 18903cd..31e4f6b 100644 --- a/ipaclient/plugins/dns.py +++ b/ipaclient/plugins/dns.py @@ -22,6 +22,7 @@ import six import copy +import re from ipaclient.frontend import MethodOverride from ipalib import errors @@ -30,7 +31,8 @@ has_cli_options, iterate_rrparams_by_parts, record_name_format) -from ipalib.parameters import Bool +from ipalib.frontend import Command +from ipalib.parameters import Bool, Str from ipalib.plugable import Registry from ipalib import _, ngettext from ipapython.dnsutil import DNSName @@ -129,6 +131,63 @@ class dnszone_mod(DNSZoneMethodOverride): pass +# Support old servers without dnsrecord_split_parts +@register(no_fail=True) +class dnsrecord_split_parts(Command): + NO_CLI = True + + takes_args = ( + Str('name'), + Str('value'), + ) + + def execute(self, name, value, *args, **options): + def split_exactly(count): + values = value.split() + if len(values) != count: + return None + return tuple(values) + + result = () + + rrtype = get_record_rrtype(name) + if rrtype in ('A', 'AAAA', 'CNAME', 'DNAME', 'NS', 'PTR'): + result = split_exactly(1) + elif rrtype in ('AFSDB', 'KX', 'MX'): + result = split_exactly(2) + elif rrtype in ('CERT', 'DLV', 'DS', 'SRV', 'TLSA'): + result = split_exactly(4) + elif rrtype in ('NAPTR'): + result = split_exactly(6) + elif rrtype in ('A6', 'TXT'): + result = (value,) + elif rrtype == 'LOC': + regex = re.compile( + r'(?P<d1>\d{1,2}\s+)' + r'(?:(?P<m1>\d{1,2}\s+)' + r'(?P<s1>\d{1,2}(?:\.\d{1,3})?\s+)?)?' + r'(?P<dir1>[NS])\s+' + r'(?P<d2>\d{1,3}\s+)' + r'(?:(?P<m2>\d{1,2}\s+)' + r'(?P<s2>\d{1,2}(?:\.\d{1,3})?\s+)?)?' + r'(?P<dir2>[WE])\s+' + r'(?P<alt>-?\d{1,8}(?:\.\d{1,2})?)m?' + r'(?:\s+(?P<siz>\d{1,8}(?:\.\d{1,2})?)m?' + r'(?:\s+(?P<hp>\d{1,8}(?:\.\d{1,2})?)m?' + r'(?:\s+(?P<vp>\d{1,8}(?:\.\d{1,2})?)m?\s*)?)?)?$') + + m = regex.match(value) + if m is not None: + result = tuple( + x.strip() if x is not None else x for x in m.groups()) + elif rrtype == 'SSHFP': + values = value.split(None, 2) + if len(values) == 3: + result = tuple(values) + + return dict(result=result) + + @register(override=True, no_fail=True) class dnsrecord_add(MethodOverride): no_option_msg = 'No options to add a specific record provided.\n' \
-- Manage your subscription for the Freeipa-devel mailing list: https://www.redhat.com/mailman/listinfo/freeipa-devel Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code