[Freeipa-devel] [PATCH] 0009 Use cli_name if possible to return errors via exceptions in Param

Alexander Bokovoy abokovoy at redhat.com
Tue Aug 2 12:27:43 UTC 2011


On 01.08.2011 17:44, Rob Crittenden wrote:
> Alexander Bokovoy wrote:
>> Hi,
>>
>> as result of discussion on Param and environment/context, here is patch
>> to fix
>>      https://fedorahosted.org/freeipa/ticket/1549
>>      https://fedorahosted.org/freeipa/ticket/1550
>>
>> CLI and Web UI work.
> 
> nack.
> 
> When using ipalib outside of the cli the wrong attribute is in the error
> message. See the test program in
> https://fedorahosted.org/freeipa/attachment/ticket/187
> 
> In this sample the error when context='cli' should be 'desc' otherwise
> it should be 'description'. With your patch it is always 'desc'.
Following yesterday's discussion on IRC with Rob, I further investigated
the issue and came up with a following fix (attached).

The patch extends arguments supported by Param class to accept
environment and set it if it is not None before locking down the class.

It further extends create_param() helper function to re-create params
from a passed spec if provided environment is not None.

Command and Object now use create_param() to inject their environment
into specified arguments, parameters, and options.

There are might be more cases where using create_param(spec,
env=self.env) would be needed as I have found that, for example, running

ipa user-add

and not passing first name (--first) would give you

$ ./ipa user-add
First name:
ipa: ERROR: 'givenname' is required

while actual error should be

ipa: ERROR: 'first' is required

This is solved by the attached patch by introducing create_param() call
into Object while fixes in Command will give you protection for
client-side commands as well.

If approach is fine, I can find and fix other places.
-- 
/ Alexander Bokovoy
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: params-env-1.patch
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20110802/b6e6f291/attachment.ksh>


More information about the Freeipa-devel mailing list