puppet-forge-server 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/lib/puppet_forge_server.rb +4 -0
- data/lib/puppet_forge_server/api/v1/modules.rb +7 -3
- data/lib/puppet_forge_server/api/v3/modules.rb +7 -2
- data/lib/puppet_forge_server/api/v3/releases.rb +9 -4
- data/lib/puppet_forge_server/app/frontend.rb +19 -0
- data/lib/puppet_forge_server/app/public/css/puppetlabs.css +236 -0
- data/lib/puppet_forge_server/app/views/layout.haml +1 -1
- data/lib/puppet_forge_server/app/views/module.haml +71 -0
- data/lib/puppet_forge_server/app/views/modules.haml +1 -1
- data/lib/puppet_forge_server/backends/directory.rb +12 -5
- data/lib/puppet_forge_server/backends/proxy.rb +29 -4
- data/lib/puppet_forge_server/backends/proxy_v3.rb +20 -6
- data/lib/puppet_forge_server/http/http_client.rb +29 -2
- data/lib/puppet_forge_server/logger.rb +9 -2
- data/lib/puppet_forge_server/models/builder.rb +6 -1
- data/lib/puppet_forge_server/models/metadata.rb +1 -1
- data/lib/puppet_forge_server/models/module.rb +2 -2
- data/lib/puppet_forge_server/server.rb +2 -0
- data/lib/puppet_forge_server/utils/archiver.rb +3 -1
- data/lib/puppet_forge_server/utils/cache_provider.rb +42 -0
- data/lib/puppet_forge_server/utils/encoding.rb +46 -0
- data/lib/puppet_forge_server/utils/filtering_inspecter.rb +30 -0
- data/lib/puppet_forge_server/utils/md_renderer.rb +54 -0
- data/lib/puppet_forge_server/utils/option_parser.rb +23 -1
- data/lib/puppet_forge_server/version.rb +1 -1
- data/puppet-forge-server.gemspec +8 -0
- data/spec/spec_helper.rb +41 -1
- data/spec/unit/http/http_client_spec.rb +93 -0
- data/spec/unit/utils/encoding_spec.rb +35 -0
- metadata +110 -2
@@ -28,9 +28,23 @@ module PuppetForgeServer::Utils
|
|
28
28
|
@@DEFAULT_LOG_DIR = File.join(Dir.tmpdir.to_s, 'puppet-forge-server', 'log')
|
29
29
|
@@DEFAULT_WEBUI_ROOT = File.expand_path('../app', File.dirname(__FILE__))
|
30
30
|
@@DEFAULT_HOST = '0.0.0.0'
|
31
|
+
@@DEFAULT_RAM_CACHE_TTL = 60 * 30 # 30min
|
32
|
+
@@DEFAULT_RAM_CACHE_SIZE = 250
|
33
|
+
|
34
|
+
def self.DEFAULT_OPTIONS
|
35
|
+
{
|
36
|
+
:daemonize => @@DEFAULT_DAEMONIZE,
|
37
|
+
:cache_basedir => @@DEFAULT_CACHE_DIR,
|
38
|
+
:port => @@DEFAULT_PORT,
|
39
|
+
:webui_root => @@DEFAULT_WEBUI_ROOT,
|
40
|
+
:host => @@DEFAULT_HOST,
|
41
|
+
:ram_cache_ttl => @@DEFAULT_RAM_CACHE_TTL,
|
42
|
+
:ram_cache_size => @@DEFAULT_RAM_CACHE_SIZE
|
43
|
+
}
|
44
|
+
end
|
31
45
|
|
32
46
|
def parse_options(args)
|
33
|
-
options =
|
47
|
+
options = PuppetForgeServer::Utils::OptionParser.DEFAULT_OPTIONS
|
34
48
|
option_parser = ::OptionParser.new do |opts|
|
35
49
|
opts.banner = "Usage: #{File.basename $0} [options]"
|
36
50
|
opts.version = PuppetForgeServer::VERSION
|
@@ -63,6 +77,14 @@ module PuppetForgeServer::Utils
|
|
63
77
|
options[:cache_basedir] = cache_basedir
|
64
78
|
end
|
65
79
|
|
80
|
+
opts.on('--ram-cache-ttl SECONDS', "The time to live in seconds for remote requests RAM cache (default: #{@@DEFAULT_RAM_CACHE_TTL})") do |ram_cache_ttl|
|
81
|
+
options[:ram_cache_ttl] = ram_cache_ttl
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on('--ram-cache-size ENTRIES', "The maximum number of enties in RAM cache for remote requests (default: #{@@DEFAULT_RAM_CACHE_SIZE})") do |ram_cache_size|
|
85
|
+
options[:ram_cache_size] = ram_cache_size
|
86
|
+
end
|
87
|
+
|
66
88
|
opts.on('--log-dir DIR', "Log directory (default: #{@@DEFAULT_LOG_DIR})") do |log_dir|
|
67
89
|
options[:log_dir] = log_dir
|
68
90
|
end
|
data/puppet-forge-server.gemspec
CHANGED
@@ -44,10 +44,18 @@ Gem::Specification.new do |spec|
|
|
44
44
|
spec.add_dependency 'haml', '~> 4.0'
|
45
45
|
spec.add_dependency 'deep_merge', '~> 1.0'
|
46
46
|
spec.add_dependency 'multipart-post', '~> 2.0.0'
|
47
|
+
spec.add_dependency 'redcarpet', '~> 3.3.0'
|
48
|
+
spec.add_dependency 'lrucache', '~> 0.1.4'
|
49
|
+
spec.add_dependency 'iconv', '~> 1.0.4'
|
50
|
+
spec.add_dependency 'logger-colors', '~> 1.0'
|
47
51
|
|
48
52
|
spec.add_development_dependency 'rake', '~> 10.3'
|
49
53
|
spec.add_development_dependency 'rspec', '~> 3.1'
|
50
54
|
spec.add_development_dependency 'rspec-core', '~> 3.1'
|
55
|
+
spec.add_development_dependency 'simplecov', '~> 0.11.0'
|
56
|
+
spec.add_development_dependency 'rspec-stopwatch', '~> 0.1.3'
|
57
|
+
spec.add_development_dependency 'pry'
|
58
|
+
spec.add_development_dependency 'pry-byebug' if RUBY_VERSION > '2.0.0'
|
51
59
|
|
52
60
|
spec.required_ruby_version = '>= 1.9.3'
|
53
61
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,6 +16,7 @@
|
|
16
16
|
|
17
17
|
require 'rack/test'
|
18
18
|
require 'rspec'
|
19
|
+
require 'rspec/stopwatch'
|
19
20
|
require 'puppet_forge_server'
|
20
21
|
|
21
22
|
ENV['RACK_ENV'] = 'test'
|
@@ -23,8 +24,47 @@ ENV['RACK_ENV'] = 'test'
|
|
23
24
|
module RSpecMixin
|
24
25
|
include Rack::Test::Methods
|
25
26
|
end
|
27
|
+
begin
|
28
|
+
gem 'simplecov'
|
29
|
+
require 'simplecov'
|
30
|
+
formatters = []
|
31
|
+
formatters << SimpleCov::Formatter::HTMLFormatter
|
32
|
+
|
33
|
+
begin
|
34
|
+
gem 'coveralls'
|
35
|
+
require 'coveralls'
|
36
|
+
formatters << Coveralls::SimpleCov::Formatter if ENV['TRAVIS']
|
37
|
+
rescue Gem::LoadError
|
38
|
+
# do nothing
|
39
|
+
end
|
40
|
+
|
41
|
+
begin
|
42
|
+
gem 'codeclimate-test-reporter'
|
43
|
+
require 'codeclimate-test-reporter'
|
44
|
+
formatters << CodeClimate::TestReporter::Formatter if (ENV['TRAVIS'] and ENV['CODECLIMATE_REPO_TOKEN'])
|
45
|
+
rescue Gem::LoadError
|
46
|
+
# do nothing
|
47
|
+
end
|
48
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new(*formatters)
|
49
|
+
SimpleCov.start do
|
50
|
+
add_filter "/spec/"
|
51
|
+
add_filter "/.vendor/"
|
52
|
+
add_filter "/vendor/"
|
53
|
+
add_filter "/gems/"
|
54
|
+
refuse_coverage_drop
|
55
|
+
end
|
56
|
+
rescue Gem::LoadError
|
57
|
+
# do nothing
|
58
|
+
end
|
59
|
+
|
60
|
+
begin
|
61
|
+
gem 'pry'
|
62
|
+
require 'pry'
|
63
|
+
rescue Gem::LoadError
|
64
|
+
# do nothing
|
65
|
+
end
|
26
66
|
|
27
67
|
RSpec.configure do |c|
|
28
68
|
c.include RSpecMixin
|
29
69
|
c.add_formatter(:documentation)
|
30
|
-
end
|
70
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'puppet_forge_server'
|
3
|
+
|
4
|
+
describe PuppetForgeServer::Http::HttpClient do
|
5
|
+
# Finding a free port to host mock server
|
6
|
+
let(:port) do
|
7
|
+
require 'socket'
|
8
|
+
server = TCPServer.new('127.0.0.1', 0)
|
9
|
+
port = server.addr[1]
|
10
|
+
server.close
|
11
|
+
port
|
12
|
+
end
|
13
|
+
let(:uri) { "http://localhost:#{port}/" }
|
14
|
+
before(:each) do
|
15
|
+
# Staring a mock server on free port to test network fetching performence
|
16
|
+
@server = TCPServer.new('localhost', port)
|
17
|
+
@thr = Thread.new do
|
18
|
+
loop do
|
19
|
+
socket = @server.accept
|
20
|
+
response = "Hello!"
|
21
|
+
socket.print "HTTP/1.1 200 OK\r\n" +
|
22
|
+
"Content-Type: text/plain\r\n" +
|
23
|
+
"Content-Length: #{response.bytesize}\r\n" +
|
24
|
+
"Connection: close\r\n"
|
25
|
+
socket.print "\r\n"
|
26
|
+
# To simulate network lag
|
27
|
+
sleep 0.01
|
28
|
+
socket.print response
|
29
|
+
socket.close
|
30
|
+
end
|
31
|
+
end
|
32
|
+
@original_level = PuppetForgeServer::Logger.get.level.first
|
33
|
+
PuppetForgeServer::Logger.get.level = Logger::WARN
|
34
|
+
end
|
35
|
+
after(:each) do
|
36
|
+
@server.close
|
37
|
+
@thr.kill
|
38
|
+
PuppetForgeServer::Logger.get.level = @original_level
|
39
|
+
end
|
40
|
+
let(:instance) { described_class.new(cache) }
|
41
|
+
describe '#download' do
|
42
|
+
let(:load) do
|
43
|
+
Proc.new do
|
44
|
+
# To simulate multiple fetches
|
45
|
+
99.times { instance.download(uri) }
|
46
|
+
instance.download(uri)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
subject do
|
50
|
+
load.call
|
51
|
+
end
|
52
|
+
context 'with 1sec LRU cache' do
|
53
|
+
let(:cache) do
|
54
|
+
require 'lrucache'
|
55
|
+
LRUCache.new(:ttl => 1)
|
56
|
+
end
|
57
|
+
it { expect { load.call }.to run_for < 0.01 }
|
58
|
+
it { expect(subject).not_to be_nil }
|
59
|
+
it { expect(subject).not_to be_closed }
|
60
|
+
end
|
61
|
+
context 'with default cache' do
|
62
|
+
let(:cache) { nil }
|
63
|
+
it { expect { load.call }.to run_for < 0.01 }
|
64
|
+
it { expect(subject).not_to be_nil }
|
65
|
+
it { expect(subject).not_to be_closed }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
describe '#get' do
|
69
|
+
let(:load) do
|
70
|
+
Proc.new do
|
71
|
+
# To simulate multiple fetches
|
72
|
+
99.times { instance.get(uri) }
|
73
|
+
instance.get(uri)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
subject do
|
77
|
+
load.call
|
78
|
+
end
|
79
|
+
context 'with 1sec LRU cache' do
|
80
|
+
let(:cache) do
|
81
|
+
require 'lrucache'
|
82
|
+
LRUCache.new(:ttl => 1)
|
83
|
+
end
|
84
|
+
it { expect(subject).to eq('Hello!') }
|
85
|
+
it { expect { load.call }.to run_for < 0.01 }
|
86
|
+
end
|
87
|
+
context 'with default cache' do
|
88
|
+
let(:cache) { nil }
|
89
|
+
it { expect(subject).to eq('Hello!') }
|
90
|
+
it { expect { load.call }.to run_for < 0.01 }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe 'PuppetForgeServer::Utils::Encoding' do
|
5
|
+
let(:dummy_class) { Class.new { include PuppetForgeServer::Utils::Encoding } }
|
6
|
+
let(:dummy) { dummy_class.new }
|
7
|
+
describe '#to_utf8' do
|
8
|
+
subject { dummy.to_utf8(input_text) }
|
9
|
+
context 'for nil' do
|
10
|
+
let(:input_text) { nil }
|
11
|
+
it { expect(subject).to be_nil }
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'for valid ascii text' do
|
15
|
+
let(:input_text) { 'a simple ascii text!' }
|
16
|
+
it { expect(subject).to eq('a simple ascii text!') }
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'for valid utf-8 text' do
|
20
|
+
let(:input_text) { 'Zażółć gęślą jażń' }
|
21
|
+
it { expect(subject).to eq('Zażółć gęślą jażń') }
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'for text with ISO-8859-1 encoded as UTF-8' do
|
25
|
+
let(:input_text) { "Co\xE2te d'Azur" }
|
26
|
+
it { expect(subject).to eq('Cote d\'Azur') }
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'for text with UTF-8 not replaced characters' do
|
30
|
+
let(:multidot) { [0xE2, 0x80, 0xA6].pack("c*") }
|
31
|
+
let(:input_text) { "Read more#{multidot}" }
|
32
|
+
it { expect(subject).to eq('Read more…') }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-forge-server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ilja Bobkevic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sinatra
|
@@ -150,6 +150,62 @@ dependencies:
|
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: 2.0.0
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: redcarpet
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 3.3.0
|
160
|
+
type: :runtime
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 3.3.0
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: lrucache
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.1.4
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 0.1.4
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: iconv
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: 1.0.4
|
188
|
+
type: :runtime
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: 1.0.4
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: logger-colors
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '1.0'
|
202
|
+
type: :runtime
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '1.0'
|
153
209
|
- !ruby/object:Gem::Dependency
|
154
210
|
name: rake
|
155
211
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +248,48 @@ dependencies:
|
|
192
248
|
- - "~>"
|
193
249
|
- !ruby/object:Gem::Version
|
194
250
|
version: '3.1'
|
251
|
+
- !ruby/object:Gem::Dependency
|
252
|
+
name: simplecov
|
253
|
+
requirement: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - "~>"
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: 0.11.0
|
258
|
+
type: :development
|
259
|
+
prerelease: false
|
260
|
+
version_requirements: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - "~>"
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: 0.11.0
|
265
|
+
- !ruby/object:Gem::Dependency
|
266
|
+
name: rspec-stopwatch
|
267
|
+
requirement: !ruby/object:Gem::Requirement
|
268
|
+
requirements:
|
269
|
+
- - "~>"
|
270
|
+
- !ruby/object:Gem::Version
|
271
|
+
version: 0.1.3
|
272
|
+
type: :development
|
273
|
+
prerelease: false
|
274
|
+
version_requirements: !ruby/object:Gem::Requirement
|
275
|
+
requirements:
|
276
|
+
- - "~>"
|
277
|
+
- !ruby/object:Gem::Version
|
278
|
+
version: 0.1.3
|
279
|
+
- !ruby/object:Gem::Dependency
|
280
|
+
name: pry
|
281
|
+
requirement: !ruby/object:Gem::Requirement
|
282
|
+
requirements:
|
283
|
+
- - ">="
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: '0'
|
286
|
+
type: :development
|
287
|
+
prerelease: false
|
288
|
+
version_requirements: !ruby/object:Gem::Requirement
|
289
|
+
requirements:
|
290
|
+
- - ">="
|
291
|
+
- !ruby/object:Gem::Version
|
292
|
+
version: '0'
|
195
293
|
description: Private Puppet forge server supports local files, both v1 and v3 API
|
196
294
|
proxies
|
197
295
|
email: ilja.bobkevic@unibet.com
|
@@ -201,6 +299,7 @@ extensions: []
|
|
201
299
|
extra_rdoc_files: []
|
202
300
|
files:
|
203
301
|
- ".gitignore"
|
302
|
+
- ".rspec"
|
204
303
|
- ".travis.yml"
|
205
304
|
- Gemfile
|
206
305
|
- README.md
|
@@ -222,6 +321,7 @@ files:
|
|
222
321
|
- lib/puppet_forge_server/app/version3.rb
|
223
322
|
- lib/puppet_forge_server/app/views/index.haml
|
224
323
|
- lib/puppet_forge_server/app/views/layout.haml
|
324
|
+
- lib/puppet_forge_server/app/views/module.haml
|
225
325
|
- lib/puppet_forge_server/app/views/modules.haml
|
226
326
|
- lib/puppet_forge_server/app/views/upload.haml
|
227
327
|
- lib/puppet_forge_server/backends/directory.rb
|
@@ -239,7 +339,11 @@ files:
|
|
239
339
|
- lib/puppet_forge_server/server.rb
|
240
340
|
- lib/puppet_forge_server/utils/archiver.rb
|
241
341
|
- lib/puppet_forge_server/utils/buffer.rb
|
342
|
+
- lib/puppet_forge_server/utils/cache_provider.rb
|
343
|
+
- lib/puppet_forge_server/utils/encoding.rb
|
344
|
+
- lib/puppet_forge_server/utils/filtering_inspecter.rb
|
242
345
|
- lib/puppet_forge_server/utils/http.rb
|
346
|
+
- lib/puppet_forge_server/utils/md_renderer.rb
|
243
347
|
- lib/puppet_forge_server/utils/option_parser.rb
|
244
348
|
- lib/puppet_forge_server/version.rb
|
245
349
|
- puppet-forge-server.gemspec
|
@@ -247,10 +351,12 @@ files:
|
|
247
351
|
- spec/unit/app/version1_spec.rb
|
248
352
|
- spec/unit/app/version2_spec.rb
|
249
353
|
- spec/unit/backends/directory_spec.rb
|
354
|
+
- spec/unit/http/http_client_spec.rb
|
250
355
|
- spec/unit/logger_spec.rb
|
251
356
|
- spec/unit/models/dependency_spec.rb
|
252
357
|
- spec/unit/models/metadata_spec.rb
|
253
358
|
- spec/unit/server_spec.rb
|
359
|
+
- spec/unit/utils/encoding_spec.rb
|
254
360
|
homepage: https://github.com/unibet/puppet-forge-server
|
255
361
|
licenses:
|
256
362
|
- Apache 2
|
@@ -280,7 +386,9 @@ test_files:
|
|
280
386
|
- spec/unit/app/version1_spec.rb
|
281
387
|
- spec/unit/app/version2_spec.rb
|
282
388
|
- spec/unit/backends/directory_spec.rb
|
389
|
+
- spec/unit/http/http_client_spec.rb
|
283
390
|
- spec/unit/logger_spec.rb
|
284
391
|
- spec/unit/models/dependency_spec.rb
|
285
392
|
- spec/unit/models/metadata_spec.rb
|
286
393
|
- spec/unit/server_spec.rb
|
394
|
+
- spec/unit/utils/encoding_spec.rb
|