Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for /api/requests creation and edits #11892

Merged
merged 8 commits into from
Oct 21, 2016

Conversation

abellotti
Copy link
Member

  • Support for creates via POST /api/requests
  • Support for edits via POST /api/requests/:id - action "edit"

@abellotti
Copy link
Member Author

abellotti commented Oct 12, 2016

Marked as WIP

TODO's

  • tire kicking

@abellotti
Copy link
Member Author

abellotti commented Oct 12, 2016

Basic usage:

POST /api/requests
{
  "options" : {
     "request_type" : "service_reconfigure",
     "src_id" : 4
  },
  "requester" : {
    "user_name" : "admin"
  },
  "auto_approve" : false
}
GET /api/requests/:id
GET /api/requests/:id?expand=tasks

@abellotti
Copy link
Member Author

abellotti commented Oct 12, 2016

/cc @bdunne @carbonin

WIP, but was able to create a request from API client.

miq.requests.create(:options => { :request_type => "service_reconfigure", :src_id => 4}, :auto_approve => false)

def create_resource(type, _id, data)
assert_id_not_specified(data, type)

request_type = data.delete("request_type")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:request_type is an attribute on MiqRequest, so it's probably not safe to use that.

include Subcollections::RequestTasks
include Subcollections::Tasks

def create_resource(type, _id, data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need _id since it isn't used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API signature for _resource.


requester = Hash(data.delete("requester"))
user = fetch_requester_user(requester)
auto_approve = fetch_auto_approve(requester)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The auto_approve flag lives under the requester?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, was using an example from MiqProvisionVirtWorkflow. Moved that puppy out so it is its own parameter now.

request_type.constantize.create_request(data.symbolize_keys, user, auto_approve)
end

def edit_resource(type, id = nil, data = {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is type? I'm assuming STI type, but not sure why we would need that if we have an ID.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

collection type, API signature as above.

raise BadRequestError, "Must specify a id for editing a #{type} resource" unless id
request_klass = collection_class(:requests)
request = resource_search(id, type, request_klass)
user = fetch_requester_user(Hash(data.delete("requester")))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user updating the request may not be the requester.

:collection_actions:
:get:
- :name: read
:identifier: miq_request_show_list
:post:
- :name: query
:identifier: miq_request_show_list
- :name: create
:identifier: vm_miq_request_new
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MiqRequests are not tied to only VMs

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this needs to change. Couldn't fine a generic miq_request_new role identifier. Part of the TODO is to support different identifier based on request_type. One option is to open the door here (no role check), but enforce it in the create method based on the type.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, role identifier per request type now provided by model and used for authorization.

@abellotti abellotti force-pushed the api_create_requests branch 4 times, most recently from 112d7ca to 5a30357 Compare October 18, 2016 22:50
@miq-bot
Copy link
Member

miq-bot commented Oct 19, 2016

Checked commits abellotti/manageiq@a4a8c11~...a6d6e3e with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
2 files checked, 0 offenses detected
Everything looks good. 🏆

Copy link
Member

@carbonin carbonin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @abellotti

@bdunne bdunne removed the wip label Oct 21, 2016
@carbonin
Copy link
Member

Tested this out with the API client gem and it looks good. I think we can un-wip and merge.

@bdunne
Copy link
Member

bdunne commented Oct 21, 2016

Tires have been kicked and everything looks good

@bdunne bdunne changed the title [WIP] Adding support for /api/requests creation and edits Adding support for /api/requests creation and edits Oct 21, 2016
@bdunne bdunne merged commit aacbf4f into ManageIQ:master Oct 21, 2016
@bdunne bdunne added this to the Sprint 48 Ending Oct 24, 2016 milestone Oct 21, 2016
@abellotti abellotti deleted the api_create_requests branch October 21, 2016 21:34
chessbyte pushed a commit that referenced this pull request Oct 21, 2016
Adding support for /api/requests creation and edits
(cherry picked from commit aacbf4f)
@chessbyte
Copy link
Member

Euwe Backport details:

$ git log -1
commit 72c9b0a4051baf1b169409f5485bd20b240cdd6d
Author: Brandon Dunne <brandondunne@hotmail.com>
Date:   Fri Oct 21 14:18:01 2016 -0400

    Merge pull request #11892 from abellotti/api_create_requests

    Adding support for /api/requests creation and edits
    (cherry picked from commit aacbf4f6fb2dc5edbc5ff52f9c8a40b68b415306)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants