Skip to content

Commit d771052

Browse files
authored
Log service plan visibility on create or update service instances (#4230)
* enhance plan visibility check, refactor service_plan_valid?, split up and log more details on failure causes
1 parent fad2da1 commit d771052

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

app/controllers/v3/service_instances_controller.rb

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ def create_user_provided(message)
254254

255255
def create_managed(message, space:)
256256
service_plan = ServicePlan.first(guid: message.service_plan_guid)
257-
unprocessable_service_plan! unless service_plan_valid?(service_plan)
257+
service_plan_does_not_exist! unless service_plan
258+
service_plan_not_visible_to_user!(service_plan) unless visible_to_current_user?(plan: service_plan)
258259
unavailable_service_plan!(service_plan) unless service_plan_active?(service_plan)
259260
service_plan_not_visible_in_space!(service_plan, space) unless service_plan_exists_in_space?(service_plan, space)
260261

@@ -396,11 +397,6 @@ def admin?
396397
permission_queryer.can_write_globally?
397398
end
398399

399-
def service_plan_valid?(service_plan)
400-
service_plan &&
401-
visible_to_current_user?(plan: service_plan)
402-
end
403-
404400
def service_plan_active?(service_plan)
405401
service_plan.active?
406402
end
@@ -413,7 +409,8 @@ def raise_if_invalid_service_plan!(service_instance, message)
413409
return unless message.service_plan_guid
414410

415411
service_plan = ServicePlan.first(guid: message.service_plan_guid)
416-
unprocessable_service_plan! unless service_plan_valid?(service_plan)
412+
service_plan_does_not_exist! unless service_plan
413+
service_plan_not_visible_to_user!(service_plan) unless visible_to_current_user?(plan: service_plan)
417414
unavailable_service_plan!(service_plan) unless service_plan_active?(service_plan)
418415
service_plan_not_visible_in_space!(service_plan, service_instance.space) unless service_plan_exists_in_space?(service_plan, service_instance.space)
419416
invalid_service_plan_relation! unless service_plan.service == service_instance.service
@@ -431,7 +428,15 @@ def unprocessable_space!
431428
unprocessable!('Invalid space. Ensure that the space exists and you have access to it.')
432429
end
433430

434-
def unprocessable_service_plan!
431+
def service_plan_does_not_exist!
432+
logger.info('Service Plan does not exist.')
433+
unprocessable!('Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.')
434+
end
435+
436+
def service_plan_not_visible_to_user!(service_plan)
437+
user = VCAP::CloudController::SecurityContext.current_user
438+
logger.info("Service Plan with guid '#{service_plan.guid}' and id '#{service_plan.id}' is not visible to user with guid '#{user.guid}'.")
439+
435440
unprocessable!('Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.')
436441
end
437442

@@ -458,4 +463,8 @@ def operation_in_progress!
458463
def read_scope
459464
%w[show_permissions].include?(action_name) && roles.cloud_controller_service_permissions_reader? ? true : super
460465
end
466+
467+
def logger
468+
@logger ||= Steno.logger('cc.api')
469+
end
461470
end

0 commit comments

Comments
 (0)