Skip to content

Commit

Permalink
use OPTIONS /api/providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Erez Freiberger committed Aug 9, 2017
1 parent 673664d commit fe1ba1f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/controllers/api/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ def import_vm_resource(type, id = nil, data = {})
end
end

def options
if params[:ems_type].blank?
all_options = Hash[ExtManagementSystem.descendants.collect do |ems|
[ems.ems_type, ems.respond_to?(:provider_settings) ? ems.provider_settings : {}]
end
]
all_options.delete(nil)
render_options(:providers, all_options)
else
ems_class = ExtManagementSystem.descendants.find { |ems| ems.ems_type == params[:ems_type] }
render_options(:providers, ems_class.respond_to?(:provider_settings) ? ems_class.provider_settings : {})
end
end

private

def format_provider_custom_attributes(attribute)
Expand Down
24 changes: 24 additions & 0 deletions spec/requests/api/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1116,4 +1116,28 @@ def gen_import_request
end
end
end

context "OPTIONS /api/providers" do
it "returns options for all providers when no query" do
api_basic_authorize
run_options(providers_url)
expect(response.parsed_body["data"].keys.count).to eq(
ExtManagementSystem.descendants.select { |ems| !ems.ems_type.blank?}.count)
expect(response.parsed_body["data"]["kubernetes"]["proxy_settings"]["settings"]["http_proxy"]["label"]).to eq(N_('HTTP Proxy'))
end

it "returns options for all queried provider class" do
api_basic_authorize
ExtManagementSystem.descendants.select { |ems| ems.respond_to?(:provider_settings) }.each do |ems_type|
run_options("#{providers_url}?ems_type=#{ems_type.ems_type}")
expect_options_results(:providers, JSON.parse(ems_type.provider_settings.to_json))
end
end

it "returns proxy settings options for kubernetes provider" do
api_basic_authorize
run_options(providers_url + "?ems_type=kubernetes")
expect(response.parsed_body["data"]["proxy_settings"]["settings"]["http_proxy"]["label"]).to eq(N_('HTTP Proxy'))
end
end
end

0 comments on commit fe1ba1f

Please sign in to comment.