update rakefile to allow heroku deployment, update create.rb with api builds rate limit
This commit is contained in:
parent
d6c0621d71
commit
f51cf1a1d1
|
@ -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
|
||||
|
|
1
Rakefile
1
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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user