Project

General

Profile

Actions

Bug #5178

closed

Users API requires parameters to be wrapped

Added by Thomas McKay about 10 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
High
Assignee:
Category:
API
Target version:
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

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 4 (0 open4 closed)

Related to Foreman - Bug #6248: Some JSON responses are still nested in a root nodeClosedJoseph Magen06/17/2014Actions
Related to Foreman - Bug #4181: V2: Api docs in foreman should not specify a root node for POST/PUTRejectedJoseph Magen01/24/2014Actions
Related to Foreman - Bug #6674: Can't create a host via the API because params aren't correctly wrappedDuplicateThomas McKay07/17/2014Actions
Related to Foreman - Bug #6696: API v2 - specify the key in which the parameters would be wrapped rather than passing model nameClosedJoseph Magen07/20/2014Actions
Actions

Also available in: Atom PDF