Red Hat Satellite engineering is moving the tracking of its product development work on Satellite to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "Satellite project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs will be migrated starting at the end of May. If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "Satellite project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/SAT-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1941126 - [BUG] The " POST /api/hosts/:id/parameters " API endpoint does not work as expected in case of value in Array format.
Summary: [BUG] The " POST /api/hosts/:id/parameters " API endpoint does not work as ex...
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Satellite
Classification: Red Hat
Component: Parameters
Version: 6.9.0
Hardware: All
OS: All
unspecified
medium
Target Milestone: Unspecified
Assignee: satellite6-bugs
QA Contact: Peter Ondrejka
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-03-20 07:48 UTC by Sayan Das
Modified: 2022-12-02 17:25 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-12-02 17:25:56 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Foreman Issue Tracker 35254 0 Normal New The " POST /api/hosts/:id/parameters " API endpoint does not work as expected in case of value in Array format. 2022-07-20 08:26:32 UTC

Description Sayan Das 2021-03-20 07:48:38 UTC
Problem Description:

The " POST /api/hosts/:id/parameters " API endpoint does not work as expected in the case of value in an Array format.


Version-Release number of selected component (if applicable):

Any satellite version



How Reproducible :

100%



Reproducer Steps and Actual Results:

Let's assume the following parameters,

Host ID: 3

Actual Param name: myparam

Actual Value : ["item1","item2"]    ## This can be used in both UI and hammer.


Scenario 0: When using GUI or hammer i.e. hammer -d host set-parameter --host-id 3 --name myparam --parameter-type array --value ["item1","item2"] 

The API POST data looks like as below,
~~
[ INFO 2021-03-20T13:05:45 API] POST /api/hosts/3/parameters
[DEBUG 2021-03-20T13:05:45 API] Params: {
    "parameter" => {
                  "name" => "myparam",
                 "value" => "[item1,item2]",
        "parameter_type" => "array",
          "hidden_value" => nil
    }
}
..
..
[DEBUG 2021-03-20T13:05:45 API] Response: {
          "priority" => 70,
        "created_at" => "2021-03-20 07:35:45 UTC",
        "updated_at" => "2021-03-20 07:35:45 UTC",
                "id" => 19,
              "name" => "myparam",
    "parameter_type" => "array",
             "value" => [
        [0] "item1",
        [1] "item2"
    ]
}
~~

	--> As we can see that,
		input value is --> ["item1","item2"]  which is in array format
		Processed value is --> "[item1,item2]" which is basically a string conversion of the array format
		output value is same as input value i.e. the expected array value.


Let's Consider 4 more scenarios, 


Scenario 1: Null Value being passed when mentioning the value in the same way as we mention with hammer or in UI --> ["item1","item2"] 

# cat data1.json 
{
	"parameter": {
		"parameter_type": "array",
		"name": "myparam",
		"value": ["item1","item2"]
	}
}


# json_verify < data1.json
JSON is valid

# curl -ksu admin:RedHat1! -X POST -H "Accept:application/json,version=2" -H "Content-Type:application/json" https://`hostname -f`/api/hosts/3/parameters -d @data1.json | json_reformat | grep myparam -A3
    "name": "myparam",
    "parameter_type": "array",
    "value": null
}


Logging,

~~
2021-03-20T12:51:58 [I|app|b4828eff] Started POST "/api/hosts/3/parameters" for 127.0.0.1 at 2021-03-20 12:51:58 +0530
2021-03-20T12:51:58 [I|app|b4828eff] Processing by Api::V2::ParametersController#create as JSON
2021-03-20T12:51:58 [I|app|b4828eff]   Parameters: {"parameter"=>{"parameter_type"=>"array", "name"=>"myparam", "value"=>"[FILTERED]"}, "apiv"=>"v2", "host_id"=>"3"}
2021-03-20T12:51:58 [I|app|b4828eff] Authorized user admin(Admin User)
2021-03-20T12:51:58 [I|aud|b4828eff] Parameter (14) create event on name myparam
2021-03-20T12:51:58 [I|aud|b4828eff] Parameter (14) create event on value 
2021-03-20T12:51:58 [I|aud|b4828eff] Parameter (14) create event on reference_id 3
2021-03-20T12:51:58 [I|aud|b4828eff] Parameter (14) create event on hidden_value false
2021-03-20T12:51:58 [I|aud|b4828eff] Parameter (14) create event on key_type array
2021-03-20T12:51:58 [I|app|b4828eff]   Rendering api/v2/parameters/create.json.rabl
2021-03-20T12:51:58 [I|app|b4828eff]   Rendered api/v2/parameters/create.json.rabl (Duration: 9.0ms | Allocations: 7575)
~~



