-
Notifications
You must be signed in to change notification settings - Fork 143
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
Add basic CentralAdmin support to the API #472
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5d11ea8
Add CentralAdmin support to the API
bdunne 23b8a38
Add CentralAdmin support to /api/vms for:
bdunne 81bb2b7
Add CentralAdmin support to /api/instances for:
bdunne 9922180
Refactor into vms and instances shared_examples
bdunne f685194
Move central admin tests into existing spec files
bdunne 504eda4
Existing tests should be using the current region
bdunne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Api | ||
module Mixins | ||
module CentralAdmin | ||
def self.extended(klass) | ||
unless klass.const_defined?("MethodRelay") | ||
method_relay = klass.const_set("MethodRelay", Module.new) | ||
klass.prepend(method_relay) | ||
end | ||
end | ||
|
||
def central_admin(method, action = method) | ||
const_get("MethodRelay").class_eval do | ||
define_method(method) do |*meth_args, &meth_block| | ||
api_args = yield(*meth_args) if block_given? | ||
|
||
type, id, _rest = meth_args | ||
|
||
if ApplicationRecord.id_in_current_region?(id.to_i) | ||
super(*meth_args, &meth_block) | ||
else | ||
region_number = ApplicationRecord.id_to_region(id) | ||
Api::Mixins::CentralAdmin.inter_region_call(region_number, @req.subject.to_sym, action, api_args, id).tap do |response| | ||
add_href_to_result(response, type, id) | ||
add_task_to_result(response, response["task_href"].split("api/tasks/").last) if response["task_href"] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
def self.inter_region_call(region, collection, action, api_args, id) | ||
InterRegionApiMethodRelay.exec_api_call(region, collection, action, api_args, id) | ||
rescue InterRegionApiMethodRelay::InterRegionApiMethodRelayError => error | ||
{"success" => false, "message" => error.message} | ||
end | ||
end | ||
end | ||
end | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
shared_examples "resource power operations" do |factory, operation| | ||
let!(:resource) { FactoryGirl.create(factory, :id => ApplicationRecord.id_in_region(1, region_remote.region)) } | ||
let(:api_client_collection) { double("/api/#{resource_type.pluralize}") } | ||
let(:api_client_connection) { double("ApiClient", :instances => api_client_collection) } | ||
let(:api_resource) { double(resource_type) } | ||
let(:operation) { operation } | ||
let(:region_remote) { FactoryGirl.create(:miq_region) } | ||
let(:url) { send("api_#{resource_type}_url", nil, resource) } | ||
|
||
it operation.to_s do | ||
api_basic_authorize(action_identifier(resource_type.pluralize.to_sym, operation)) | ||
|
||
expect(api_client_connection).to receive(resource_type.pluralize).and_return(api_client_collection) | ||
expect(InterRegionApiMethodRelay).to receive(:api_client_connection_for_region).with(region_remote.region).and_return(api_client_connection) | ||
expect(api_client_collection).to receive(:find).with(resource.id).and_return(api_resource) | ||
expect(api_resource).to receive(operation) | ||
|
||
post(url, :params => gen_request(operation)) | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enddddddd