Skip to content

Commit

Permalink
Add cloud subnet REST API
Browse files Browse the repository at this point in the history
  • Loading branch information
gildub committed May 31, 2017
1 parent d2a5576 commit d63393e
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/controllers/api/cloud_subnets_controller.rb
@@ -0,0 +1,4 @@
module Api
class CloudSubnetsController < BaseController
end
end
1 change: 1 addition & 0 deletions app/controllers/api/providers_controller.rb
Expand Up @@ -14,6 +14,7 @@ class ProvidersController < BaseController
include Subcollections::PolicyProfiles
include Subcollections::Tags
include Subcollections::CloudNetworks
include Subcollections::CloudSubnets
include Subcollections::CloudTenants
include Subcollections::CustomAttributes
include Subcollections::LoadBalancers
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/api/subcollections/cloud_subnets.rb
@@ -0,0 +1,9 @@
module Api
module Subcollections
module CloudSubnets
def cloud_subnets_query_resource(object)
object.cloud_subnets
end
end
end
end
28 changes: 28 additions & 0 deletions config/api.yml
Expand Up @@ -436,6 +436,33 @@
:get:
- :name: read
:identifier: miq_cloud_networks_view
:cloud_subnets:
:description: Cloud Subnets
:identifier: cloud_subnet
:options:
- :collection
- :subcollection
:verbs: *gp
:klass: CloudSubnet
:collection_actions:
:get:
- :name: read
:identifier: cloud_subnet_show_list
:post:
- :name: query
:identifier: cloud_subnet_show_list
:resource_actions:
:get:
- :name: read
:identifier: cloud_subnet_show
:subcollection_actions:
:get:
- :name: read
:identifier: cloud_tenant_show_list
:subresource_actions:
:get:
- :name: read
:identifier: cloud_tenant_show
:cloud_tenants:
:description: Cloud Tenants
:identifier: cloud_tenant
Expand Down Expand Up @@ -1263,6 +1290,7 @@
- :policies
- :policy_profiles
- :cloud_networks
- :cloud_subnets
- :cloud_tenants
- :custom_attributes
- :load_balancers
Expand Down
49 changes: 49 additions & 0 deletions spec/requests/api/cloud_subnets_spec.rb
@@ -0,0 +1,49 @@
RSpec.describe 'CloudSubnets API' do
describe 'GET /api/cloud_subnets' do
it 'lists all cloud subnets with an appropriate role' do
cloud_subnet = FactoryGirl.create(:cloud_subnet)
api_basic_authorize collection_action_identifier(:cloud_subnets, :read, :get)
run_get(cloud_subnets_url)

expected = {
'count' => 1,
'subcount' => 1,
'name' => 'cloud_subnets',
'resources' => [
hash_including('href' => a_string_matching(cloud_subnets_url(cloud_subnet.id)))
]
}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it 'forbids access to cloud subnets without an appropriate role' do
api_basic_authorize

run_get(cloud_subnets_url)

expect(response).to have_http_status(:forbidden)
end
end

describe 'GET /api/cloud_subnets/:id' do
it 'will show a cloud subnet with an appropriate role' do
cloud_subnet = FactoryGirl.create(:cloud_subnet)
api_basic_authorize action_identifier(:cloud_subnets, :read, :resource_actions, :get)

run_get(cloud_subnets_url(cloud_subnet.id))

expect(response.parsed_body).to include('href' => a_string_matching(cloud_subnets_url(cloud_subnet.id)))
expect(response).to have_http_status(:ok)
end

it 'forbids access to a cloud tenant without an appropriate role' do
cloud_subnet = FactoryGirl.create(:cloud_subnet)
api_basic_authorize

run_get(cloud_subnets_url(cloud_subnet.id))

expect(response).to have_http_status(:forbidden)
end
end
end
10 changes: 10 additions & 0 deletions spec/requests/api/collections_spec.rb
Expand Up @@ -288,6 +288,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_query(:cloud_networks, cloud_networks_url, CloudNetwork)
end

it 'queries CloudSubnets' do
FactoryGirl.create(:cloud_subnet)
test_collection_query(:cloud_subnets, cloud_subnets_url, CloudSubnet)
end

it 'queries CloudTenants' do
FactoryGirl.create(:cloud_tenant)
test_collection_query(:cloud_tenants, cloud_tenants_url, CloudTenant)
Expand Down Expand Up @@ -558,6 +563,11 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil)
test_collection_bulk_query(:load_balancers, load_balancers_url, LoadBalancer)
end

it "bulk query CloudSubnets" do
FactoryGirl.create(:cloud_subnet)
test_collection_bulk_query(:cloud_subnets, cloud_subnets_url, CloudSubnet)
end

it 'bulk query CloudTenants' do
FactoryGirl.create(:cloud_tenant)
test_collection_bulk_query(:cloud_tenants, cloud_tenants_url, CloudTenant)
Expand Down
47 changes: 47 additions & 0 deletions spec/requests/api/providers_spec.rb
Expand Up @@ -952,6 +952,53 @@ def gen_import_request
end
end

context 'cloud subnets subcollection' do
before do
@provider = FactoryGirl.create(:ems_openstack).network_manager
@cloud_subnet = FactoryGirl.create(:cloud_subnet, :ext_management_system => @provider)
end

it 'queries all cloud subnets' do
api_basic_authorize subcollection_action_identifier(:providers, :cloud_subnets, :read, :get)

run_get("#{providers_url(@provider.id)}/cloud_subnets")

expected = {
'resources' => [
{ 'href' => a_string_matching("#{providers_url(@provider.id)}/cloud_subnets/#{@cloud_subnet.id}") }
]

}
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end

it "will not show a provider's cloud subnets without the appropriate role" do
api_basic_authorize

run_get("#{providers_url(@provider.id)}/cloud_subnets")

expect(response).to have_http_status(:forbidden)
end

it 'queries a single cloud subnet' do
api_basic_authorize action_identifier(:cloud_subnets, :read, :subresource_actions, :get)

run_get("#{providers_url(@provider.id)}/cloud_subnets/#{@cloud_subnet.id}")

expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include('id' => @cloud_subnet.id)
end

it "will not show a provider's cloud subnet without the appropriate role" do
api_basic_authorize

run_get("#{providers_url(@provider.id)}/cloud_subnets/#{@cloud_subnet.id}")

expect(response).to have_http_status(:forbidden)
end
end

context 'cloud tenants subcollection' do
before do
@provider = FactoryGirl.create(:ems_openstack)
Expand Down

0 comments on commit d63393e

Please sign in to comment.