piedesaint 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/piedesaint/cli.rb +2 -1
- data/lib/piedesaint/version.rb +1 -1
- data/lib/piedesaint.rb +35 -21
- data/piedesaint.gemspec +2 -0
- metadata +20 -4
data/lib/piedesaint/cli.rb
CHANGED
@@ -18,7 +18,7 @@ module Piedesaint
|
|
18
18
|
piedesanto.start
|
19
19
|
end
|
20
20
|
|
21
|
-
def init ( parameters )
|
21
|
+
def init ( parameters = [] )
|
22
22
|
if File.exist?(".piedesaint")
|
23
23
|
abort "Configuration already exists at #{Dir.pwd}/.piedesaint"
|
24
24
|
end
|
@@ -39,6 +39,7 @@ module Piedesaint
|
|
39
39
|
cert: File.join(".", ".piedesaint", "ssl", "server.crt" ),
|
40
40
|
username: "user",
|
41
41
|
password: "password",
|
42
|
+
freshness: 3600,
|
42
43
|
folders: parameters }
|
43
44
|
|
44
45
|
open 'config', 'w' do |io| io.write config.to_yaml end
|
data/lib/piedesaint/version.rb
CHANGED
data/lib/piedesaint.rb
CHANGED
@@ -6,8 +6,11 @@ require 'puma/events'
|
|
6
6
|
require 'openssl'
|
7
7
|
|
8
8
|
require 'rack/ssl-enforcer'
|
9
|
+
require 'rack/cache'
|
10
|
+
|
9
11
|
require 'rubygems/package'
|
10
12
|
require "stringio"
|
13
|
+
require 'time'
|
11
14
|
|
12
15
|
|
13
16
|
module Piedesaint
|
@@ -15,17 +18,32 @@ module Piedesaint
|
|
15
18
|
module Rack
|
16
19
|
class DirectoryCompress < ::Rack::Directory
|
17
20
|
def list_directory
|
18
|
-
|
21
|
+
tarball = ::Piedesaint.tar(@path)
|
22
|
+
etag = Digest::MD5.base64digest tarball.string
|
23
|
+
headers = {"Cache-Control" => "public", "ETag" => etag }
|
24
|
+
|
25
|
+
return [304, headers, []] if etag == @env['HTTP_IF_NONE_MATCH']
|
26
|
+
return [200, headers, tarball]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class FileEtag < ::Rack::File
|
31
|
+
def serving(env)
|
32
|
+
etag = Digest::MD5.file(@path).base64digest
|
33
|
+
@headers['Cache-Control'] = "public"
|
34
|
+
@headers['ETag'] = etag
|
35
|
+
super
|
19
36
|
end
|
20
37
|
end
|
21
38
|
|
22
|
-
class
|
23
|
-
def initialize(
|
39
|
+
class DirectoriesTraversal
|
40
|
+
def initialize(options, app=nil)
|
24
41
|
@apps = []
|
25
|
-
|
42
|
+
@options = options.dup
|
43
|
+
@options[:folders].each do |root|
|
26
44
|
root = File.expand_path root
|
27
45
|
puts "Service root: #{root}"
|
28
|
-
@apps << Rack::DirectoryCompress.new(root, app)
|
46
|
+
@apps << Rack::DirectoryCompress.new(root, app ? app : Rack::FileEtag.new(root) )
|
29
47
|
end
|
30
48
|
end
|
31
49
|
|
@@ -61,9 +79,13 @@ module Piedesaint
|
|
61
79
|
use ::Rack::Auth::Basic, "Icecreamland" do |username, password|
|
62
80
|
( options[:username] == username ) && ( options[:password] == password )
|
63
81
|
end
|
64
|
-
|
82
|
+
use ::Rack::Deflater
|
83
|
+
use ::Rack::Cache, verbose: true,
|
84
|
+
metastore: 'file:/tmp/rack/meta',
|
85
|
+
entitystore: 'file:/tmp/rack/body',
|
86
|
+
default_ttl: options[:freshness]
|
65
87
|
map "/" do
|
66
|
-
run Rack::
|
88
|
+
run Rack::DirectoriesTraversal.new(options)
|
67
89
|
end
|
68
90
|
end
|
69
91
|
end
|
@@ -90,7 +112,7 @@ module Piedesaint
|
|
90
112
|
puma.add_ssl_listener options[:host], options[:https_port], ctx
|
91
113
|
|
92
114
|
puma.min_threads = 1
|
93
|
-
puma.max_threads =
|
115
|
+
puma.max_threads = 10
|
94
116
|
|
95
117
|
begin
|
96
118
|
Signal.trap "SIGUSR2" do
|
@@ -116,10 +138,10 @@ module Piedesaint
|
|
116
138
|
graceful_stop puma
|
117
139
|
end
|
118
140
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
141
|
+
if @restart
|
142
|
+
p "* Restarting..."
|
143
|
+
@status.stop true if @status
|
144
|
+
restart!
|
123
145
|
end
|
124
146
|
end
|
125
147
|
|
@@ -128,17 +150,9 @@ module Piedesaint
|
|
128
150
|
p " - Gracefully stopping, waiting for requests to finish"
|
129
151
|
@status.stop(true) if @status
|
130
152
|
puma.stop(true)
|
131
|
-
delete_pidfile
|
132
153
|
p " - Goodbye!"
|
133
154
|
end
|
134
155
|
|
135
|
-
def self.delete_pidfile
|
136
|
-
#�if path = @options[:pidfile]
|
137
|
-
# File.unlink path
|
138
|
-
#end
|
139
|
-
end
|
140
|
-
|
141
|
-
|
142
156
|
def self.tar(path)
|
143
157
|
tar = StringIO.new
|
144
158
|
Gem::Package::TarWriter.new(tar) do |tarwriter|
|
@@ -160,4 +174,4 @@ module Piedesaint
|
|
160
174
|
tar
|
161
175
|
end
|
162
176
|
|
163
|
-
end
|
177
|
+
end
|
data/piedesaint.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: piedesaint
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: thor
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rack-cache
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
78
94
|
description: ! 'Drop-in web server to serve files and tar''ed directories.
|
79
95
|
|
80
96
|
Use it as a tool to make available databse backups, installation packages that don''t
|
@@ -118,7 +134,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
134
|
version: '0'
|
119
135
|
segments:
|
120
136
|
- 0
|
121
|
-
hash:
|
137
|
+
hash: 2452808336996512805
|
122
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
139
|
none: false
|
124
140
|
requirements:
|
@@ -127,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
143
|
version: '0'
|
128
144
|
segments:
|
129
145
|
- 0
|
130
|
-
hash:
|
146
|
+
hash: 2452808336996512805
|
131
147
|
requirements: []
|
132
148
|
rubyforge_project:
|
133
149
|
rubygems_version: 1.8.25
|