500 Error Using REST API v2

Greetings, Foreman people.

I'm trying to update a user via the REST API and am getting a 500 error
doing so. Relevant code is as follows, using the rest-client rubygem:

require 'json'
require 'rest_client'

RestClient::Resource.new(
url,
:headers => {
:content_type => :json,
:accept => :json,
},
:ssl_ca_file => '/etc/pki/cacerts/cacerts.pem',
:ssl_client_cert =>
OpenSSL::X509::Certificate.new(File.read("/etc/pki/public/#{Socket.gethostname}.pub")),
:ssl_client_key =>
OpenSSL::PKey::RSA.new(File.read("/etc/pki/private/#{Socket.gethostname}.pem")),
:ssl_version => :TLSv1_2,
:user => 'admin',
:password => 'draw me like one of your french girls',
:verify_ssl => OpenSSL::SSL::VERIFY_PEER,
).put( {'user' => some_options }.to_json)

The error I'm seeing in my production log looks like this:

Started PUT "/api/v2/users/3" for 1.2.3.4 at 2015-03-07 06:10:28 +0000
Processing by Api::V2::UsersController#update as JSON
Parameters: {"user"=>{"login"=>"admin", "auth_source_id"=>1,
"password"=>"[FILTERED]", "admin"=>true, "mail"=>"awesome.user@my.domain",
"firstname"=>"Awesome", "lastname"=>"User"}, "apiv"=>"v2", "id"=>"5"}
Authorized user awesome.user(Awesome User)
undefined method admin=' for nil:NilClass (NoMethodError) /usr/share/foreman/app/controllers/concerns/foreman/controller/users_mixin.rb:48:inupdate_admin_flag'

Any thoughts on this? I checked users_mixin and it appears that the @user
object is nill, but that's about as far into debugging as I've made it.
Also, for what it's worth, it's not specific to this user. It happens with
any user any time I do a put or a post.

Thanks for the help.

Hello,
I tested your scenario and I'm afraid you found a bug. Any time one
tries to update user's admin flag the request fails with 500. Reported here:
http://projects.theforeman.org/issues/9678

The fix should be easy though so stay tuned for my PR.

Regards
Tomas

··· On 03/07/2015 07:32 AM, Kendall Moore wrote: > Greetings, Foreman people. > > I'm trying to update a user via the REST API and am getting a 500 error > doing so. Relevant code is as follows, using the rest-client rubygem: > > require 'json' > require 'rest_client' > > RestClient::Resource.new( > url, > :headers => { > :content_type => :json, > :accept => :json, > }, > :ssl_ca_file => '/etc/pki/cacerts/cacerts.pem', > :ssl_client_cert => > OpenSSL::X509::Certificate.new(File.read("/etc/pki/public/#{Socket.gethostname}.pub")), > :ssl_client_key => > OpenSSL::PKey::RSA.new(File.read("/etc/pki/private/#{Socket.gethostname}.pem")), > :ssl_version => :TLSv1_2, > :user => 'admin', > :password => 'draw me like one of your french girls', > :verify_ssl => OpenSSL::SSL::VERIFY_PEER, > ).put( {'user' => some_options }.to_json) > > The error I'm seeing in my production log looks like this: > > Started PUT "/api/v2/users/3" for 1.2.3.4 at 2015-03-07 06:10:28 +0000 > Processing by Api::V2::UsersController#update as JSON > Parameters: {"user"=>{"login"=>"admin", "auth_source_id"=>1, > "password"=>"[FILTERED]", "admin"=>true, > "mail"=>"awesome.user@my.domain", "firstname"=>"Awesome", > "lastname"=>"User"}, "apiv"=>"v2", "id"=>"5"} > Authorized user awesome.user(Awesome User) > undefined method `admin=' for nil:NilClass (NoMethodError) > /usr/share/foreman/app/controllers/concerns/foreman/controller/users_mixin.rb:48:in > `update_admin_flag' > > Any thoughts on this? I checked users_mixin and it appears that the > @user object is nill, but that's about as far into debugging as I've > made it. Also, for what it's worth, it's not specific to this user. It > happens with any user any time I do a put or a post. > > Thanks for the help. >

Thanks for the quick reply, and I'll be sure to stay tuned!

