diff --git a/Gemfile.lock b/Gemfile.lock index 7f9f612b..30724ec1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -48,7 +48,7 @@ GIT GIT remote: git://github.com/travis-ci/travis-core.git - revision: f7b3a76b3f39c28bb5cf7b9dc24acec13908a11a + revision: 57634c3103dec6472bf732de5f051702224dc345 specs: travis-core (0.0.1) actionmailer (~> 3.2.19) @@ -331,7 +331,7 @@ GEM treetop (1.4.15) polyglot polyglot (>= 0.3.1) - tzinfo (0.3.47) + tzinfo (0.3.48) unicorn (4.8.3) kgio (~> 2.6) rack @@ -388,3 +388,6 @@ DEPENDENCIES travis-yaml! unicorn yard-sinatra! + +BUNDLED WITH + 1.10.6 diff --git a/Rakefile b/Rakefile index 80871975..f1cee930 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,5 @@ namespace :db do env = ENV["RAILS_ENV"] - # fail "Cannot run rake db:create in production." if env == 'production' desc "Create and migrate the #{env} database" task :create do sh "createdb travis_#{env}" rescue nil diff --git a/lib/travis/api/attack.rb b/lib/travis/api/attack.rb index fbec755d..d210b633 100644 --- a/lib/travis/api/attack.rb +++ b/lib/travis/api/attack.rb @@ -58,11 +58,8 @@ class Rack::Attack #### # Ban based on: IP address or access token # 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| - p "request.inspect ++++++++++++++++++++++++++++" - p request.inspect - p "+++++++++++++++++++++++++++++++++++++++++++++++++++" 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 end diff --git a/lib/travis/api/v3/services/requests/create.rb b/lib/travis/api/v3/services/requests/create.rb index c3353daf..24254be1 100644 --- a/lib/travis/api/v3/services/requests/create.rb +++ b/lib/travis/api/v3/services/requests/create.rb @@ -22,14 +22,15 @@ module Travis::API::V3 accepted(remaining_requests: remaining, repository: repository, request: payload) end - def limit - Travis.config.requests_create_api_limit || LIMIT + def limit(repository) + repository.settings.try(:api_builds_rate_limit) || LIMIT end 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 > limit ? 0 : limit - count + count > api_builds_rate_limit ? 0 : api_builds_rate_limit - count end end end