geminabox 0.12.3 → 0.12.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of geminabox might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWI3ZTAwOTg3NjFmZTcwN2RmNDNhZTYwM2MzMjM4YWE5OWI4NzUyNg==
4
+ MTBmZWQxYjM3NjFlODM4NmQ0N2ViMjY1MjU0ZjRiMWE4ODcyMjFmYw==
5
5
  data.tar.gz: !binary |-
6
- YThlZTE0MWJkYTI5YzNlMTkxNjkyMjQ2ZTEzNGUzOTU4NDQ5NmZlYw==
6
+ NTcwNGQ5YjkxMDNkMGMzOWNmMThjNTJlNmVlNDg0MjE0MGEzNTdkMg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MDYyOTRiMDA0ZDhkOTY4YTQ1MzQxMTQ1YzYzZGVkNzlhOWNjMzU5ZDQwNTBk
10
- YTUwYTJlZDg1N2ZlOWE5MjNmMWRjYjE2MTY3ZmRhNTBiYTVlODMxYzg2NWU5
11
- ZDUzYjg3Y2FmMTdjNGQxMzRiZmM3YmE4YWRiZmJhZTI2YmRmYmM=
9
+ YWQyZjU1NWM4M2FmY2U1NDgzMzU5MTgzYWI1ZTVjYzc0ZWVjNTM4MTkyMzRk
10
+ NTc3NjM4N2VkNTljODAwZjk5MDQ5MTdiZjU1ZGMyNTg0ZjMzNTQ3Y2FkMjJk
11
+ YjE2NTI2Y2NiNzY5NWUyNzdlNGJiMTBlOWU1MDBiYzJjZDg3MzU=
12
12
  data.tar.gz: !binary |-
13
- M2Q3NmZmZDk2MzE1N2E3YzdjNDVmMzJlNDkzOTU4YzBlZWU0YTA1MDAyZjUy
14
- N2VmZTE4YTkyMjkyOTA5NTRmMWU2ZWViNmUzZTQ4M2FkYjVlYmEyOTdkZTc3
15
- NWJlMGU1MzlhNDY5OWI3YWE5YzVkYWIxZDEzYjZkNDU4MDkwYjE=
13
+ NTUwM2EwZGVjYzc2ZTI3YjExMjI2ODI3ODZlMjc2YzIzOWUyM2IxMmIyYmMy
14
+ MDdkMTNmY2E5ZmRkYzNiM2YyMjliMWViYjM2NWFlMWFmMzY5NWFmOTFiY2Uz
15
+ ZDc1ZmU4NWY3MjM1NTY3MDg1MTcyYWM5NDY5YjgzOWM3MmZkODA=
@@ -48,6 +48,26 @@ Or in config.ru (before the run command), set:
48
48
 
49
49
  Geminabox.rubygems_proxy = true
50
50
 
51
+ ## HTTP adapter
52
+
53
+ Geminabox uses the HTTPClient gem to manage its connections to remote resources.
54
+ The relationship is managed via Geminabox::HttpClientAdapter.
55
+
56
+ If you would like to use an alternative HTTP gem, create your own adapter
57
+ and specify it in config.ru:
58
+
59
+ Geminabox.http_adapter = YourHttpAdapter.new
60
+
61
+ It is recommend (but not essential) that your adapter inherits from HttpAdapter.
62
+ The adapter will need to replace HttpAdapter's methods with those specific to
63
+ the alternative HTTP gem. It should also be able to handle HTTP proxy
64
+ settings.
65
+
66
+ Defining your own adapter also allows you to configure Geminabox to use the
67
+ local systems SSL certificates.
68
+
69
+ TemplateFaradayAdapter is provided as an example of an alternative HTTPAdapter.
70
+
51
71
  ## Client Usage
52
72
 
53
73
  Since version 0.10, Geminabox supports the standard gemcutter push API:
@@ -13,21 +13,22 @@ module Geminabox
13
13
 
14
14
  require_relative 'geminabox/version'
15
15
  require_relative 'geminabox/proxy'
