Bug #5178

Users API requires parameters to be wrapped

Added by Thomas McKay over 4 years ago. Updated 8 days ago.

Status:Closed
Priority:High
Assignee:Joseph Magen
Category:API
Target version:1.6.0
Difficulty: Team Backlog:
Triaged: Fixed in Releases:
Bugzilla link:1087372 Found in Releases:
Pull request:https://github.com/theforeman/foreman/pull/1441

Description

Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1087372
Description of problem:
Calling
@api = ApipieBindings::API.new({
:uri => HammerCLI::Settings.get(:foreman, :host),
:username => HammerCLI::Settings.get(:foreman, :username),
:password => HammerCLI::Settings.get(:foreman, :password),
:api_version => 2
})
@api.resource(entity_type).call(:create, entity_hash)

expects different level of hash encapsulation for different entity_types:

  • for entity_type :organizations :
    @api.resource(:organizations).call(:create, entity_hash)
    the entity_hash is expected to be a simple hash of organization attributes {:description=>"Imported 'Red Hat IT' organization from Red Hat Satellite 5", :name=>"Red Hat IT"}
  • for entity_type :users :
    @api.resource(:users).call(:create, entity_hash)
    the entity_hash is expected to be a simple hash of user attributes embedded/wrapped into a extra higher level hash with a single :user key: {:user => user_hash} {:user=>{:location_ids=>[], :firstname=>"another", :role_ids=>[], :lastname=>"another", :login=>"another", :mail=>"root@localhost", :auth_source_id=>1, :organization_ids=>[5], :password=>"another_gfolvwxr"}}

Similarly the return values of these API calls are not consistent:

  • when creating an organization, the return value is an organization hash embedded in a higher level hash with one "organization" key {"organization" => organization_hash} {"organization"=>{"apply_info_task_id"=>nil, "updated_at"=>"2014-04-14T09:21:50Z", "description"=>"Imported 'Red Hat IT' organization from Red Hat Satellite 5", "default_info"=>{"system"=>[], "distributor"=>[]}, "id"=>2, "deletion_task_id"=>nil, "owner_auto_attach_all_systems_task_id"=>nil, "ancestry"=>nil, "created_at"=>"2014-04-14T09:21:49Z", "service_level"=>nil, "title"=>"Red Hat IT", "name"=>"Red Hat IT", "label"=>"Red_Hat_IT", "ignore_types"=>[], "service_levels"=>[]}}
  • when creating a new user, the API return value is a simple user_hash. {"locations"=>[], "lastname"=>"another", "firstname"=>"another", "roles"=>[{"name"=>"Anonymous", "id"=>8}], "updated_at"=>"2014-04-14T09:26:32Z", "admin"=>nil, "last_login_on"=>nil, "usergroups"=>[], "organizations"=>[{"title"=>"Red Hat IT", "name"=>"Red Hat IT", "id"=>5}], "created_at"=>"2014-04-14T09:26:32Z", "mail"=>"root@localhost", "id"=>4, "auth_source_id"=>1, "auth_source_name"=>"Internal", "login"=>"another", "auth_source_internal"=>{"type"=>"AuthSourceInternal", "name"=>"Internal", "id"=>1}}

Version-Release number of selected component (if applicable):
sat6-Satellite-6.0.3-RHEL-6-20140404.0-Satellite-x86_64-dvd1.iso

This is a request to unify to API parameter and return value encapsulation.


Related issues

Related to Foreman - Bug #6248: Some JSON responses are still nested in a root node Closed 06/17/2014
Related to Foreman - Bug #4181: V2: Api docs in foreman should not specify a root node fo... Rejected 01/24/2014
Related to Foreman - Bug #6674: Can't create a host via the API because params aren't cor... Duplicate 07/17/2014
Related to Foreman - Bug #6696: API v2 - specify the key in which the parameters would be... Closed 07/20/2014

Associated revisions

Revision c980e9a8
Added by Joseph Magen about 4 years ago

fixes #5178 - unify API parameters and return values. User creation should not require payload wrapped with 'user' root

History

#1 Updated by Thomas McKay over 4 years ago

  • Project changed from Katello to Foreman
  • Category set to API

Incorrectly put in katello project; fix is predominantly required in foreman to bring apipie params into compliance with documented style.

#2 Updated by Adam Price over 4 years ago

  • Priority changed from Normal to High

#3 Updated by David Davis over 4 years ago

The first part of this bug (requiring params be nested) is the same as http://projects.theforeman.org/issues/4181.

The second part of this bug is a new issue.

#4 Updated by Joseph Magen about 4 years ago

  • Status changed from New to Ready For Testing
  • Assignee set to Joseph Magen

PR 4181 is docs only, so it's not related to this.

This bug was caused by password [filtered] attributes not being wrapped, so POST /users didn't work unless the Hash was wrapped. Now it should work.

https://github.com/theforeman/foreman/pull/1441

#5 Updated by Joseph Magen about 4 years ago

  • Target version set to 1.8.3

#6 Updated by Dmitri Dolguikh about 4 years ago

  • Target version changed from 1.8.3 to 1.8.2

#8 Updated by Dominic Cleal about 4 years ago

  • Subject changed from unify API parameters and return values to Users API requires parameters to be wrapped

Return value of the taxonomy controllers has been moved to #5580, it's an unrelated issue.

#9 Updated by Bryan Kearney about 4 years ago

  • Status changed from Ready For Testing to Closed

Downstream bug is fixed, closing this.

#10 Updated by Dominic Cleal about 4 years ago

  • Status changed from Closed to Ready For Testing

Please don't close issues that have open pull requests, irrespective of bugzilla states.

#11 Updated by Dmitri Dolguikh about 4 years ago

  • Target version changed from 1.8.2 to 1.8.1

#12 Updated by Dominic Cleal about 4 years ago

  • Related to Bug #6248: Some JSON responses are still nested in a root node added

#13 Updated by Dominic Cleal about 4 years ago

  • Related to Bug #4181: V2: Api docs in foreman should not specify a root node for POST/PUT added

#14 Updated by Dmitri Dolguikh about 4 years ago

  • Target version changed from 1.8.1 to 1.8.0

#15 Updated by The Foreman Bot about 4 years ago

  • Pull request https://github.com/theforeman/foreman/pull/1441 added

#16 Updated by Joseph Magen about 4 years ago

  • Status changed from Ready For Testing to Closed
  • % Done changed from 0 to 100

#17 Updated by Dominic Cleal almost 4 years ago

  • Legacy Backlogs Release (now unused) set to 10

#18 Updated by Dominic Cleal almost 4 years ago

  • Related to Bug #6674: Can't create a host via the API because params aren't correctly wrapped added

#19 Updated by Dominic Cleal almost 4 years ago

  • Related to Bug #6696: API v2 - specify the key in which the parameters would be wrapped rather than passing model name added

Also available in: Atom PDF