From accf8654e996b55bb954317180a5e7c14e3703fc Mon Sep 17 00:00:00 2001 From: Erez Freiberger Date: Sun, 6 Aug 2017 11:00:44 +0300 Subject: [PATCH] use OPTIONS /api/providers --- app/controllers/api/providers_controller.rb | 9 +++++++++ spec/requests/providers_spec.rb | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/controllers/api/providers_controller.rb b/app/controllers/api/providers_controller.rb index 9f182a0a3b..06663409c0 100644 --- a/app/controllers/api/providers_controller.rb +++ b/app/controllers/api/providers_controller.rb @@ -85,6 +85,15 @@ def import_vm_resource(type, id = nil, data = {}) end end + def options + all_options = ExtManagementSystem.descendants.inject({}) do |ao, ems| + ao[ems.ems_type] = ems.respond_to?(:provider_settings) ? ems.provider_settings : {} + ao + end + all_options.delete(nil) + render_options(:providers, all_options) + end + private def format_provider_custom_attributes(attribute) diff --git a/spec/requests/providers_spec.rb b/spec/requests/providers_spec.rb index f34b15757c..72cca3f4d2 100644 --- a/spec/requests/providers_spec.rb +++ b/spec/requests/providers_spec.rb @@ -1116,4 +1116,14 @@ def gen_import_request end end end + + context "OPTIONS /api/providers" do + it "returns options for all providers when no query" do + 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 + end end