Skip to content

Commit

Permalink
Moved disallowed/whitelisted gems/projects to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
lsegal committed Oct 22, 2012
1 parent 42168d0 commit 22d8c8f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
20 changes: 10 additions & 10 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ class NilClass; def blank?; true end end
class DocServer < Sinatra::Base
include YARD::Server

DISALLOWED_GEMS = %w(netsuite_client)
DISALLOWED_PROJECTS = %w(kraeftemessen/spider-network)
WHITELISTED_GEMS = %w(yard)
WHITELISTED_PROJECTS = %w(lsegal/yard)

def self.adapter_options
caching = %w(staging production).include?(ENV['RACK_ENV'])
{
Expand All @@ -39,6 +34,11 @@ def self.load_configuration
set :name, 'RubyDoc.info'
set :url, 'http://rubydoc.info'

set :disallowed_projects, []
set :disallowed_gems, []
set :whitelisted_projects, []
set :whitelisted_gems, []

return unless File.file?(CONFIG_FILE)

puts ">> Loading #{CONFIG_FILE}"
Expand Down Expand Up @@ -255,11 +255,11 @@ def shorten_commit_link(commit)
url = url.sub(%r{^http://}, 'git://')
if url =~ %r{github\.com/([^/]+)/([^/]+)}
username, project = $1, $2
if WHITELISTED_PROJECTS.include?("#{username}/#{project}")
if settings.whitelisted_projects.include?("#{username}/#{project}")
puts "Dropping safe mode for #{username}/#{project}"
YARD::Config.options[:safe_mode] = false
end
if DISALLOWED_PROJECTS.include?("#{username}/#{project}")
if settings.disallowed_projects.include?("#{username}/#{project}")
return status(503) && "Cannot parse this project"
end
end
Expand Down Expand Up @@ -316,7 +316,7 @@ def shorten_commit_link(commit)

get %r{^/(?:(?:search|list)/)?github/([^/]+)/([^/]+)} do |username, project|
@username, @project = username, project
if WHITELISTED_PROJECTS.include?("#{username}/#{project}")
if settings.whitelisted_projects.include?("#{username}/#{project}")
puts "Dropping safe mode for #{username}/#{project}"
YARD::Config.options[:safe_mode] = false
end
Expand All @@ -326,8 +326,8 @@ def shorten_commit_link(commit)
end

get %r{^/(?:(?:search|list)/)?gems/([^/]+)} do |gemname|
return status(503) && "Cannot parse this gem" if DISALLOWED_GEMS.include?(gemname)
if WHITELISTED_GEMS.include?(gemname)
return status(503) && "Cannot parse this gem" if settings.disallowed_gems.include?(gemname)
if settings.whitelisted_gems.include?(gemname)
puts "Dropping safe mode for #{gemname}"
YARD::Config.options[:safe_mode] = false
end
Expand Down
14 changes: 14 additions & 0 deletions config/config.yaml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,17 @@
# yard:
# 0.6.4: /path/to/yard/0.6.4
# 0.6.0: /path/to/yard/0.6.0

# Projects / gems that are whitelisted for template and non-plugin code execution:
# whitelisted_projects:
# - lsegal/yard
#
# whitelisted_gems:
# - yard

# Projects / gems that are blacklisted from the site
# disallowed_projects:
# - user/projectname
#
# disallowed_gems:
# - gemname

0 comments on commit 22d8c8f

Please sign in to comment.