Bug #5178
Users API requires parameters to be wrapped
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
Associated revisions
History
#1
Updated by Thomas McKay almost 9 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 almost 9 years ago
- Priority changed from Normal to High
#3
Updated by David Davis almost 9 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 almost 9 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.
#5
Updated by Joseph Magen almost 9 years ago
- Target version set to 1.8.3
#6
Updated by Anonymous almost 9 years ago
- Target version changed from 1.8.3 to 1.8.2
#8
Updated by Dominic Cleal almost 9 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 almost 9 years ago
- Status changed from Ready For Testing to Closed
Downstream bug is fixed, closing this.
#10
Updated by Dominic Cleal almost 9 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 Anonymous almost 9 years ago
- Target version changed from 1.8.2 to 1.8.1
#12
Updated by Dominic Cleal almost 9 years ago
- Related to Bug #6248: Some JSON responses are still nested in a root node added
#13
Updated by Dominic Cleal almost 9 years ago
- Related to Bug #4181: V2: Api docs in foreman should not specify a root node for POST/PUT added
#14
Updated by Anonymous over 8 years ago
- Target version changed from 1.8.1 to 1.8.0
#15
Updated by The Foreman Bot over 8 years ago
- Pull request https://github.com/theforeman/foreman/pull/1441 added
#16
Updated by Joseph Magen over 8 years ago
- Status changed from Ready For Testing to Closed
- % Done changed from 0 to 100
Applied in changeset c980e9a8917cc9fdee5835732428462e22fa3f5b.
#17
Updated by Dominic Cleal over 8 years ago
- Legacy Backlogs Release (now unused) set to 10
#18
Updated by Dominic Cleal over 8 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 over 8 years ago
- Related to Bug #6696: API v2 - specify the key in which the parameters would be wrapped rather than passing model name added
fixes #5178 - unify API parameters and return values. User creation should not require payload wrapped with 'user' root