diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-20 11:43:02 +0300 |
commit | d9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch) | |
tree | 2341ef426af70ad1e289c38036737e04b0aa5007 /lib/gitlab/request_endpoints.rb | |
parent | d6e514dd13db8947884cd58fe2a9c2a063400a9b (diff) |
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'lib/gitlab/request_endpoints.rb')
-rw-r--r-- | lib/gitlab/request_endpoints.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/gitlab/request_endpoints.rb b/lib/gitlab/request_endpoints.rb new file mode 100644 index 00000000000..157c0f91e65 --- /dev/null +++ b/lib/gitlab/request_endpoints.rb @@ -0,0 +1,41 @@ +# frozen_string_literal: true + +module Gitlab + module RequestEndpoints + class << self + def all_api_endpoints + # This compile does not do anything if the routes were already built + # but if they weren't, the routes will be drawn and available for the rest of + # application. + API::API.compile! + API::API.routes.select { |route| route.app.options[:for] < API::Base } + end + + def all_controller_actions + # This will return tuples of all controller actions defined in the routes + # Only for controllers inheriting ApplicationController + # Excluding controllers from gems (OAuth, Sidekiq) + Rails.application.routes.routes.filter_map do |route| + route_info = route.required_defaults.presence + next unless route_info + next if route_info[:controller].blank? || route_info[:action].blank? + + controller = constantize_controller(route_info[:controller]) + next unless controller&.include?(::Gitlab::EndpointAttributes) + next if controller == ApplicationController + next if controller == Devise::UnlocksController + + [controller, route_info[:action]] + end + end + + private + + def constantize_controller(name) + "#{name.camelize}Controller".constantize + rescue NameError + nil # some controllers, like the omniauth ones are dynamic + end + end + end +end |