Project

General

Profile

Actions

Bug #26120

closed

Insufficient parsing capabilities of complex list type options

Added by Martin Bacovsky over 5 years ago. Updated over 5 years ago.

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

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 1 (0 open1 closed)

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

Updated by Martin Bacovsky over 5 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

Actions #2

Updated by Martin Bacovsky over 5 years ago

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

Updated by Oleh Fedorenko over 5 years ago

  • Status changed from New to Assigned
  • Assignee set to Oleh Fedorenko
Actions #4

Updated by The Foreman Bot over 5 years ago

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

Updated by Oleh Fedorenko over 5 years ago

  • Status changed from Ready For Testing to Closed
Actions #6

Updated by Martin Bacovsky over 5 years ago

  • Fixed in Releases hammer-cli-0.17.0 added
Actions

Also available in: Atom PDF