403b09
From 7563ae6257c56555e502d40bc6fc2e142f850094 Mon Sep 17 00:00:00 2001
403b09
From: Jan Cholasta <jcholast@redhat.com>
403b09
Date: Fri, 2 Sep 2016 16:42:57 +0200
403b09
Subject: [PATCH] dns: prompt for missing record parts in CLI
403b09
403b09
Fix the code which determines if a record part is required and thus should
403b09
be prompted not to wrongfully consider all record parts to be optional.
403b09
403b09
https://fedorahosted.org/freeipa/ticket/6203
403b09
403b09
Reviewed-By: Martin Basti <mbasti@redhat.com>
403b09
---
403b09
 API.txt                  | 29 +++++++++++++++++++++++++++++
403b09
 VERSION                  |  4 ++--
403b09
 ipaclient/plugins/dns.py | 30 ++++++++++++++++--------------
403b09
 ipaserver/plugins/dns.py | 15 +++++++++++++++
403b09
 4 files changed, 62 insertions(+), 16 deletions(-)
403b09
403b09
diff --git a/API.txt b/API.txt
403b09
index 5b83bfbd0b457b77e0522ab7d83abfae4df3ebe9..fb5bf83cea0633130217cf1327481c8e9b11c4fc 100644
403b09
--- a/API.txt
403b09
+++ b/API.txt
403b09
@@ -6312,9 +6312,20 @@ default: dns_is_enabled/1
403b09
 default: dns_resolve/1
403b09
 default: dns_system_records/1
403b09
 default: dns_update_system_records/1
403b09
+default: dnsa6record/1
403b09
+default: dnsaaaarecord/1
403b09
+default: dnsafsdbrecord/1
403b09
+default: dnsaplrecord/1
403b09
+default: dnsarecord/1
403b09
+default: dnscertrecord/1
403b09
+default: dnscnamerecord/1
403b09
 default: dnsconfig/1
403b09
 default: dnsconfig_mod/1
403b09
 default: dnsconfig_show/1
403b09
+default: dnsdhcidrecord/1
403b09
+default: dnsdlvrecord/1
403b09
+default: dnsdnamerecord/1
403b09
+default: dnsdsrecord/1
403b09
 default: dnsforwardzone/1
403b09
 default: dnsforwardzone_add/1
403b09
 default: dnsforwardzone_add_permission/1
403b09
@@ -6325,6 +6336,16 @@ default: dnsforwardzone_find/1
403b09
 default: dnsforwardzone_mod/1
403b09
 default: dnsforwardzone_remove_permission/1
403b09
 default: dnsforwardzone_show/1
403b09
+default: dnshiprecord/1
403b09
+default: dnsipseckeyrecord/1
403b09
+default: dnskeyrecord/1
403b09
+default: dnskxrecord/1
403b09
+default: dnslocrecord/1
403b09
+default: dnsmxrecord/1
403b09
+default: dnsnaptrrecord/1
403b09
+default: dnsnsecrecord/1
403b09
+default: dnsnsrecord/1
403b09
+default: dnsptrrecord/1
403b09
 default: dnsrecord/1
403b09
 default: dnsrecord_add/1
403b09
 default: dnsrecord_del/1
403b09
@@ -6333,12 +6354,20 @@ default: dnsrecord_find/1
403b09
 default: dnsrecord_mod/1
403b09
 default: dnsrecord_show/1
403b09
 default: dnsrecord_split_parts/1
403b09
+default: dnsrprecord/1
403b09
+default: dnsrrsigrecord/1
403b09
 default: dnsserver/1
403b09
 default: dnsserver_add/1
403b09
 default: dnsserver_del/1
403b09
 default: dnsserver_find/1
403b09
 default: dnsserver_mod/1
403b09
 default: dnsserver_show/1
403b09
+default: dnssigrecord/1
403b09
+default: dnsspfrecord/1
403b09
+default: dnssrvrecord/1
403b09
+default: dnssshfprecord/1
403b09
+default: dnstlsarecord/1
403b09
+default: dnstxtrecord/1
403b09
 default: dnszone/1
403b09
 default: dnszone_add/1
403b09
 default: dnszone_add_permission/1
403b09
diff --git a/VERSION b/VERSION
403b09
index a8b89ed305bcfdf2990a7400d005a68d734fa7e8..796e9fea36b72f3a63372c84b9bfb1538efccfb7 100644
403b09
--- a/VERSION
403b09
+++ b/VERSION
403b09
@@ -90,5 +90,5 @@ IPA_DATA_VERSION=20100614120000
403b09
 #                                                      #
403b09
 ########################################################
403b09
 IPA_API_VERSION_MAJOR=2
