From 1176c513c7ff2663ce20a05efe900e85533711a4 Mon Sep 17 00:00:00 2001 From: Seth Boyles Date: Fri, 13 Dec 2024 14:41:04 -0800 Subject: [PATCH] Minor refactor of v2 endpoints --- .../managed_service_instances_controller.rb | 12 ----- .../services/service_instances_controller.rb | 6 +++ ...naged_service_instances_controller_spec.rb | 26 ----------- .../service_instances_controller_spec.rb | 45 +++++++++++++++++++ 4 files changed, 51 insertions(+), 38 deletions(-) delete mode 100644 app/controllers/services/managed_service_instances_controller.rb delete mode 100644 spec/unit/controllers/services/managed_service_instances_controller_spec.rb diff --git a/app/controllers/services/managed_service_instances_controller.rb b/app/controllers/services/managed_service_instances_controller.rb deleted file mode 100644 index 02f95d1faa8..00000000000 --- a/app/controllers/services/managed_service_instances_controller.rb +++ /dev/null @@ -1,12 +0,0 @@ -module VCAP::CloudController - class ManagedServiceInstancesController < RestController::ModelController - allow_unauthenticated_access - - deprecated_endpoint '/v2/managed_service_instance' - - get '/v2/managed_service_instances/:guid', :read - def read(guid) - redirect "v2/service_instances/#{guid}" - end - end -end diff --git a/app/controllers/services/service_instances_controller.rb b/app/controllers/services/service_instances_controller.rb index e77b9346c58..283bf771543 100644 --- a/app/controllers/services/service_instances_controller.rb +++ b/app/controllers/services/service_instances_controller.rb @@ -10,6 +10,7 @@ require 'presenters/v2/service_instance_shared_from_presenter' module VCAP::CloudController + # rubocop:disable Metrics/ClassLength class ServiceInstancesController < RestController::ModelController include VCAP::CloudController::LockCheck @@ -142,6 +143,10 @@ def update(guid) raise CloudController::Errors::ApiError.new_from_details('AsyncServiceBindingOperationInProgress', e.service_binding.app.name, e.service_binding.service_instance.name) end + deprecated_endpoint '/v2/managed_service_instances' + get '/v2/managed_service_instances', :enumerate + get '/v2/managed_service_instances/:guid', :read + def read(guid) service_instance = find_guid_and_validate_access(:read, guid, ServiceInstance) @@ -597,4 +602,5 @@ def projected_service_instance(service_instance) service_instance.clone.set(request_attrs.select { |k, _v| ServiceInstanceUpdate::KEYS_TO_UPDATE_CC.include? k }) end end + # rubocop:enable Metrics/ClassLength end diff --git a/spec/unit/controllers/services/managed_service_instances_controller_spec.rb b/spec/unit/controllers/services/managed_service_instances_controller_spec.rb deleted file mode 100644 index df13ebf6437..00000000000 --- a/spec/unit/controllers/services/managed_service_instances_controller_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'spec_helper' - -## NOTICE: Prefer request specs over controller specs as per ADR #0003 ## - -module VCAP::CloudController - RSpec.describe ManagedServiceInstancesController, :services do - describe 'GET', '/v2/managed_service_instances' do - it 'is deprecated' do - get '/v2/managed_service_instances' - expect(last_response).to be_a_deprecated_response - end - end - - describe 'GET', '/v2/managed_service_instances/:guid' do - it 'is deprecated' do - get '/v2/managed_service_instances/abcd' - expect(last_response).to be_a_deprecated_response - end - - it 'redirects to /v2/service_instances/:guid' do - get '/v2/managed_service_instances/abcd' - expect(last_response).to have_status_code(302) - end - end - end -end diff --git a/spec/unit/controllers/services/service_instances_controller_spec.rb b/spec/unit/controllers/services/service_instances_controller_spec.rb index d66f8a896bd..80a75f21d79 100644 --- a/spec/unit/controllers/services/service_instances_controller_spec.rb +++ b/spec/unit/controllers/services/service_instances_controller_spec.rb @@ -1123,6 +1123,28 @@ def stub_delete_and_return(status, body) end end + describe 'GET', '/v2/managed_service_instances' do + let(:service_instance) { ManagedServiceInstance.make(gateway_name: Sham.name) } + let(:space) { service_instance.space } + let(:developer) { make_developer_for_space(space) } + + it 'is deprecated' do + set_current_user(developer) + get '/v2/managed_service_instances' + expect(last_response).to be_a_deprecated_response + end + + it 'behaves the same as /v2/service_instances/' do + set_current_user(developer) + get '/v2/managed_service_instances' + deprecated_response = last_response + expect(deprecated_response).to have_status_code(200) + get '/v2/service_instances' + new_response = last_response + expect(new_response.body).to eq(deprecated_response.body) + end + end + describe 'GET /v2/service_instances' do context 'dashboard_url' do let(:service_instance) { ManagedServiceInstance.make(gateway_name: Sham.name) } @@ -1535,6 +1557,29 @@ def stub_delete_and_return(status, body) end end + describe 'GET', '/v2/managed_service_instances/:guid' do + let(:space) { Space.make } + let(:developer) { make_developer_for_space(space) } + let(:service_instance) { ManagedServiceInstance.make(space:) } + let(:service_plan) { ServicePlan.make(active: false) } + + it 'is deprecated' do + set_current_user(developer) + get "v2/managed_service_instances/#{service_instance.guid}" + expect(last_response).to be_a_deprecated_response + end + + it 'behaves the same as /v2/service_instances/:guid' do + set_current_user(developer) + get "v2/managed_service_instances/#{service_instance.guid}" + deprecated_response = last_response + expect(deprecated_response).to have_status_code(200) + get "v2/service_instances/#{service_instance.guid}" + new_response = last_response + expect(new_response.body).to eq(deprecated_response.body) + end + end + describe 'GET /v2/service_instances/:service_instance_guid' do let(:space) { service_instance.space } let(:developer) { make_developer_for_space(space) }