mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
chore(rswag-ui): Organise basic auth files
This commit is contained in:
parent
529cfae73e
commit
19e985a828
25
rswag-ui/lib/rswag/ui/basic_auth.rb
Normal file
25
rswag-ui/lib/rswag/ui/basic_auth.rb
Normal 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
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user