··· On Monday, March 9, 2015 at 5:09:17 AM UTC-4, Tomas Strachota wrote: > > On 03/07/2015 07:32 AM, Kendall Moore wrote: > > Greetings, Foreman people. > > > > I'm trying to update a user via the REST API and am getting a 500 error > > doing so. Relevant code is as follows, using the rest-client rubygem: > > > > require 'json' > > require 'rest_client' > > > > RestClient::Resource.new( > > url, > > :headers => { > > :content_type => :json, > > :accept => :json, > > }, > > :ssl_ca_file => '/etc/pki/cacerts/cacerts.pem', > > :ssl_client_cert => > > > OpenSSL::X509::Certificate.new(File.read("/etc/pki/public/#{Socket.gethostname}.pub")), > > > :ssl_client_key => > > > OpenSSL::PKey::RSA.new(File.read("/etc/pki/private/#{Socket.gethostname}.pem")), > > > :ssl_version => :TLSv1_2, > > :user => 'admin', > > :password => 'draw me like one of your french girls', > > :verify_ssl => OpenSSL::SSL::VERIFY_PEER, > > ).put( {'user' => some_options }.to_json) > > > > The error I'm seeing in my production log looks like this: > > > > Started PUT "/api/v2/users/3" for 1.2.3.4 at 2015-03-07 06:10:28 +0000 > > Processing by Api::V2::UsersController#update as JSON > > Parameters: {"user"=>{"login"=>"admin", "auth_source_id"=>1, > > "password"=>"[FILTERED]", "admin"=>true, > > "mail"=>"awesome.user@my.domain", "firstname"=>"Awesome", > > "lastname"=>"User"}, "apiv"=>"v2", "id"=>"5"} > > Authorized user awesome.user(Awesome User) > > undefined method `admin=' for nil:NilClass (NoMethodError) > > > /usr/share/foreman/app/controllers/concerns/foreman/controller/users_mixin.rb:48:in > > > `update_admin_flag' > > > > Any thoughts on this? I checked users_mixin and it appears that the > > @user object is nill, but that's about as far into debugging as I've > > made it. Also, for what it's worth, it's not specific to this user. It > > happens with any user any time I do a put or a post. > > > > Thanks for the help. > > > > Hello, > I tested your scenario and I'm afraid you found a bug. Any time one > tries to update user's admin flag the request fails with 500. Reported > here: > http://projects.theforeman.org/issues/9678 > > The fix should be easy though so stay tuned for my PR. > > Regards > Tomas >

> Thanks for the quick reply, and I'll be sure to stay tuned!

FYI the fix got merged today https://github.com/theforeman/foreman/pull/2231

T.

··· On 03/09/2015 02:57 PM, Kendall Moore wrote:

On Monday, March 9, 2015 at 5:09:17 AM UTC-4, Tomas Strachota wrote:

On 03/07/2015 07:32 AM, Kendall Moore wrote:
 > Greetings, Foreman people.
 >
 > I'm trying to update a user via the REST API and am getting a 500
error
 > doing so. Relevant code is as follows, using the rest-client
rubygem:
 >
 > require 'json'
 > require 'rest_client'
 >
 > RestClient::Resource.new(
 >        url,
 >        :headers => {
 >          :content_type    => :json,
 >          :accept          => :json,
 >        },
 >        :ssl_ca_file     => '/etc/pki/cacerts/cacerts.pem',
 >        :ssl_client_cert =>
 >
OpenSSL::X509::Certificate.new(File.read("/etc/pki/public/#{Socket.gethostname}.pub")),

 >        :ssl_client_key  =>
 >
OpenSSL::PKey::RSA.new(File.read("/etc/pki/private/#{Socket.gethostname}.pem")),

 >        :ssl_version     => :TLSv1_2,
 >        :user            => 'admin',
 >        :password     => 'draw me like one of your french girls',
 >        :verify_ssl      => OpenSSL::SSL::VERIFY_PEER,
 >      ).put( {'user' => some_options }.to_json)
 >
 > The error I'm seeing in my production log looks like this:
 >
 > Started PUT "/api/v2/users/3" for 1.2.3.4 at 2015-03-07 06:10:28
+0000
 > Processing by Api::V2::UsersController#update as JSON
 >    Parameters: {"user"=>{"login"=>"admin", "auth_source_id"=>1,
 > "password"=>"[FILTERED]", "admin"=>true,
 > "mail"=>"awesome.user@my.domain", "firstname"=>"Awesome",
 > "lastname"=>"User"}, "apiv"=>"v2", "id"=>"5"}
 > Authorized user awesome.user(Awesome User)
 > undefined method `admin=' for nil:NilClass (NoMethodError)
 >
/usr/share/foreman/app/controllers/concerns/foreman/controller/users_mixin.rb:48:in

 > `update_admin_flag'
 >
 > Any thoughts on this? I checked users_mixin and it appears that the
 > @user object is nill, but that's about as far into debugging as I've
 > made it. Also, for what it's worth, it's not specific to this