16
+ require_relative 'geminabox/http_adapter'
16
17
 
17
18
  def self.geminabox_path(file)
18
19
  File.join File.dirname(__FILE__), 'geminabox', file
19
20
  end
20
21
 
21
- autoload :Hostess, geminabox_path('hostess')
22
- autoload :GemStore, geminabox_path('gem_store')
23
- autoload :GemStoreError, geminabox_path('gem_store_error')
24
- autoload :RubygemsDependency, geminabox_path('rubygems_dependency')
25
- autoload :GemListMerge, geminabox_path('gem_list_merge')
26
- autoload :GemVersion, geminabox_path('gem_version')
27
- autoload :GemVersionCollection, geminabox_path('gem_version_collection')
28
- autoload :Server, geminabox_path('server')
29
- autoload :DiskCache, geminabox_path('disk_cache')
30
- autoload :IncomingGem, geminabox_path('incoming_gem')
22
+ autoload :Hostess, geminabox_path('hostess')
23
+ autoload :GemStore, geminabox_path('gem_store')
24
+ autoload :GemStoreError, geminabox_path('gem_store_error')
25
+ autoload :RubygemsDependency, geminabox_path('rubygems_dependency')
26
+ autoload :GemListMerge, geminabox_path('gem_list_merge')
27
+ autoload :GemVersion, geminabox_path('gem_version')
28
+ autoload :GemVersionCollection, geminabox_path('gem_version_collection')
29
+ autoload :Server, geminabox_path('server')
30
+ autoload :DiskCache, geminabox_path('disk_cache')
31
+ autoload :IncomingGem, geminabox_path('incoming_gem')
31
32
 
32
33
  class << self
33
34
 
@@ -40,7 +41,9 @@ module Geminabox
40
41
  :allow_replace,
41
42
  :gem_permissions,
42
43
  :allow_delete,
43
- :rubygems_proxy
44
+ :rubygems_proxy,
45
+ :http_adapter,
46
+ :allow_remote_failure
44
47
  )
45
48
 
46
49
  def set_defaults(defaults)
@@ -60,17 +63,17 @@ module Geminabox
60
63
  end
61
64
 
62
65
  set_defaults(
63
-
64
- data: File.join(File.dirname(__FILE__), *%w[.. data]),
65
- public_folder: File.join(File.dirname(__FILE__), *%w[.. public]),
66
- build_legacy: false,
67
- incremental_updates: true,
68
- views: File.join(File.dirname(__FILE__), *%w[.. views]),
69
- allow_replace: false,
70
- gem_permissions: 0644,
71
- rubygems_proxy: (ENV['RUBYGEMS_PROXY'] == 'true'),
72
- allow_delete: true
73
-
66
+ data: File.join(File.dirname(__FILE__), *%w[.. data]),
67
+ public_folder: File.join(File.dirname(__FILE__), *%w[.. public]),
68
+ build_legacy: false,
69
+ incremental_updates: true,
70
+ views: File.join(File.dirname(__FILE__), *%w[.. views]),
71
+ allow_replace: false,
72
+ gem_permissions: 0644,
73
+ rubygems_proxy: (ENV['RUBYGEMS_PROXY'] == 'true'),
74
+ allow_delete: true,
75
+ http_adapter: HttpClientAdapter.new,
76
+ allow_remote_failure: false
74
77
  )
75
78
 
76
79
  end
