update rakefile to allow heroku deployment, update create.rb with api builds rate limit

This commit is contained in:
carlad 2016-03-31 16:54:12 +02:00
parent d6c0621d71
commit f51cf1a1d1
4 changed files with 11 additions and 11 deletions

View File

@ -48,7 +48,7 @@ GIT
GIT GIT
remote: git://github.com/travis-ci/travis-core.git remote: git://github.com/travis-ci/travis-core.git
revision: f7b3a76b3f39c28bb5cf7b9dc24acec13908a11a revision: 57634c3103dec6472bf732de5f051702224dc345
specs: specs:
travis-core (0.0.1) travis-core (0.0.1)
actionmailer (~> 3.2.19) actionmailer (~> 3.2.19)
@ -331,7 +331,7 @@ GEM
treetop (1.4.15) treetop (1.4.15)
polyglot polyglot
polyglot (>= 0.3.1) polyglot (>= 0.3.1)
tzinfo (0.3.47) tzinfo (0.3.48)
unicorn (4.8.3) unicorn (4.8.3)
kgio (~> 2.6) kgio (~> 2.6)
rack rack
@ -388,3 +388,6 @@ DEPENDENCIES
travis-yaml! travis-yaml!
unicorn unicorn
yard-sinatra! yard-sinatra!
BUNDLED WITH
1.10.6

View File

@ -1,6 +1,5 @@
namespace :db do namespace :db do
env = ENV["RAILS_ENV"] env = ENV["RAILS_ENV"]
# fail "Cannot run rake db:create in production." if env == 'production'
desc "Create and migrate the #{env} database" desc "Create and migrate the #{env} database"
task :create do task :create do
sh "createdb travis_#{env}" rescue nil sh "createdb travis_#{env}" rescue nil

View File

@ -58,11 +58,8 @@ class Rack::Attack
#### ####
# Ban based on: IP address or access token # Ban based on: IP address or access token
# Ban time: 1 hour # Ban time: 1 hour
# Ban after: 10 POST requests within 30 seconds, unless api_builds_rate_limit is set in repository settings # Ban after: 10 POST requests within 30 seconds
blacklist('spamming with POST requests') do |request| blacklist('spamming with POST requests') do |request|
p "request.inspect ++++++++++++++++++++++++++++"
p request.inspect
p "+++++++++++++++++++++++++++++++++++++++++++++++++++"
Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 10, findtime: 30.seconds, bantime: bantime(1.hour)) do Rack::Attack::Allow2Ban.filter(request.identifier, maxretry: 10, findtime: 30.seconds, bantime: bantime(1.hour)) do
request.post? and not POST_WHITELISTED.include? request.path request.post? and not POST_WHITELISTED.include? request.path
end end

View File

@ -22,14 +22,15 @@ module Travis::API::V3
accepted(remaining_requests: remaining, repository: repository, request: payload) accepted(remaining_requests: remaining, repository: repository, request: payload)
end end
def limit def limit(repository)
Travis.config.requests_create_api_limit || LIMIT repository.settings.try(:api_builds_rate_limit) || LIMIT
end end
def remaining_requests(repository) def remaining_requests(repository)
return limit if access_control.full_access? api_builds_rate_limit = limit(repository)
return api_builds_rate_limit if access_control.full_access?
count = query(:requests).count(repository, TIME_FRAME) count = query(:requests).count(repository, TIME_FRAME)
count > limit ? 0 : limit - count count > api_builds_rate_limit ? 0 : api_builds_rate_limit - count
end end
end end
end end