user. It
 > happens with any user any time I do a put or a post.
 >
 > Thanks for the help.
 >

Hello,
I tested your scenario and I'm afraid you found a bug. Any time one
tries to update user's admin flag the request fails with 500.
Reported here:
http://projects.theforeman.org/issues/9678
<http://projects.theforeman.org/issues/9678>

The fix should be easy though so stay tuned for my PR.

Regards
Tomas


You received this message because you are subscribed to the Google
Groups “Foreman users” group.
To unsubscribe from this group and stop receiving emails from it, send
an email to foreman-users+unsubscribe@googlegroups.com
mailto:foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com
mailto:foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

Thanks a bunch! I grabbed the fix myself and all is working as expected now.

··· On Tuesday, March 10, 2015 at 4:24:50 AM UTC-4, Tomas Strachota wrote: > > On 03/09/2015 02:57 PM, Kendall Moore wrote: > > Thanks for the quick reply, and I'll be sure to stay tuned! > > FYI the fix got merged today > https://github.com/theforeman/foreman/pull/2231 > > T. > > > > > On Monday, March 9, 2015 at 5:09:17 AM UTC-4, Tomas Strachota wrote: > > > > On 03/07/2015 07:32 AM, Kendall Moore wrote: > > > Greetings, Foreman people. > > > > > > I'm trying to update a user via the REST API and am getting a 500 > > error > > > doing so. Relevant code is as follows, using the rest-client > > rubygem: > > > > > > require 'json' > > > require 'rest_client' > > > > > > RestClient::Resource.new( > > > url, > > > :headers => { > > > :content_type => :json, > > > :accept => :json, > > > }, > > > :ssl_ca_file => '/etc/pki/cacerts/cacerts.pem', > > > :ssl_client_cert => > > > > > > OpenSSL::X509::Certificate.new(File.read("/etc/pki/public/#{Socket.gethostname}.pub")), > > > > > > :ssl_client_key => > > > > > > OpenSSL::PKey::RSA.new(File.read("/etc/pki/private/#{Socket.gethostname}.pem")), > > > > > > :ssl_version => :TLSv1_2, > > > :user => 'admin', > > > :password => 'draw me like one of your french girls', > > > :verify_ssl => OpenSSL::SSL::VERIFY_PEER, > > > ).put( {'user' => some_options }.to_json) > > > > > > The error I'm seeing in my production log looks like this: > > > > > > Started PUT "/api/v2/users/3" for 1.2.3.4 at 2015-03-07 06:10:28 > > +0000 > > > Processing by Api::V2::UsersController#update as JSON > > > Parameters: {"user"=>{"login"=>"admin", "auth_source_id"=>1, > > > "password"=>"[FILTERED]", "admin"=>true, > > > "mail"=>"awesome.user@my.domain", "firstname"=>"Awesome", > > > "lastname"=>"User"}, "apiv"=>"v2", "id"=>"5"} > > > Authorized user awesome.user(Awesome User) > > > undefined method `admin=' for nil:NilClass (NoMethodError) > > > > > > /usr/share/foreman/app/controllers/concerns/foreman/controller/users_mixin.rb:48:in > > > > > > `update_admin_flag' > > > > > > Any thoughts on this? I checked users_mixin and it appears that > the > > > @user object is nill, but that's about as far into debugging as > I've > > > made it. Also, for what it's worth, it's not specific to this > > user. It > > > happens with any user any time I do a put or a post. > > > > > > Thanks for the help. > > > > > > > Hello, > > I tested your scenario and I'm afraid you found a bug. Any time one > > tries to update user's admin flag the request fails with 500. > > Reported here: > > http://projects.theforeman.org/issues/9678 > > > > > > The fix should be easy though so stay tuned for my PR. > > > > Regards > > Tomas > > > > -- > > You received this message because you are subscribed to the Google > > Groups "Foreman users" group. > > To unsubscribe from this group and stop receiving emails from it, send > > an email to foreman-user...@googlegroups.com > > <mailto:foreman-users+unsubscribe@googlegroups.com >. > > To post to this group, send email to forema...@googlegroups.com > > > <mailto:forema...@googlegroups.com >. > > Visit this group at http://groups.google.com/group/foreman-users. > > For more options, visit https://groups.google.com/d/optout. > >