@@ -0,0 +1,27 @@
1
+ require_relative 'http_adapter_config_error'
2
+
3
+ module Geminabox
4
+ class HttpAdapter
5
+
6
+ def get_content(*args)
7
+ raise HttpAdapterConfigError.new(:get_content, 'the response body')
8
+ end
9
+
10
+ def get(*args)
11
+ raise HttpAdapterConfigError.new(:get, 'a response object')
12
+ end
13
+
14
+ def post(*args)
15
+ raise HttpAdapterConfigError.new(:post, 'a response object')
16
+ end
17
+
18
+ def set_auth(*args)
19
+ raise HttpAdapterConfigError.new(:set_auth, 'true')
20
+ end
21
+
22
+ end
23
+ end
24
+
25
+ Dir[File.expand_path('http_adapter/*.rb', File.dirname(__FILE__))].each do |file|
26
+ require file
27
+ end
@@ -0,0 +1,32 @@
1
+ require 'httpclient'
2
+
3
+ module Geminabox
4
+
5
+ class HttpClientAdapter < HttpAdapter
6
+
7
+ def get(*args)
8
+ http_client.get(*args)
9
+ end
10
+
11
+ def get_content(*args)
12
+ http_client.get_content(*args)
13
+ end
14
+
15
+ def post(*args)
16
+ http_client.post(*args)
17
+ end
18
+
19
+ def set_auth(url, username = nil, password = nil)
20
+ http_client.set_auth(url, username, password) if username or password
21
+ http_client.www_auth.basic_auth.challenge(url) # Workaround: https://github.com/nahi/httpclient/issues/63
22
+ http_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
23
+ http_client.send_timeout = 0
24
+ http_client.receive_timeout = 0
25
+ end
26
+
27
+ def http_client
28
+ @http_client ||= HTTPClient.new(ENV['http_proxy'])
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,51 @@
1
+ require 'faraday'
2
+
3
+ module Geminabox
4
+
5
+ class TemplateFaradayAdapter < HttpAdapter
6
+
7
+ def get(*args)
8
+ adapter.get(*args)
9
+ end
10
+
11
+ def get_content(*args)
12
+ response = adapter.get(*args)
13
+ response.body
14
+ end
15
+
16
+ def post(*args)
17
+ adapter.post(*args)
18
+ end
19
+
20
+ # Note that this configuration turns SSL certificate verification off.
21
+ # To set up the adapter for your environment see:
22
+ # https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates
23
+ def set_auth(uri, username = nil, password = nil)
24
+ connection = Faraday.new url: uri, ssl: {verify: false} do |faraday|
25
+ faraday.adapter http_engine
26
+ faraday.proxy(ENV['http_proxy']) if ENV['http_proxy']
27
+ end
28
+ connection.basic_auth username, password if username
29
+ connection
30
+ end
31
+
32
+ def adapter
33
+ @adapter ||= Faraday.new do |faraday|
34
+ faraday.adapter http_engine
35
+ faraday.proxy(ENV['http_proxy']) if ENV['http_proxy']
36
+ end
37
+ end
38
+
39
+ def http_engine
40
+ :net_http # make requests with Net::HTTP
41
+ end
42
+
43
+ def options
44
+ lambda {|faraday|
45
+ faraday.adapter http_engine
46
+ faraday.proxy(ENV['http_proxy']) if ENV['http_proxy']
47
+ }
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,7 @@
1
+ module Geminabox
2
+ class HttpAdapterConfigError < StandardError
3
+ def initialize(method_name, returns)
4
+ super("#{method_name} must be defined, and return #{returns}")
5
+ end
6
+ end
7
+ end
@@ -10,7 +10,7 @@ module Geminabox
10
10
  if RbConfig::CONFIG["MAJOR"].to_i <= 1 and RbConfig::CONFIG["MINOR"].to_i <= 8
11
11
  @tempfile = Tempfile.new("gem")
12
12
  else
13
- @tempfile = Tempfile.new("gem", :encoding => 'binary')
13
+ @tempfile = Tempfile.new("gem", :encoding => 'binary', :binmode => true)
14
14
  end
15
15
 
16
16
  while data = gem_data.read(1024**2)
@@ -1,4 +1,4 @@
1
- require 'httpclient'
1
+
2
2
  module Geminabox
3
3
  module Proxy
4
4
  class FileHandler
@@ -43,7 +43,7 @@ module Geminabox
43
43
  end
44
44
 
45
45
  def remote_content
46
- HTTPClient.get_content(remote_url).force_encoding(encoding)
46
+ Geminabox.http_adapter.get_content(remote_url).force_encoding(encoding)
47
47
  rescue
48
48
  raise GemStoreError.new(500, "Unable to get content from #{remote_url}")
49
49
  end
