Looks like it… perhaps you can add the following line to
"check_content_type" in
/usr/share/foreman/app/controllers/api/v2/base_controller.rb, then
restart Apache.
···
On 07/10/14 13:30, Herwig Bogaert wrote:
> Hi
>
> The following code results in a HTTP error 415 when running in our
> Foreman 1.6 environment.
>
> In our Foreman 1.5.2 environment, this runs just fine.
>
> Running similar post requests with json data via curl runs fine in both
> environments (1.5.2 and 1.6).
>
> #!/usr/bin/env ruby
>
> require 'rubygems'
> require 'rest-client'
> require 'json'
> matcher = 'environment=development'
> client = RestClient::Resource.new('https://foreman/api', :user =>
> 'admin', :password => '********', :headers => { :accept =>
> 'application/json;version=2' })
> newhash = { 'testkey' => "testvalue"}.to_json
> response = client["smart_class_parameters/664/override_values"].post(
> { :override_value => { :match => matcher,:value => newhash } },
> :content_type => 'application/json')
>
> The main difference between the two environments is the foreman version,
> hence I suspect something is wrong in parsing the request body generated
> by ruby rest-client in foreman 1.6.
>
> Foreman production.log (it does not contain more relevant information
> when foreman runs in debug mode).:
>
> Started POST "/api/smart_class_parameters/664/override_values" for
> 10.9.120.2 at 2014-10-07 14:17:57 +0200
> Processing by Api::V2::OverrideValuesController#create as JSON
> Parameters: {"override_value"=>"[FILTERED]", "apiv"=>"v2",
> "smart_class_parameter_id"=>"664"}
> Authorized user admin(Admin User)
> Rendered api/v2/errors/unsupported_content_type.json.rabl within
> api/v2/layouts/error_layout (1.0ms)
>
> Is this a bug ?
This solves the problem for me, but let me know if you are still interested
in the result of the check-content-type output…
Best regards
Herwig
···
On Tuesday, October 7, 2014 2:37:55 PM UTC+2, Dominic Cleal wrote:
>
> On 07/10/14 13:30, Herwig Bogaert wrote:
> > Hi
> >
> > The following code results in a HTTP error 415 when running in our
> > Foreman 1.6 environment.
> >
> > In our Foreman 1.5.2 environment, this runs just fine.
> >
> > Running similar post requests with json data via curl runs fine in both
> > environments (1.5.2 and 1.6).
> >
> > #!/usr/bin/env ruby
> >
> > require 'rubygems'
> > require 'rest-client'
> > require 'json'
> > matcher = 'environment=development'
> > client = RestClient::Resource.new('https://foreman/api', :user =>
> > 'admin', :password => '********', :headers => { :accept =>
> > 'application/json;version=2' })
> > newhash = { 'testkey' => "testvalue"}.to_json
> > response = client["smart_class_parameters/664/override_values"].post(
> > { :override_value => { :match => matcher,:value => newhash } },
> > :content_type => 'application/json')
> >
> > The main difference between the two environments is the foreman version,
> > hence I suspect something is wrong in parsing the request body generated
> > by ruby rest-client in foreman 1.6.
> >
> > Foreman production.log (it does not contain more relevant information
> > when foreman runs in debug mode).:
> >
> > Started POST "/api/smart_class_parameters/664/override_values" for
> > 10.9.120.2 at 2014-10-07 14:17:57 +0200
> > Processing by Api::V2::OverrideValuesController#create as JSON
> > Parameters: {"override_value"=>"[FILTERED]", "apiv"=>"v2",
> > "smart_class_parameter_id"=>"664"}
> > Authorized user admin(Admin User)
> > Rendered api/v2/errors/unsupported_content_type.json.rabl within
> > api/v2/layouts/error_layout (1.0ms)
> >
> > Is this a bug ?
>
> Looks like it.. perhaps you can add the following line to
> "check_content_type" in
> /usr/share/foreman/app/controllers/api/v2/base_controller.rb, then
> restart Apache.
>
> logger.warn("Detected content type: #{request.content_type.inspect}")
>
> --
> Dominic Cleal
> Red Hat Engineering
>