Project

General

Profile

Bug #26120

Insufficient parsing capabilities of complex list type options

Added by Martin Bacovsky about 4 years ago. Updated over 3 years ago.

Status:
Closed
Priority:
Normal
Category:
Hammer core
Target version:
-
Difficulty:
Triaged:
No
Bugzilla link:
Team Backlog:
Fixed in Releases:
Found in Releases:
In Kanboard:
Red Hat JIRA:

Description

It is not possible to parse complex parameters of type list. E.g.

hammer os create --architectures amd64,i386 --description "Windows 7 EN (2019-01)" --major 6 --minor 1.7601 --family Windows --partition-tables Empty --password-hash SHA256 --provisioning-templates winpe_clone,winpe_finish,winpe_pxelinux_boot_clone,winpe_unattend_template --name Windows7EM2019-01 --os-parameters-attributes="test=1,other=2" 

Error: ApipieBindings::InvalidArgumentTypesError: operatingsystem[os_parameters_attributes][0] - Hash was expected, operatingsystem[os_parameters_attributes][1] - Hash was expected

The field is defined as a list of hashes in the API

          param :os_parameters_attributes, Array, :desc => N_("Array of parameters") do
            param :name, String, :desc => N_("Name of the parameter"), :required => true
            param :value, String, :desc => N_("Parameter value"), :required => true
          end

Related issues

Related to Hammer CLI - Bug #20348: Hammer Does Not Consistently Escape Quotes When Assigning JSON To A Host Parameter.Resolved

Associated revisions

Revision 494ae8e3 (diff)
Added by Oleh Fedorenko almost 4 years ago

Fixes #26120 - Extended capabilities for list type options

History

#1 Updated by Martin Bacovsky about 4 years ago

At the very least we should allow to use JSON to provide the value

--os-parameters-attributes="[{\"name\":\"test\", \"value\":1}]" 

That possibility should be mentioned in the help. We may be able to construct and example based on the param description.

 --os-parameters-attributes OS_PARAMETERS_ATTRIBUTES   Array of parameters
                                                       Comma separated list of values. Values containing comma should be quoted or escaped with backslash

Is really hard to use without consulting the API docs.

We may think of something like following for the List normalizer to allow the JSON input.

         def format(val)
-          (val.is_a?(String) && !val.empty?) ? HammerCLI::CSVParser.new.parse(val) : []
+          return [] unless val.is_a?(String) && !val.empty?
+          begin
+              formatter = JSONInput.new
+              formatter.format(val)
+          rescue ArgumentError
+            HammerCLI::CSVParser.new.parse(val)
+          end
         end

#2 Updated by Martin Bacovsky about 4 years ago

  • Related to Bug #20348: Hammer Does Not Consistently Escape Quotes When Assigning JSON To A Host Parameter. added

#3 Updated by Oleh Fedorenko about 4 years ago

  • Assignee set to Oleh Fedorenko
  • Status changed from New to Assigned

#4 Updated by The Foreman Bot about 4 years ago

  • Status changed from Assigned to Ready For Testing
  • Pull request https://github.com/theforeman/hammer-cli/pull/298 added

#5 Updated by Oleh Fedorenko almost 4 years ago

  • Status changed from Ready For Testing to Closed

#6 Updated by Martin Bacovsky over 3 years ago

  • Fixed in Releases hammer-cli-0.17.0 added

Also available in: Atom PDF