Scenario 2: Correct value gets created, While escaping the value in this way --> "[\"item1\",\"item2\"]" 


# cat data2.json 
{
	"parameter": {
		"parameter_type": "array",
		"name": "myparam",
		"value": "[\"item1\",\"item2\"]"
	}
}


# json_verify < data2.json 
JSON is valid


# curl -ksu admin:RedHat1! -X POST -H "Accept:application/json,version=2" -H "Content-Type:application/json" https://`hostname -f`/api/hosts/3/parameters -d @data2.json | json_reformat | grep myparam -A5
    "name": "myparam",
    "parameter_type": "array",
    "value": [
        "item1",
        "item2"
    ]


Logging,

2021-03-20T12:55:39 [I|app|8786ca0c] Started POST "/api/hosts/3/parameters" for 127.0.0.1 at 2021-03-20 12:55:39 +0530
2021-03-20T12:55:39 [I|app|8786ca0c] Processing by Api::V2::ParametersController#create as JSON
2021-03-20T12:55:39 [I|app|8786ca0c]   Parameters: {"parameter"=>{"parameter_type"=>"array", "name"=>"myparam", "value"=>"[FILTERED]"}, "apiv"=>"v2", "host_id"=>"3"}
2021-03-20T12:55:39 [I|app|8786ca0c] Authorized user admin(Admin User)
2021-03-20T12:55:39 [I|aud|8786ca0c] Parameter (16) create event on name myparam
2021-03-20T12:55:39 [I|aud|8786ca0c] Parameter (16) create event on value ["item1", "item2"]
2021-03-20T12:55:39 [I|aud|8786ca0c] Parameter (16) create event on reference_id 3
2021-03-20T12:55:39 [I|aud|8786ca0c] Parameter (16) create event on hidden_value false
2021-03-20T12:55:39 [I|aud|8786ca0c] Parameter (16) create event on key_type array
2021-03-20T12:55:39 [I|app|8786ca0c]   Rendering api/v2/parameters/create.json.rabl
2021-03-20T12:55:39 [I|app|8786ca0c]   Rendered api/v2/parameters/create.json.rabl (Duration: 9.1ms | Allocations: 7576)
2021-03-20T12:55:39 [I|app|8786ca0c] Completed 201 Created in 148ms (Views: 10.0ms | ActiveRecord: 12.8ms | Allocations: 27207)




Scenario 3: Correct value gets created , While posting the value in this way --> "['item1','item2']" 

# cat data3.json 
{
	"parameter": {
		"parameter_type": "array",
		"name": "myparam",
		"value": "['item1','item2']"
	}
}


# json_verify < data3.json 
JSON is valid


# curl -ksu admin:RedHat1! -X POST -H "Accept:application/json,version=2" -H "Content-Type:application/json" https://`hostname -f`/api/hosts/3/parameters -d @data3.json | json_reformat | grep myparam -A5
    "name": "myparam",
    "parameter_type": "array",
    "value": [
        "item1",
        "item2"
    ]




Logging,


2021-03-20T13:00:19 [I|app|003a94d6] Started POST "/api/hosts/3/parameters" for 127.0.0.1 at 2021-03-20 13:00:19 +0530
2021-03-20T13:00:19 [I|app|003a94d6] Processing by Api::V2::ParametersController#create as JSON
2021-03-20T13:00:19 [I|app|003a94d6]   Parameters: {"parameter"=>{"parameter_type"=>"array", "name"=>"myparam", "value"=>"[FILTERED]"}, "apiv"=>"v2", "host_id"=>"3"}
2021-03-20T13:00:19 [I|app|003a94d6] Authorized user admin(Admin User)
2021-03-20T13:00:19 [I|aud|003a94d6] Parameter (17) create event on name myparam
2021-03-20T13:00:19 [I|aud|003a94d6] Parameter (17) create event on value ["item1", "item2"]
2021-03-20T13:00:19 [I|aud|003a94d6] Parameter (17) create event on reference_id 3
2021-03-20T13:00:19 [I|aud|003a94d6] Parameter (17) create event on hidden_value false
2021-03-20T13:00:19 [I|aud|003a94d6] Parameter (17) create event on key_type array
2021-03-20T13:00:19 [I|app|003a94d6]   Rendering api/v2/parameters/create.json.rabl
2021-03-20T13:00:19 [I|app|003a94d6]   Rendered api/v2/parameters/create.json.rabl (Duration: 10.6ms | Allocations: 7578)
2021-03-20T13:00:19 [I|app|003a94d6] Completed 201 Created in 156ms (Views: 11.4ms | ActiveRecord: 14.7ms | Allocations: 27191)



