fix(rswag-ui): Define BasicAuth in Rswag::Ui module

This commit is contained in:
Kabiru Mwenja 2020-01-06 10:55:43 +03:00
parent 6e706c04d7
commit a43e6f6546
No known key found for this signature in database
GPG Key ID: 6D6C5615C3E00288

View File

@ -1,25 +1,34 @@
# frozen_string_literal: true
require 'rack/auth/basic'
class BasicAuth < ::Rack::Auth::Basic
def call(env)
return @app.call(env) unless env_matching_path
module Rswag
module Ui
# Extend Rack HTTP Basic Authentication, as per RFC 2617.
# @api private
#
class BasicAuth < ::Rack::Auth::Basic
def call(env)
return @app.call(env) unless env_matching_path
super(env)
end
super(env)
end
private
private
def env_matching_path
swagger_endpoints = Rswag::Ui.config.swagger_endpoints[:urls]
swagger_endpoints.find do |endpoint|
base_path = base_path(endpoint[:url])
env_base_path = base_path(env['PATH_INFO'])
def env_matching_path
Rswag::Ui.config.swagger_endpoints[:urls].find do |endpoint|
base_path(endpoint[:url]) == env_base_path
end
end
base_path == env_base_path
def env_base_path
base_path(env['PATH_INFO'])
end
def base_path(url)
url.downcase.split('/')[1]
end
end
end
def base_path(url)
url.downcase.split('/')[1]
end
end