403b09
-IPA_API_VERSION_MINOR=212
403b09
-# Last change: ab: service: add flag to allow S4U2Self
403b09
+IPA_API_VERSION_MINOR=213
403b09
+# Last change: dns: prompt for missing record parts in CLI
403b09
diff --git a/ipaclient/plugins/dns.py b/ipaclient/plugins/dns.py
403b09
index db9c17f8b523365779e53adfb2acc43f4a23401f..5e29b8c6666f94f52add7f2e1de8679127886fc2 100644
403b09
--- a/ipaclient/plugins/dns.py
403b09
+++ b/ipaclient/plugins/dns.py
403b09
@@ -25,10 +25,10 @@ import copy
403b09
 
403b09
 from ipaclient.frontend import MethodOverride
403b09
 from ipalib import errors
403b09
-from ipalib.dns import (get_part_rrtype,
403b09
-                        get_record_rrtype,
403b09
+from ipalib.dns import (get_record_rrtype,
403b09
                         has_cli_options,
403b09
                         iterate_rrparams_by_parts,
403b09
+                        part_name_format,
403b09
                         record_name_format)
403b09
 from ipalib.parameters import Bool
403b09
 from ipalib.plugable import Registry
403b09
@@ -46,9 +46,9 @@ _rev_top_record_types = ('PTR', )
403b09
 _zone_top_record_types = ('NS', 'MX', 'LOC', )
403b09
 
403b09
 
403b09
-def __get_part_param(cmd, part, output_kw, default=None):
403b09
-    name = part.name
403b09
-    label = unicode(part.label)
403b09
+def __get_part_param(rrtype, cmd, part, output_kw, default=None):
403b09
+    name = part_name_format % (rrtype.lower(), part.name)
403b09
+    label = unicode(cmd.params[name].label)
403b09
     optional = not part.required
403b09
 
403b09
     output_kw[name] = cmd.prompt_param(part,
403b09
@@ -64,29 +64,31 @@ def prompt_parts(rrtype, cmd, mod_dnsvalue=None):
403b09
             name, mod_dnsvalue)['result']
403b09
 
403b09
     user_options = {}
403b09
-    parts = [p for p in cmd.params() if get_part_rrtype(p.name) == rrtype]
403b09
-    if not parts:
403b09
+    try:
403b09
+        rrobj = cmd.api.Object['dns{}record'.format(rrtype.lower())]
403b09
+    except KeyError:
403b09
         return user_options
403b09
 
403b09
-    for part_id, part in enumerate(parts):
403b09
+    for part_id, part in enumerate(rrobj.params()):
403b09
         if mod_parts:
403b09
             default = mod_parts[part_id]
403b09
         else:
403b09
             default = None
403b09
 
403b09
-        __get_part_param(cmd, part, user_options, default)
403b09
+        __get_part_param(rrtype, cmd, part, user_options, default)
403b09
 
403b09
     return user_options
403b09
 
403b09
 
403b09
 def prompt_missing_parts(rrtype, cmd, kw, prompt_optional=False):
403b09
     user_options = {}
403b09
-    parts = [p for p in cmd.params() if get_part_rrtype(p.name) == rrtype]
403b09
-    if not parts:
403b09
+    try:
403b09
+        rrobj = cmd.api.Object['dns{}record'.format(rrtype.lower())]
403b09
+    except KeyError:
403b09
         return user_options
403b09
 
403b09
-    for part in parts:
403b09
-        name = part.name
403b09
+    for part in rrobj.params():
403b09
+        name = part_name_format % (rrtype.lower(), part.name)
403b09
 
403b09
         if name in kw:
403b09
             continue
403b09
@@ -96,7 +98,7 @@ def prompt_missing_parts(rrtype, cmd, kw, prompt_optional=False):
403b09
             continue
403b09
 
403b09
         default = part.get_default(**kw)
403b09
-        __get_part_param(cmd, part, user_options, default)
403b09
+        __get_part_param(rrtype, cmd, part, user_options, default)
403b09
 
403b09
     return user_options
403b09
 
403b09
diff --git a/ipaserver/plugins/dns.py b/ipaserver/plugins/dns.py
403b09
index 6f1bd716d202bd85dfc46b5eb94f73e85683b917..f048351e649fe0e8e2893627946333b14c11018a 100644
403b09
--- a/ipaserver/plugins/dns.py
403b09
+++ b/ipaserver/plugins/dns.py
403b09
@@ -3471,6 +3471,21 @@ class dnsrecord(LDAPObject):
403b09
             )
403b09
 
403b09
 
403b09
+# Make DNS record types available as objects in the API.
403b09
+# This is used by the CLI to get otherwise unavailable attributes of record
403b09
+# parts.
403b09
+for param in _dns_records:
403b09
+    register()(
403b09
+        type(
403b09
+            'dns{}record'.format(param.rrtype.lower()),
403b09
+            (Object,),
403b09
+            dict(
403b09
+                takes_params=(param.parts or ()) + (param.extra or ()),
403b09
+            )
403b09
+        )
403b09
+    )
403b09
+
403b09
+
403b09
 @register()
403b09
 class dnsrecord_split_parts(Command):
403b09
     NO_CLI = True
403b09
-- 
403b09
2.7.4
403b09