Bug 557163 - File parameter fails if prompted for
Summary: File parameter fails if prompted for
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: freeIPA
Classification: Retired
Component: ipa-admintools
Version: 2.0
Hardware: All
OS: Linux
low
medium
Target Milestone: v2 release
Assignee: Dmitri Pal
QA Contact: Chandrasekar Kannan
URL:
Whiteboard:
Depends On:
Blocks: 431020 737994
TreeView+ depends on / blocked
 
Reported: 2010-01-20 15:58 UTC by John Dennis
Modified: 2015-01-04 23:41 UTC (History)
5 users (show)

Fixed In Version: freeipa-2.1.3-5.fc16
Clone Of:
: 737994 (view as bug list)
Environment:
Last Closed: 2012-03-28 09:30:21 UTC
Embargoed:


Attachments (Terms of Use)

Description John Dennis 2010-01-20 15:58:07 UTC
The File parameter (parameters.py line 1298) does not work properly unless it's provided on the command line. If the command prompts for the parameter it fails. For example if one has a file called "csr" containing a certificate signing request this works:

ipa cert-request --principal=foo/vm-041.idm.lab.bos.redhat.com csr

however this does not:

ipa cert-request --principal=foo/vm-041.idm.lab.bos.redhat.com
<csr>: csr
ipa: ERROR: Base64 decoding failed: Incorrect padding

The reason it fails is because the validation function is being called on the file name not the file contents:

The parameter is defined like this:

    takes_args = (
        File('csr', validate_csr,
            cli_name='csr_file',
        ),
    )

If csr is not provided on the command line it's prompted for and validate_csr is invoked being passed the filename entered on the command line, however validate_csr is expecting file contents.

The reason why it works when passed on the command line is because of the function load_files() in cli.py which is invoked in the run method of the command which loads the file contents and runs the validation routine on the file contents.

The problem occurs in prompt_interactively() in cli.py which calls the parameter like this:

value = param(raw, **kw)

which invokes the validation routine. But the raw value is what was read from the terminal, it's the file name. There is no mechanism to cause contents of the file to be read, so the validation routine sees the file name, not the file contents and it fails.

Comment 1 John Dennis 2010-01-20 17:20:14 UTC
Maybe Jason can chime in. I just don't see anyway to support the concept of File parameters using the existing parameter mechanism without a lot of special case hacks spread through the code. The fundamental problems are that the Parameter classes are read only descriptions of what the parameter should look like but don't actually contain the parameter value. The parameter value is in the kw dict of the command and there is no way for the parameter mechanism to know if what's in the kw dict has been operated on (e.g. the file name replaced with the file contents). If that were true then the normalize and/or validate routine could be used to transform the file name into the file contents, but we can't do that because we have to set a flag indicating if the file contents have been read and there is no place to set such a flag.

Comment 3 Martin Kosek 2011-09-12 07:47:30 UTC
Upstream ticket:
https://fedorahosted.org/freeipa/ticket/1777


Note You need to log in before you can comment on or make changes to this bug.