diff --git a/app/fetchers/service_offering_list_fetcher.rb b/app/fetchers/service_offering_list_fetcher.rb index a785ab2d2a3..8342ef8d3b0 100644 --- a/app/fetchers/service_offering_list_fetcher.rb +++ b/app/fetchers/service_offering_list_fetcher.rb @@ -15,6 +15,8 @@ def fetch(message, omniscient: false, readable_orgs_query: nil, readable_spaces_ private def filter(message, dataset, klass) + dataset = dataset.where(Sequel[:services][:unique_id] =~ message.broker_catalog_ids) if message.requested?(:broker_catalog_ids) + dataset = dataset.where(Sequel[:services][:label] =~ message.names) if message.requested?(:names) dataset = dataset.where { Sequel[:services][:active] =~ message.available? } if message.requested?(:available) diff --git a/app/messages/service_offerings_list_message.rb b/app/messages/service_offerings_list_message.rb index 4cde3d9a9e9..2b36e53065a 100644 --- a/app/messages/service_offerings_list_message.rb +++ b/app/messages/service_offerings_list_message.rb @@ -4,6 +4,7 @@ module VCAP::CloudController class ServiceOfferingsListMessage < MetadataListMessage @array_keys = %i[ + broker_catalog_ids service_broker_guids service_broker_names names diff --git a/docs/v3/source/includes/resources/service_offerings/_list.md.erb b/docs/v3/source/includes/resources/service_offerings/_list.md.erb index 5558451d382..049b7c1263f 100644 --- a/docs/v3/source/includes/resources/service_offerings/_list.md.erb +++ b/docs/v3/source/includes/resources/service_offerings/_list.md.erb @@ -32,6 +32,7 @@ Name | Type | Description ---- | ---- | ------------ **names** | _list of strings_ | Comma-delimited list of names to filter by **available** | _boolean_ | Filter by the `available` property; valid values are `true` or `false` +**broker_catalog_ids** | _list of strings_ | Comma-delimited list of IDs provided by the service broker for the service offering to filter by **service_broker_guids** | _list of strings_ | Comma-delimited list of service broker GUIDs to filter by **service_broker_names** | _list of strings_ | Comma-delimited list of service broker names to filter by **space_guids** | _list of strings_ | Comma-delimited list of space GUIDs to filter by diff --git a/spec/request/service_offerings_spec.rb b/spec/request/service_offerings_spec.rb index a61d0c77fa2..4076abeba89 100644 --- a/spec/request/service_offerings_spec.rb +++ b/spec/request/service_offerings_spec.rb @@ -210,6 +210,7 @@ let(:params) do { available: true, + broker_catalog_ids: %w[catalog-id-1 catalog-id-2], service_broker_guids: %w[foo bar], service_broker_names: %w[baz qux], names: %w[quux quuz], @@ -373,6 +374,20 @@ end end + describe 'broker_catalog_ids' do + let!(:service_offering_1) { VCAP::CloudController::ServicePlan.make(public: true).service } + let!(:service_offering_2) { VCAP::CloudController::ServicePlan.make(public: true).service } + let!(:service_offering_3) { VCAP::CloudController::ServicePlan.make(public: true).service } + let!(:service_offering_4) { VCAP::CloudController::ServicePlan.make(public: true).service } + + it 'filters by broker catalog id' do + expect_filtered_service_offerings( + "broker_catalog_ids=#{service_offering_1.unique_id},#{service_offering_3.unique_id}", + [service_offering_1, service_offering_3] + ) + end + end + describe 'guids' do let!(:service_broker_1) { VCAP::CloudController::ServiceBroker.make(space:) } let!(:service_offering_1) { VCAP::CloudController::Service.make(service_broker: service_broker_1) } diff --git a/spec/unit/fetchers/service_offering_list_fetcher_spec.rb b/spec/unit/fetchers/service_offering_list_fetcher_spec.rb index 84ded4ab18f..6870940f3f7 100644 --- a/spec/unit/fetchers/service_offering_list_fetcher_spec.rb +++ b/spec/unit/fetchers/service_offering_list_fetcher_spec.rb @@ -397,6 +397,24 @@ module VCAP::CloudController end end + describe 'the `broker_catalog_ids` filter' do + let!(:service_offering_1) { VCAP::CloudController::ServicePlan.make(public: true).service } + let!(:service_offering_2) { VCAP::CloudController::ServicePlan.make(public: true).service } + let!(:service_offering_3) { VCAP::CloudController::ServicePlan.make(public: true).service } + let!(:service_offering_4) { VCAP::CloudController::ServicePlan.make(public: true).service } + + let(:message) do + ServiceOfferingsListMessage.from_params({ broker_catalog_ids: [service_offering_1.unique_id, service_offering_4.unique_id].join(',') }.with_indifferent_access) + end + + it 'filters the service offerings with matching broker catalog IDs' do + expect(service_offerings).to contain_exactly( + service_offering_1, + service_offering_4 + ) + end + end + describe 'the `service_broker_guids` filter' do let!(:service_broker) { VCAP::CloudController::ServiceBroker.make } let!(:service_offering_1) do diff --git a/spec/unit/messages/service_offerings_list_message_spec.rb b/spec/unit/messages/service_offerings_list_message_spec.rb index 177d83cb118..17bfc0ec7f9 100644 --- a/spec/unit/messages/service_offerings_list_message_spec.rb +++ b/spec/unit/messages/service_offerings_list_message_spec.rb @@ -7,6 +7,7 @@ module VCAP::CloudController let(:params) do { 'available' => 'true', + 'broker_catalog_ids' => 'broker_catalog_id_1,broker_catalog_id_2', 'service_broker_guids' => 'one,two', 'service_broker_names' => 'zhou,qin', 'names' => 'service_offering1,other_2', @@ -23,6 +24,7 @@ module VCAP::CloudController expect(message).to be_valid expect(message).to be_a(described_class) expect(message.available).to eq('true') + expect(message.broker_catalog_ids).to eq(%w[broker_catalog_id_1 broker_catalog_id_2]) expect(message.service_broker_guids).to eq(%w[one two]) expect(message.service_broker_names).to eq(%w[zhou qin]) expect(message.names).to eq(%w[service_offering1 other_2]) @@ -34,6 +36,7 @@ module VCAP::CloudController message = described_class.from_params(params) expect(message).to be_requested(:available) + expect(message).to be_requested(:broker_catalog_ids) expect(message).to be_requested(:names) expect(message).to be_requested(:service_broker_guids) expect(message).to be_requested(:service_broker_names)