@@ -59,21 +59,14 @@ module Geminabox
59
59
  file = File.expand_path(File.join(Server.data, *request.path_info))
60
60
 
61
61
  unless File.exists?(file)
62
- net_http_class.start("production.cf.rubygems.org") do |http|
63
- path = File.join(*request.path_info)
64
- response = http.get(path)
65
- GemStore.create(IncomingGem.new(StringIO.new(response.body)))
66
- end
62
+ ruby_gems_url = 'http://production.cf.rubygems.org'
63
+ path = File.join(ruby_gems_url, *request.path_info)
64
+ content = Geminabox.http_adapter.get_content(path)
65
+ GemStore.create(IncomingGem.new(StringIO.new(content)))
67
66
  end
68
67
 
69
68
  end
70
69
 
71
- def net_http_class
72
- return ::Net::HTTP unless ENV['http_proxy']
73
- proxy_uri = URI.parse(ENV['http_proxy'])
74
- ::Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_uri.user, proxy_uri.password)
75
- end
76
-
77
70
  def splice_file(file_name)
78
71
  self.file_handler = Splicer.make(file_name)
79
72
  end
@@ -1,4 +1,3 @@
1
- require 'httpclient'
2
1
  require 'json'
3
2
 
4
3
  module Geminabox
@@ -13,8 +12,11 @@ module Geminabox
13
12
  '?gems=',
14
13
  gems.map(&:to_s).join(',')
15
14
  ].join
16
- body = HTTPClient.get_content(url)
15
+ body = Geminabox.http_adapter.get_content(url)
17
16
  JSON.parse(body)
17
+ rescue Exception => e
18
+ return [] if Geminabox.allow_remote_failure
19
+ raise e
18
20
  end
19
21
 
20
22
  def rubygems_uri
@@ -241,7 +241,10 @@ HTML
241
241
  filename = [gem_name, version]
242
242
  filename.push(platform) if platform != default_platform
243
243
  spec_file = File.join(settings.data, "quick", "Marshal.#{Gem.marshal_version}", "#{filename.join("-")}.gemspec.rz")
244
- Marshal.load(Gem.inflate(File.read(spec_file))) if File.exists? spec_file
244
+ File::open(spec_file, 'r') do |unzipped_spec_file|
245
+ unzipped_spec_file.binmode
246
+ Marshal.load(Gem.inflate(unzipped_spec_file.read))
247
+ end if File.exists? spec_file
245
248
  end
246
249
 
247
250
  def default_platform
@@ -1,3 +1,3 @@
1
1
  module Geminabox
2
- VERSION = '0.12.3' unless defined? VERSION
2
+ VERSION = '0.12.4' unless defined? VERSION
3
3
  end
@@ -1,17 +1,13 @@
1
1
  require 'uri'
2
- require 'httpclient'
2
+ require 'geminabox'
3
3
 
4
4
  class GeminaboxClient
5
5
  attr_reader :url, :http_client
6
6
 
7
7
  def initialize(url)
8
8
  extract_username_and_password_from_url!(url)
9
- @http_client = HTTPClient.new
10
- @http_client.set_auth(url_for(:upload), @username, @password) if @username or @password
11
- @http_client.www_auth.basic_auth.challenge(url_for(:upload)) # Workaround: https://github.com/nahi/httpclient/issues/63
12
- @http_client.ssl_config.verify_mode = OpenSSL::SSL::VERIFY_NONE
13
- @http_client.send_timeout = 0
14
- @http_client.receive_timeout = 0
9
+ @http_client = Geminabox.http_adapter
10
+ @http_client.set_auth(url_for(:upload), @username, @password)
15
11
  end
16
12
 
17
13
  def extract_username_and_password_from_url!(url)
@@ -32,7 +28,7 @@ class GeminaboxClient
32
28
  if response.status < 300
33
29
  response.body
34
30
  else
35
- raise GeminaboxClient::Error, "Error (#{response.code} received)\n\n#{response.body}"
31
+ raise GeminaboxClient::Error, "Error (#{response.status} received)\n\n#{response.body}"
36
32
  end
