Skip to content

Commit

Permalink
[api] do not forbid to connect to the backend
Browse files Browse the repository at this point in the history
  • Loading branch information
coolo committed Dec 20, 2012
1 parent f1bdfca commit 164f9ec
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
37 changes: 17 additions & 20 deletions src/api/app/models/distribution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,26 @@ def self.all_as_hash
end

def self.all_including_remotes
local = Distribution.all_as_hash

remote = Rails.cache.fetch("remote_distribution_list", expires_in: 1.day) do
list = []
remote_projects = Project.where("NOT ISNULL(projects.remoteurl)")
remote_projects.each do |prj|
body = ActiveXML.transport.load_external_url(prj.remoteurl + "/distributions.xml")
next if body.blank? # don't let broken remote instances break us
xmlhash = Xmlhash.parse(body)
xmlhash.elements('distribution') do |d|
iconlist = []
d.elements('icon') do |i|
iconlist << { "width" => i['width'], "height" => i['height'], "url" => i['url'] }
end
list << {"vendor" => d['vendor'], "version" => d['version'], "name" => d['name'],
"project" => prj.name + ":" + d['project'], "icons" => iconlist,
"reponame" => d['reponame'], "repository" => d['repository'], "link" => d['link']}
list = Distribution.all_as_hash

remote_projects = Project.where("NOT ISNULL(projects.remoteurl)")
remote_projects.each do |prj|
body = Rails.cache.fetch("remote_distribution_#{prj.id}", expires_in: 1.hour) do
ActiveXML.transport.load_external_url(prj.remoteurl + "/distributions.xml")
end
next if body.blank? # don't let broken remote instances break us
xmlhash = Xmlhash.parse(body)
xmlhash.elements('distribution') do |d|
iconlist = []
d.elements('icon') do |i|
iconlist << { "width" => i['width'], "height" => i['height'], "url" => i['url'] }
end
list << {"vendor" => d['vendor'], "version" => d['version'], "name" => d['name'],
"project" => prj.name + ":" + d['project'], "icons" => iconlist,
"reponame" => d['reponame'], "repository" => d['repository'], "link" => d['link']}
end
list
end

return local + remote
return list
end

end
1 change: 1 addition & 0 deletions src/api/config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@
# make sure we have invalid setup for errbit
CONFIG['errbit_api_key'] = 'INVALID'
CONFIG['errbit_host'] = '192.0.2.0'

2 changes: 1 addition & 1 deletion src/api/script/start_test_backend
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
# check for still running daemons from former run
[ '3200', '3201', '3202' ].each do |port|
begin
Net::HTTP.start(CONFIG['source_host'], 3201) {|http| http.get('/') }
Net::HTTP.start(CONFIG['source_host'], port) {|http| http.get('/') }
puts "ERROR Port #{port} is already in use, maybe from former unclean shutdown, aborting ..."
exit 1
rescue Errno::ECONNREFUSED, Errno::ENETUNREACH
Expand Down
2 changes: 2 additions & 0 deletions src/api/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

require 'webmock/minitest'

WebMock.disable_net_connect!(allow: CONFIG['source_host'])

# uncomment to enable tests which currently are known to fail, but where either the test
# or the code has to be fixed
#$ENABLE_BROKEN_TEST=true
Expand Down

0 comments on commit 164f9ec

Please sign in to comment.