Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add security group subcollection to providers, cloud tenants, and vms #81

Merged
merged 8 commits into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/api/cloud_tenants_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Api
class CloudTenantsController < BaseController
include Subcollections::SecurityGroups
end
end
1 change: 1 addition & 0 deletions app/controllers/api/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class ProvidersController < BaseController
include Subcollections::CloudTenants
include Subcollections::CustomAttributes
include Subcollections::LoadBalancers
include Subcollections::SecurityGroups
include Subcollections::Vms

def create_resource(type, _id, data = {})
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/api/subcollections/security_groups.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module Subcollections
module SecurityGroups
def security_groups_query_resource(object)
object.respond_to?(:security_groups) ? object.security_groups : []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test that executes the case when the object does not respond to :security_groups?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done - thanks!

end
end
end
end
1 change: 1 addition & 0 deletions app/controllers/api/vms_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class VmsController < BaseController
include Subcollections::PolicyProfiles
include Subcollections::Accounts
include Subcollections::CustomAttributes
include Subcollections::SecurityGroups
include Subcollections::Software
include Subcollections::Snapshots
include Subcollections::MetricRollups
Expand Down
4 changes: 4 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@
- :subcollection
:verbs: *gp
:klass: CloudTenant
:subcollections:
- :security_groups
:collection_actions:
:get:
- :name: read
Expand Down Expand Up @@ -1607,6 +1609,7 @@
- :cloud_tenants
- :custom_attributes
- :load_balancers
- :security_groups
- :vms
:collection_actions:
:get:
Expand Down Expand Up @@ -2650,6 +2653,7 @@
- :policy_profiles
- :accounts
- :custom_attributes
- :security_groups
- :software
- :snapshots
- :metric_rollups
Expand Down
47 changes: 47 additions & 0 deletions spec/requests/providers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,53 @@ def gen_import_request
end
end

context 'security groups subcollection' do
before do
@provider = FactoryGirl.create(:ems_openstack)
@security_group = FactoryGirl.create(:security_group, :ext_management_system => @provider)
end

it 'queries all security groups' do
api_basic_authorize subcollection_action_identifier(:providers, :security_groups, :read, :get)

get(api_provider_security_groups_url(nil, @provider))

expected = {
'resources' => [
{ 'href' => api_provider_security_group_url(nil, @provider, @security_group) }
]

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

it "will not show a provider's security groups without the appropriate role" do
api_basic_authorize

get(api_provider_security_groups_url(nil, @provider))

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

it 'queries a single security group' do
api_basic_authorize action_identifier(:security_groups, :read, :subresource_actions, :get)

get(api_provider_security_group_url(nil, @provider, @security_group))

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

it "will not show a provider's security group without the appropriate role" do
api_basic_authorize

get(api_provider_security_group_url(nil, @provider, @security_group))

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

describe 'edit custom_attributes on providers' do
context 'provider_class=provider' do
let(:generic_provider) { FactoryGirl.create(:provider) }
Expand Down