chore(rswag-ui): Organise basic auth files

This commit is contained in:
Kabiru Mwenja 2020-01-06 09:50:30 +03:00
parent 529cfae73e
commit 19e985a828
No known key found for this signature in database
GPG Key ID: 6D6C5615C3E00288
2 changed files with 26 additions and 24 deletions

View File

@ -0,0 +1,25 @@
require 'rack/auth/basic'
class BasicAuth < ::Rack::Auth::Basic
def call(env)
return @app.call(env) unless env_matching_path
super(env)
end
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'])
base_path == env_base_path
end
end
def base_path(url)
url.downcase.split('/')[1]
end
end

View File

@ -1,28 +1,5 @@
require 'rswag/ui/middleware'
class UiBasicAuth < ::Rack::Auth::Basic
def call(env)
return @app.call(env) unless env_matching_path
super(env)
end
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'])
base_path == env_base_path
end
end
def base_path(url)
url.downcase.split('/')[1]
end
end
require 'rswag/ui/basic_auth'
module Rswag
module Ui