From c256d49d755217b81226fa62bcf64edd29ae0db7 Mon Sep 17 00:00:00 2001
From: Erez Freiberger <efreiber@redhat.com>
Date: Sun, 6 Aug 2017 11:00:44 +0300
Subject: [PATCH] use OPTIONS /api/providers

---
 app/controllers/api/providers_controller.rb |  5 +++++
 spec/requests/api/providers_spec.rb         | 10 ++++++++++
 2 files changed, 15 insertions(+)

diff --git a/app/controllers/api/providers_controller.rb b/app/controllers/api/providers_controller.rb
index 9f182a0a3b..d4d383d81d 100644
--- a/app/controllers/api/providers_controller.rb
+++ b/app/controllers/api/providers_controller.rb
@@ -85,6 +85,11 @@ def import_vm_resource(type, id = nil, data = {})
       end
     end
 
+    def options
+      ems_class = ExtManagementSystem.descendants.select { |ems| ems.ems_type == params[:ems_type] }.first
+      render_options(:providers, ems_class.respond_to?(:provider_settings) ? ems_class.provider_settings : {})
+    end
+
     private
 
     def format_provider_custom_attributes(attribute)
diff --git a/spec/requests/api/providers_spec.rb b/spec/requests/api/providers_spec.rb
index f34b15757c..80017705ec 100644
--- a/spec/requests/api/providers_spec.rb
+++ b/spec/requests/api/providers_spec.rb
@@ -1116,4 +1116,14 @@ def gen_import_request
       end
     end
   end
+
+  context "#options" do
+    it "returns options for 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(response.parsed_body.to_json).to eq(ems_type.provider_settings.to_json)
+      end
+    end
+  end
 end