37
33
  end
38
34
 
@@ -27,6 +27,10 @@ class Gem::Commands::InaboxCommand < Gem::Command
27
27
  add_option('-o', '--overwrite', "Overwrite Gem.") do |value, options|
28
28
  options[:overwrite] = true
29
29
  end
30
+
31
+ add_option('-p', '--port', "Sets port") do |value, options|
32
+ options[:port] = value
33
+ end
30
34
  end
31
35
 
32
36
  def last_minute_requires!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geminabox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.3
4
+ version: 0.12.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Lea
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-03-06 00:00:00.000000000 Z
13
+ date: 2014-03-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sinatra
@@ -68,6 +68,20 @@ dependencies:
68
68
  - - ! '>='
69
69
  - !ruby/object:Gem::Version
70
70
  version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: faraday
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
71
85
  - !ruby/object:Gem::Dependency
72
86
  name: rake
73
87
  requirement: !ruby/object:Gem::Requirement
@@ -108,36 +122,40 @@ extra_rdoc_files:
108
122
  files:
109
123
  - MIT-LICENSE
110
124
  - README.markdown
111
- - lib/geminabox_client.rb
112
125
  - lib/rubygems_plugin.rb
126
+ - lib/geminabox/version.rb
113
127
  - lib/geminabox/gem_store_error.rb
114
- - lib/geminabox/server.rb
115
- - lib/geminabox/gem_version_collection.rb
116
- - lib/geminabox/disk_cache.rb
128
+ - lib/geminabox/incoming_gem.rb
129
+ - lib/geminabox/gem_version.rb
130
+ - lib/geminabox/hostess.rb
131
+ - lib/geminabox/indexer.rb
132
+ - lib/geminabox/gem_list_merge.rb
117
133
  - lib/geminabox/rubygems_dependency.rb
118
- - lib/geminabox/proxy/copier.rb
134
+ - lib/geminabox/proxy.rb
119
135
  - lib/geminabox/proxy/file_handler.rb
120
136
  - lib/geminabox/proxy/hostess.rb
137
+ - lib/geminabox/proxy/copier.rb
121
138
  - lib/geminabox/proxy/splicer.rb
122
- - lib/geminabox/proxy.rb
123
- - lib/geminabox/hostess.rb
139
+ - lib/geminabox/gem_version_collection.rb
140
+ - lib/geminabox/http_adapter/http_client_adapter.rb
141
+ - lib/geminabox/http_adapter/template_faraday_adapter.rb
142
+ - lib/geminabox/server.rb
143
+ - lib/geminabox/disk_cache.rb
144
+ - lib/geminabox/http_adapter.rb
145
+ - lib/geminabox/http_adapter_config_error.rb
124
146
  - lib/geminabox/gem_store.rb
125
- - lib/geminabox/version.rb
126
- - lib/geminabox/gem_list_merge.rb
127
- - lib/geminabox/incoming_gem.rb
128
- - lib/geminabox/indexer.rb
129
- - lib/geminabox/gem_version.rb
130
- - lib/geminabox.rb
131
147
  - lib/rubygems/commands/inabox_command.rb
148
+ - lib/geminabox_client.rb
149
+ - lib/geminabox.rb
150
+ - public/master.js
132
151
  - public/master.css
133
152
  - public/jquery.js
134
153
  - public/favicon.ico
135
- - public/master.js
154
+ - views/atom.erb
155
+ - views/gem.erb
136
156
  - views/upload.erb
137
- - views/index.erb
138
157
  - views/layout.erb
139
- - views/gem.erb
140
- - views/atom.erb
158
+ - views/index.erb
141
159
  homepage: http://tomlea.co.uk/p/gem-in-a-box
142
160
  licenses:
143
161
  - MIT-LICENSE
@@ -160,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
178
  version: '0'
161
179
  requirements: []
162
180
  rubyforge_project:
163
- rubygems_version: 2.1.11
181
+ rubygems_version: 2.1.10
164
182
  signing_key:
165
183
  specification_version: 4
166
184
  summary: Really simple rubygem hosting