Scenario 4: Correct value gets created if I post the value in the same way hammer converts it before doing a POST i.e. "[item1,item2]"


# cat data4.json 
{
	"parameter": {
		"parameter_type": "array",
		"name": "myparam",
		"value": "[item1,item2]"
	}
}


# json_verify < data4.json 
JSON is valid

# curl -ksu admin:RedHat1! -X POST -H "Accept:application/json,version=2" -H "Content-Type:application/json" https://`hostname -f`/api/hosts/3/parameters -d @data4.json | json_reformat | grep myparam -A5
    "name": "myparam",
    "parameter_type": "array",
    "value": [
        "item1",
        "item2"
    ]



Logging,

2021-03-20T13:04:01 [I|app|c4c99dfb] Started POST "/api/hosts/3/parameters" for 127.0.0.1 at 2021-03-20 13:04:01 +0530
2021-03-20T13:04:01 [I|app|c4c99dfb] Processing by Api::V2::ParametersController#create as JSON
2021-03-20T13:04:01 [I|app|c4c99dfb]   Parameters: {"parameter"=>{"parameter_type"=>"array", "name"=>"myparam", "value"=>"[FILTERED]"}, "apiv"=>"v2", "host_id"=>"3"}
2021-03-20T13:04:01 [I|app|c4c99dfb] Authorized user admin(Admin User)
2021-03-20T13:04:01 [I|aud|c4c99dfb] Parameter (18) create event on name myparam
2021-03-20T13:04:01 [I|aud|c4c99dfb] Parameter (18) create event on value ["item1", "item2"]
2021-03-20T13:04:01 [I|aud|c4c99dfb] Parameter (18) create event on reference_id 3
2021-03-20T13:04:01 [I|aud|c4c99dfb] Parameter (18) create event on hidden_value false
2021-03-20T13:04:01 [I|aud|c4c99dfb] Parameter (18) create event on key_type array
2021-03-20T13:04:01 [I|app|c4c99dfb]   Rendering api/v2/parameters/create.json.rabl
2021-03-20T13:04:01 [I|app|c4c99dfb]   Rendered api/v2/parameters/create.json.rabl (Duration: 8.4ms | Allocations: 7591)



Scenario 1 and scenario 4 is being considered as a bug as,

      In scenario 1 -> blank value is being posted even if that is a valid JSON
      In scenario 4 -> correct array value is being created even if the data format is not an array but actually a string representation of that array



Expected Results:

	Scenario 1, should be able to create the param with the expected value and the hammer should also not process the array data into a different format before POST'ing it. This is being expected as API should allow data input in the same way we can do from GUI while creating a host parameter.


Additional Info:

This is reproducible with any version of the satellite. and CU will like to know why the hammer behaves in that way as displayed in Scenario 0?

This question has been

Comment 1 Leos Stejskal 2022-07-20 08:26:31 UTC
Created redmine issue https://projects.theforeman.org/issues/35254 from this bug

Comment 2 Brad Buckingham 2022-11-03 21:47:07 UTC
Upon review of our valid but aging backlog the Satellite Team has concluded that this Bugzilla does not meet the criteria for a resolution in the near term, and are planning to close in a month. This message may be a repeat of a previous update and the bug is again being considered to be closed. If you have any concerns about this, please contact your Red Hat Account team.  Thank you.

Comment 3 Brad Buckingham 2022-12-02 17:25:56 UTC
Thank you for your interest in Red Hat Satellite. We have evaluated this request, and while we recognize that it is a valid request, we do not expect this to be implemented in the product in the foreseeable future. This is due to other priorities for the product, and not a reflection on the request itself. We are therefore closing this out as WONTFIX. If you have any concerns about this feel free to contact your Red Hat Account Team. Thank you.


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