-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from vladislavbakan/feature_security_cache_cont…
…enttype Features: security, cache, default content type
- Loading branch information
Showing
6 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,48 @@ | ||
module Swaggard | ||
class SwaggerController < ApplicationController | ||
|
||
before_filter :authorize | ||
|
||
def index | ||
respond_to do |format| | ||
format.html do | ||
@authentication_type = Swaggard.configuration.authentication_type | ||
@authentication_key = Swaggard.configuration.authentication_key | ||
@authentication_value = Swaggard.configuration.authentication_value | ||
|
||
render :index | ||
render :index, layout: false | ||
end | ||
|
||
format.json do | ||
doc = Swaggard.get_doc(request.host_with_port) | ||
doc = get_swaggard_doc | ||
|
||
render json: doc | ||
end | ||
end | ||
end | ||
|
||
protected | ||
|
||
def authorize | ||
unless Swaggard.configuration.access_username.blank? | ||
authenticate_or_request_with_http_basic do |username, password| | ||
username == Swaggard.configuration.access_username && password == Swaggard.configuration.access_password | ||
end | ||
end | ||
end | ||
|
||
def get_swaggard_doc | ||
if Swaggard.configuration.use_cache | ||
doc = Rails.cache.fetch('swagger_doc') | ||
if doc.blank? | ||
doc = Swaggard.get_doc(request.host_with_port) | ||
Rails.cache.write('swagger_doc', doc) | ||
end | ||
doc | ||
else | ||
Swaggard.get_doc(request.host_with_port) | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace :swaggard do | ||
|
||
desc 'Clear swaggard cache' | ||
task :clear_cache => :environment do | ||
Rails.cache.delete('swagger_doc') | ||
puts 'Swaggard cache has been cleared' | ||
end | ||
|
||
end |