On 10/01/2013 11:00 PM, Nathaniel McCallum wrote:
On Thu, 2013-09-05 at 12:19 +0200, Petr Viktorin wrote:
On 09/05/2013 06:38 AM, Nathaniel McCallum wrote:
3. I had to make the 'id' option optional to make the uuid
autogeneration work in otp-add. However, this has the side-effect that
'id' is now optional in all the other commands. This is particularly bad
in the case of otp-del, where calling this command with no ID
transparently removes all tokens. How can I make this optional for
otp-add but required for all other commands?

You'll need to add a new option flag.

1. Add a 'optional_create' flag to the comment in ipalib.parameters.Param.
2. Handle the flag in ipalib.crud.Create.get_options (clone with
attribute=attribute, required=False)

See the handling of 'ask_create' for exapmles.

I spent part of yesterday and all day today working on this and I can't
make the attached patch work... No matter what I do, the Param with the
'optional_create' flag is never actually optional. There is no failure,
it just doesn't work. Any thoughts?

get_args is overridden in plugins/baseldap.py, and that contains a bug. Thanks for bringing this up!
Here's a patch, apply it on top of your "Add optional_create flag".

As a hint, the code in cli.py and frontend.py seems to call cmd.args()
rather than cmd.get_args(). Though, when I changed this it seemed to
break stuff. There seems to be lots of Python magic going on here via
the NameSpace class and I can't quite follow the logic.

Yeah, the framework is a bit of a maze. Sorry for that.

--
PetrĀ³
From 93a7d802f2c50a9cc90aabc1a4e1bdfb09547d3b Mon Sep 17 00:00:00 2001
From: Petr Viktorin <pvikt...@redhat.com>
Date: Wed, 2 Oct 2013 11:01:34 +0200
Subject: [PATCH] Fix bug in LDAPCreate and crud.Create get_args method

The methods used wrong super() calls and contained an additional
reimplementation of superclass functionality.

Use correct super() calls.
---
 ipalib/crud.py             | 2 ++
 ipalib/plugins/baseldap.py | 4 +---
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/ipalib/crud.py b/ipalib/crud.py
index 84d6a43201fb34b4c59e270b141cd609eb32492d..4c740bf69ec3abb57f0abd418872d462d99984a7 100644
--- a/ipalib/crud.py
+++ b/ipalib/crud.py
@@ -136,6 +136,8 @@ def get_args(self):
             if 'optional_create' in self.obj.primary_key.flags:
                 kw['required'] = False
             yield self.obj.primary_key.clone(**kw)
+        for arg in super(Create, self).get_args():
+            yield arg
 
     def get_options(self):
         if self.extra_options_first:
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 4a79502708c358dd20ede017037b16f691b76766..d29dce1bc5a9654f7300d5cce2d7c2d5a523fb47 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -994,9 +994,7 @@ def get_args(self):
         #pylint: disable=E1003
         for key in self.obj.get_ancestor_primary_keys():
             yield key
-        if self.obj.primary_key:
-            yield self.obj.primary_key.clone(attribute=True)
-        for arg in super(crud.Create, self).get_args():
+        for arg in super(LDAPCreate, self).get_args():
             yield arg
 
     has_output_params = global_output_params
-- 
1.8.3.1

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to