From 1e6f2c972cc7f8423ac97b1ec6c747b1e33d0789 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Thu, 9 Mar 2017 17:04:49 -0800 Subject: [PATCH 1/5] Api for Cloud Volumes collection --- .../api/cloud_volumes_controller.rb | 4 ++++ config/api.yml | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 app/controllers/api/cloud_volumes_controller.rb diff --git a/app/controllers/api/cloud_volumes_controller.rb b/app/controllers/api/cloud_volumes_controller.rb new file mode 100644 index 00000000000..c434b97b25e --- /dev/null +++ b/app/controllers/api/cloud_volumes_controller.rb @@ -0,0 +1,4 @@ +module Api + class CloudVolumesController < BaseController + end +end diff --git a/config/api.yml b/config/api.yml index 925d2aece4a..5a68745203e 100644 --- a/config/api.yml +++ b/config/api.yml @@ -473,6 +473,29 @@ :get: - :name: read :identifier: miq_cloud_networks_view + :cloud_volumes: + :description: Cloud Volumes + :identifier: cloud_volume + :options: + - :collection + - :subcollection + :verbs: *gp + :klass: CloudVolume + :collection_actions: + :get: + - :name: read + :identifier: cloud_volume_show_list + :post: + - :name: query + :identifier: cloud_volume_show_list + :subcollection_actions: + :get: + - :name: read + :identifier: cloud_volume_show + :subresource_actions: + :get: + - :name: read + :identifier: cloud_volume_show :clusters: :description: Clusters :identifier: ems_cluster From f84e8143f3ed3370afd0942de3400c3b8e77fbda Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Thu, 9 Mar 2017 17:12:23 -0800 Subject: [PATCH 2/5] spec to query cloud_volumes --- spec/requests/api/collections_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/requests/api/collections_spec.rb b/spec/requests/api/collections_spec.rb index bcdd686516e..7a9837037a5 100644 --- a/spec/requests/api/collections_spec.rb +++ b/spec/requests/api/collections_spec.rb @@ -84,6 +84,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil) test_collection_query(:clusters, clusters_url, EmsCluster) end + it "query CloudVolumes" do + FactoryGirl.create(:cloud_volume) + test_collection_query(:cloud_volumes, cloud_volumes_url, CloudVolume) + end + it "query Conditions" do FactoryGirl.create(:condition) test_collection_query(:conditions, conditions_url, Condition) From 050bc40acc21a6efeb043eb360de70bb29a23d08 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Tue, 14 Mar 2017 11:44:37 -0700 Subject: [PATCH 3/5] PR feedback -- Remove :subcollections and :subresource_actions --- config/api.yml | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/config/api.yml b/config/api.yml index 5a68745203e..281ee60f0ae 100644 --- a/config/api.yml +++ b/config/api.yml @@ -478,7 +478,6 @@ :identifier: cloud_volume :options: - :collection - - :subcollection :verbs: *gp :klass: CloudVolume :collection_actions: @@ -488,14 +487,10 @@ :post: - :name: query :identifier: cloud_volume_show_list - :subcollection_actions: - :get: - - :name: read - :identifier: cloud_volume_show - :subresource_actions: + :resource_actions: :get: - :name: read - :identifier: cloud_volume_show + :identifier: cloud_volume :clusters: :description: Clusters :identifier: ems_cluster From e7fd6a600873360b64f70c38c314f35d38544082 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Tue, 14 Mar 2017 11:47:30 -0700 Subject: [PATCH 4/5] spec for cloud volumes --- spec/requests/api/cloud_volumes_spec.rb | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spec/requests/api/cloud_volumes_spec.rb diff --git a/spec/requests/api/cloud_volumes_spec.rb b/spec/requests/api/cloud_volumes_spec.rb new file mode 100644 index 00000000000..13415461d26 --- /dev/null +++ b/spec/requests/api/cloud_volumes_spec.rb @@ -0,0 +1,43 @@ +# +# REST API Request Tests - Cloud Volumes +# +# Regions primary collections: +# /api/cloud_volumes +# +# Tests for: +# GET /api/cloud_volumes/:id +# + +describe "Cloud Volumes API" do + it "forbids access to cloud volumes without an appropriate role" do + api_basic_authorize + + run_get(cloud_volumes_url) + + expect(response).to have_http_status(:forbidden) + end + + it "forbids access to a cloud volume resource without an appropriate role" do + api_basic_authorize + + cloud_volume = FactoryGirl.create(:cloud_volume) + + run_get(cloud_volumes_url(cloud_volume.id)) + + expect(response).to have_http_status(:forbidden) + end + + it "allows GETs of a cloud volume" do + api_basic_authorize action_identifier(:cloud_volumes, :read, :resource_actions, :get) + + cloud_volume = FactoryGirl.create(:cloud_volume) + + run_get(cloud_volumes_url(cloud_volume.id)) + + expect(response).to have_http_status(:ok) + expect(response.parsed_body).to include( + "href" => a_string_matching(cloud_volumes_url(cloud_volume.id)), + "id" => cloud_volume.id + ) + end +end From 0bbcd8ac7964c0b73c6b43a37ae38ccf9c0763e7 Mon Sep 17 00:00:00 2001 From: Aparna Karve Date: Wed, 15 Mar 2017 13:11:23 -0700 Subject: [PATCH 5/5] bulk query spec for cloud volumes --- spec/requests/api/collections_spec.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/requests/api/collections_spec.rb b/spec/requests/api/collections_spec.rb index 7a9837037a5..052987c7413 100644 --- a/spec/requests/api/collections_spec.rb +++ b/spec/requests/api/collections_spec.rb @@ -575,5 +575,10 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil) FactoryGirl.create(:load_balancer) test_collection_bulk_query(:load_balancers, load_balancers_url, LoadBalancer) end + + it 'bulk query CloudVolumes' do + FactoryGirl.create(:cloud_volume) + test_collection_bulk_query(:cloud_volumes, cloud_volumes_url, CloudVolume) + end end end