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 event_streams as subcollection of the physical resources #424

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions app/controllers/api/physical_chassis_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Api
class PhysicalChassisController < BaseController
include Subcollections::EventStreams

def refresh_resource(type, id, _data = nil)
raise BadRequestError, "Must specify an id for refreshing a #{type} resource" if id.blank?

Expand Down
2 changes: 2 additions & 0 deletions app/controllers/api/physical_servers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Api
class PhysicalServersController < BaseController
include Subcollections::EventStreams

def blink_loc_led_resource(type, id, _data)
change_resource_state(:blink_loc_led, type, id)
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/api/physical_switches_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Api
class PhysicalSwitchesController < BaseController
include Api::Mixins::Operations
include Subcollections::EventStreams

def refresh_resource(type, id, _data = nil)
perform_action(:refresh_ems, type, id)
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/api/subcollections/event_streams.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module Api
module Subcollections
module EventStreams
def event_streams_query_resource(object)
object.respond_to?(:event_where_clause) ? EventStream.where(object.event_where_clause) : []
end
end
end
end
12 changes: 12 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,7 @@
:description: Event Streams
:options:
- :collection
- :subcollection
:verbs: *gp
:klass: EventStream
:collection_actions:
Expand All @@ -1076,6 +1077,14 @@
:get:
- :name: read
:identifier: event_streams_show
:subcollection_actions:
:get:
- :name: read
:identifier: event_streams_show_list
:subresource_actions:
:get:
- :name: read
:identifier: event_streams_show
:events:
:description: Events
:identifier: event
Expand Down Expand Up @@ -1748,6 +1757,7 @@
:verbs: *gp
:klass: PhysicalChassis
:subcollections:
- :event_streams
:collection_actions:
:get:
- :name: read
Expand Down Expand Up @@ -1794,6 +1804,7 @@
:verbs: *gp
:klass: PhysicalServer
:subcollections:
- :event_streams
:collection_actions:
:get:
- :name: read
Expand Down Expand Up @@ -1884,6 +1895,7 @@
:verbs: *gp
:klass: PhysicalSwitch
:subcollections:
- :event_streams
:collection_actions:
:get:
- :name: read
Expand Down
49 changes: 49 additions & 0 deletions spec/requests/physical_chassis_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,53 @@
end
end
end

describe "Subcollections" do
let(:physical_chassis) { FactoryGirl.create(:physical_chassis) }
let(:event_stream) { FactoryGirl.create(:event_stream, :physical_chassis_id => physical_chassis.id, :event_type => "Some Event") }

context 'Events subcollection' do
context 'GET /api/physical_chassis/:id/event_streams' do
it 'returns the event_streams with an appropriate role' do
api_basic_authorize(collection_action_identifier(:event_streams, :read, :get))

expected = {
'resources' => [
{ 'href' => api_one_physical_chassis_event_stream_url(nil, physical_chassis, event_stream) }
]
}
get(api_one_physical_chassis_event_streams_url(nil, physical_chassis))

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

it 'does not return the event_streams without an appropriate role' do
api_basic_authorize
get(api_one_physical_chassis_event_streams_url(nil, physical_chassis))

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

context 'GET /api/physical_chassis/:id/event_streams/:id' do
it 'returns the event_stream with an appropriate role' do
api_basic_authorize(action_identifier(:event_streams, :read, :resource_actions, :get))
url = api_one_physical_chassis_event_stream_url(nil, physical_chassis, event_stream)
expected = { 'href' => url }
get(url)

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

it 'does not return the event_stream without an appropriate role' do
api_basic_authorize
get(api_one_physical_chassis_event_stream_url(nil, physical_chassis, event_stream))

expect(response).to have_http_status(:forbidden)
end
end
end
end
end
48 changes: 48 additions & 0 deletions spec/requests/physical_servers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -575,4 +575,52 @@
end
end
end
describe "Subcollections" do
let(:physical_server) { FactoryGirl.create(:physical_server) }
let(:event_stream) { FactoryGirl.create(:event_stream, :physical_server_id => physical_server.id, :event_type => "Some Event") }

context 'Events subcollection' do
context 'GET /api/physical_servers/:id/event_streams' do
it 'returns the event_streams with an appropriate role' do
api_basic_authorize(collection_action_identifier(:event_streams, :read, :get))

expected = {
'resources' => [
{ 'href' => api_physical_server_event_stream_url(nil, physical_server, event_stream) }
]
}
get(api_physical_server_event_streams_url(nil, physical_server))

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

it 'does not return the event_streams without an appropriate role' do
api_basic_authorize
get(api_physical_server_event_streams_url(nil, physical_server))

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

context 'GET /api/physical_servers/:id/event_streams/:id' do
it 'returns the event_stream with an appropriate role' do
api_basic_authorize(action_identifier(:event_streams, :read, :resource_actions, :get))
url = api_physical_server_event_stream_url(nil, physical_server, event_stream)
expected = { 'href' => url }
get(url)

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

it 'does not return the event_stream without an appropriate role' do
api_basic_authorize
get(api_physical_server_event_stream_url(nil, physical_server, event_stream))

expect(response).to have_http_status(:forbidden)
end
end
end
end
end
49 changes: 49 additions & 0 deletions spec/requests/physical_switches_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,53 @@
end
end
end

describe "Subcollections" do
let(:physical_switch) { FactoryGirl.create(:physical_switch) }
let(:event_stream) { FactoryGirl.create(:event_stream, :physical_switch_id => physical_switch.id, :event_type => "Some Event") }

context 'Events subcollection' do
context 'GET /api/physical_switches/:id/event_streams' do
it 'returns the event_streams with an appropriate role' do
api_basic_authorize(collection_action_identifier(:event_streams, :read, :get))

expected = {
'resources' => [
{ 'href' => api_physical_switch_event_stream_url(nil, physical_switch, event_stream) }
]
}
get(api_physical_switch_event_streams_url(nil, physical_switch))

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

it 'does not return the event_streams without an appropriate role' do
api_basic_authorize
get(api_physical_switch_event_streams_url(nil, physical_switch))

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

context 'GET /api/physical_switches/:id/event_streams/:id' do
it 'returns the event_stream with an appropriate role' do
api_basic_authorize(action_identifier(:event_streams, :read, :resource_actions, :get))
url = api_physical_switch_event_stream_url(nil, physical_switch, event_stream)
expected = { 'href' => url }
get(url)

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

it 'does not return the event_stream without an appropriate role' do
api_basic_authorize
get(api_physical_switch_event_stream_url(nil, physical_switch, event_stream))

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