odania 0.0.32 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +17 -13
- data/lib/odania/config/layout.rb +9 -19
- data/lib/odania/config/page_base.rb +22 -22
- data/lib/odania/config/style.rb +2 -15
- data/lib/odania/config/sub_domain.rb +27 -19
- data/lib/odania/config.rb +1 -2
- data/lib/odania/consul.rb +10 -0
- data/lib/odania/version.rb +1 -1
- data/lib/odania.rb +0 -6
- data/odania.gemspec +1 -0
- data/spec/fixtures/global_config.json +48 -69
- data/spec/fixtures/plugin_config_1.json +35 -41
- data/spec/lib/odania/config/global_config_spec.rb +5 -3
- data/spec/lib/odania/config/plugin_config_spec.rb +4 -1
- data/spec/spec_helper.rb +1 -0
- metadata +16 -32
- data/config/varnish_config.json +0 -7
- data/features/step_definitions/varnish_steps.rb +0 -7
- data/features/varnish.feature +0 -8
- data/lib/odania/config/internal.rb +0 -58
- data/lib/odania/varnish/generators/generate_backend_vcl.rb +0 -48
- data/lib/odania/varnish/generators/generate_catch_all_vcl.rb +0 -17
- data/lib/odania/varnish/generators/generate_default_vcl.rb +0 -17
- data/lib/odania/varnish/generators/generate_final_vcl.rb +0 -17
- data/lib/odania/varnish/generators/generate_general_vcl.rb +0 -17
- data/lib/odania/varnish/generators/generate_redirects_vcl.rb +0 -18
- data/lib/odania/varnish/generators/generate_site_assets_vcl.rb +0 -14
- data/lib/odania/varnish/generators/generate_site_vcl.rb +0 -41
- data/lib/odania/varnish/generators/generate_sites_vcl.rb +0 -31
- data/lib/odania/varnish.rb +0 -92
- data/spec/lib/odania/varnish_spec.rb +0 -37
- data/templates/varnish/backend.vcl.erb +0 -51
- data/templates/varnish/catch_all.vcl.erb +0 -5
- data/templates/varnish/default.vcl.erb +0 -18
- data/templates/varnish/final.vcl.erb +0 -11
- data/templates/varnish/general.vcl.erb +0 -118
- data/templates/varnish/general_site.vcl.erb +0 -33
- data/templates/varnish/general_site_assets.vcl.erb +0 -21
- data/templates/varnish/redirects.vcl.erb +0 -12
- data/templates/varnish/site.vcl.erb +0 -93
- data/templates/varnish/site_assets.vcl.erb +0 -47
- data/templates/varnish/sites.vcl.erb +0 -11
- data/templates/varnish/websocker.vcl.erb +0 -18
@@ -21,49 +21,45 @@
|
|
21
21
|
"_general": {
|
22
22
|
"redirects": {},
|
23
23
|
"config": {},
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"
|
24
|
+
"web": {},
|
25
|
+
"assets": {},
|
26
|
+
"layouts": {
|
27
|
+
"main": {
|
28
|
+
"config": {
|
29
29
|
"styles": {
|
30
30
|
"_general": {
|
31
|
-
"entry_point": "application.html.erb"
|
32
|
-
"direct": {
|
33
|
-
"layouts/mac-beath/img/favicon/favicon.png": {
|
34
|
-
"plugin_url": "layouts/mac-beath/img/favicon/favicon.png",
|
35
|
-
"cacheable": true,
|
36
|
-
"expires": 60
|
37
|
-
},
|
38
|
-
"layouts/mac-beath/img/photos/t12.jpg": {
|
39
|
-
"plugin_url": "layouts/mac-beath/img/photos/t12.jpg"
|
40
|
-
}
|
41
|
-
},
|
42
|
-
"dynamic": {
|
43
|
-
"layouts/simple/application_part1.html": {
|
44
|
-
"plugin_url": "layouts/simple/application_part1.html.erb",
|
45
|
-
"cacheable": true,
|
46
|
-
"expires": 60
|
47
|
-
}
|
48
|
-
},
|
49
|
-
"assets": {}
|
31
|
+
"entry_point": "application.html.erb"
|
50
32
|
},
|
51
33
|
"left_menu": {
|
52
|
-
"entry_point": "application.html.erb"
|
53
|
-
"direct": {},
|
54
|
-
"dynamic": {},
|
55
|
-
"assets": {}
|
34
|
+
"entry_point": "application.html.erb"
|
56
35
|
}
|
57
36
|
}
|
58
|
-
}
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
37
|
+
},
|
38
|
+
"assets": {
|
39
|
+
"layouts/mac-beath/img/favicon/favicon.png": {
|
40
|
+
"plugin_url": "layouts/mac-beath/img/favicon/favicon.png",
|
41
|
+
"cacheable": true,
|
42
|
+
"expires": 60
|
43
|
+
},
|
44
|
+
"layouts/mac-beath/img/photos/t12.jpg": {
|
45
|
+
"plugin_url": "layouts/mac-beath/img/photos/t12.jpg"
|
46
|
+
}
|
47
|
+
},
|
48
|
+
"partials": {
|
49
|
+
"layouts/simple/application_part1.html": {
|
50
|
+
"plugin_url": "layouts/simple/application_part1.html.erb",
|
51
|
+
"cacheable": true,
|
52
|
+
"expires": 60
|
53
|
+
}
|
65
54
|
}
|
66
55
|
}
|
56
|
+
},
|
57
|
+
"partials": {
|
58
|
+
"footer": {
|
59
|
+
"plugin_url": "partials/footer.html",
|
60
|
+
"cacheable": true,
|
61
|
+
"expires": 60
|
62
|
+
}
|
67
63
|
}
|
68
64
|
}
|
69
65
|
},
|
@@ -73,7 +69,7 @@
|
|
73
69
|
"^/test": "/test2"
|
74
70
|
},
|
75
71
|
"config": {},
|
76
|
-
"
|
72
|
+
"web": {
|
77
73
|
"/imprint": {
|
78
74
|
"plugin_url": "/my-imprint",
|
79
75
|
"cacheable": true,
|
@@ -84,11 +80,9 @@
|
|
84
80
|
"cacheable": false
|
85
81
|
}
|
86
82
|
},
|
87
|
-
"
|
88
|
-
"
|
89
|
-
|
90
|
-
"partials": {}
|
91
|
-
}
|
83
|
+
"assets": {},
|
84
|
+
"layouts": {},
|
85
|
+
"partials": {}
|
92
86
|
}
|
93
87
|
}
|
94
88
|
}
|
@@ -14,9 +14,11 @@ describe Odania::Config::GlobalConfig do
|
|
14
14
|
expect(cfg_result['domains']['example.com']['www']['redirects']).to eql(cfg1['domains']['example.com']['www']['redirects'])
|
15
15
|
expect(cfg_result['domains']['example.com']['www']['config']).to eql(cfg1['domains']['example.com']['www']['config'])
|
16
16
|
|
17
|
-
|
17
|
+
%w(web assets partials).each do |type|
|
18
|
+
cfg1['domains']['example.com']['www'][type].each_pair do |path, data|
|
18
19
|
|
19
|
-
|
20
|
+
expect(cfg_result['domains']['example.com']['www'][type][path]['plugin_url']).to eql(data['plugin_url'])
|
21
|
+
end
|
20
22
|
end
|
21
23
|
|
22
24
|
end
|
@@ -29,7 +31,7 @@ describe Odania::Config::GlobalConfig do
|
|
29
31
|
duplicates = subject.duplicates
|
30
32
|
expect(subject.duplicates).not_to be_empty
|
31
33
|
expect(duplicates).to have_key(:config)
|
32
|
-
expect(duplicates).to have_key(:
|
34
|
+
expect(duplicates).to have_key(:partials)
|
33
35
|
expect(duplicates).to have_key(:redirect)
|
34
36
|
end
|
35
37
|
|
@@ -22,7 +22,10 @@ describe Odania::Config::PluginConfig do
|
|
22
22
|
|
23
23
|
it 'dumps the same config' do
|
24
24
|
expect(subject.load(cfg)).to be(true)
|
25
|
-
|
25
|
+
result = subject.dump
|
26
|
+
diff = HashDiff.best_diff result, cfg
|
27
|
+
puts "Best diff: #{diff.inspect}"
|
28
|
+
expect(result).to eql(cfg)
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: odania
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.33
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Petersen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: hashdiff
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: diplomat
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,12 +196,9 @@ files:
|
|
182
196
|
- LICENSE.txt
|
183
197
|
- README.md
|
184
198
|
- Rakefile
|
185
|
-
- config/varnish_config.json
|
186
199
|
- features/plugin.feature
|
187
200
|
- features/step_definitions/plugin_steps.rb
|
188
|
-
- features/step_definitions/varnish_steps.rb
|
189
201
|
- features/support/env.rb
|
190
|
-
- features/varnish.feature
|
191
202
|
- lib/odania.rb
|
192
203
|
- lib/odania/config.rb
|
193
204
|
- lib/odania/config/backend.rb
|
@@ -195,7 +206,6 @@ files:
|
|
195
206
|
- lib/odania/config/domain.rb
|
196
207
|
- lib/odania/config/duplicates.rb
|
197
208
|
- lib/odania/config/global_config.rb
|
198
|
-
- lib/odania/config/internal.rb
|
199
209
|
- lib/odania/config/layout.rb
|
200
210
|
- lib/odania/config/page.rb
|
201
211
|
- lib/odania/config/page_base.rb
|
@@ -204,16 +214,6 @@ files:
|
|
204
214
|
- lib/odania/config/sub_domain.rb
|
205
215
|
- lib/odania/consul.rb
|
206
216
|
- lib/odania/plugin.rb
|
207
|
-
- lib/odania/varnish.rb
|
208
|
-
- lib/odania/varnish/generators/generate_backend_vcl.rb
|
209
|
-
- lib/odania/varnish/generators/generate_catch_all_vcl.rb
|
210
|
-
- lib/odania/varnish/generators/generate_default_vcl.rb
|
211
|
-
- lib/odania/varnish/generators/generate_final_vcl.rb
|
212
|
-
- lib/odania/varnish/generators/generate_general_vcl.rb
|
213
|
-
- lib/odania/varnish/generators/generate_redirects_vcl.rb
|
214
|
-
- lib/odania/varnish/generators/generate_site_assets_vcl.rb
|
215
|
-
- lib/odania/varnish/generators/generate_site_vcl.rb
|
216
|
-
- lib/odania/varnish/generators/generate_sites_vcl.rb
|
217
217
|
- lib/odania/version.rb
|
218
218
|
- odania.gemspec
|
219
219
|
- spec/fixtures/global_config.json
|
@@ -221,24 +221,11 @@ files:
|
|
221
221
|
- spec/lib/odania/config/global_config_spec.rb
|
222
222
|
- spec/lib/odania/config/plugin_config_spec.rb
|
223
223
|
- spec/lib/odania/plugin_spec.rb
|
224
|
-
- spec/lib/odania/varnish_spec.rb
|
225
224
|
- spec/lib/odania_spec.rb
|
226
225
|
- spec/spec_helper.rb
|
227
226
|
- spec/support/consul_mock.rb
|
228
227
|
- tasks/odania.rake
|
229
228
|
- tasks/rspec.rake
|
230
|
-
- templates/varnish/backend.vcl.erb
|
231
|
-
- templates/varnish/catch_all.vcl.erb
|
232
|
-
- templates/varnish/default.vcl.erb
|
233
|
-
- templates/varnish/final.vcl.erb
|
234
|
-
- templates/varnish/general.vcl.erb
|
235
|
-
- templates/varnish/general_site.vcl.erb
|
236
|
-
- templates/varnish/general_site_assets.vcl.erb
|
237
|
-
- templates/varnish/redirects.vcl.erb
|
238
|
-
- templates/varnish/site.vcl.erb
|
239
|
-
- templates/varnish/site_assets.vcl.erb
|
240
|
-
- templates/varnish/sites.vcl.erb
|
241
|
-
- templates/varnish/websocker.vcl.erb
|
242
229
|
homepage: http://www.odania.com
|
243
230
|
licenses:
|
244
231
|
- MIT
|
@@ -266,15 +253,12 @@ summary: Helper for the odania portal
|
|
266
253
|
test_files:
|
267
254
|
- features/plugin.feature
|
268
255
|
- features/step_definitions/plugin_steps.rb
|
269
|
-
- features/step_definitions/varnish_steps.rb
|
270
256
|
- features/support/env.rb
|
271
|
-
- features/varnish.feature
|
272
257
|
- spec/fixtures/global_config.json
|
273
258
|
- spec/fixtures/plugin_config_1.json
|
274
259
|
- spec/lib/odania/config/global_config_spec.rb
|
275
260
|
- spec/lib/odania/config/plugin_config_spec.rb
|
276
261
|
- spec/lib/odania/plugin_spec.rb
|
277
|
-
- spec/lib/odania/varnish_spec.rb
|
278
262
|
- spec/lib/odania_spec.rb
|
279
263
|
- spec/spec_helper.rb
|
280
264
|
- spec/support/consul_mock.rb
|
data/config/varnish_config.json
DELETED
data/features/varnish.feature
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
Feature: Varnish
|
2
|
-
Configuration for varnish. It is the gateway from the web to the plugin infrastructure.
|
3
|
-
|
4
|
-
Scenario: Generate config
|
5
|
-
Given I initialize the gem
|
6
|
-
When I registered the plugin "test-plugin"
|
7
|
-
And I generate the varnish config
|
8
|
-
Then I have a valid varnish config
|
@@ -1,58 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
module Config
|
3
|
-
class Internal
|
4
|
-
attr_accessor :partials, :layouts
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
reset
|
8
|
-
end
|
9
|
-
|
10
|
-
def assets
|
11
|
-
result = {}
|
12
|
-
self.layouts.each_pair do |_name, layout|
|
13
|
-
layout.assets.each_pair do |key, val|
|
14
|
-
result[key] = val
|
15
|
-
end
|
16
|
-
end
|
17
|
-
result
|
18
|
-
end
|
19
|
-
|
20
|
-
def load(data, group_name)
|
21
|
-
reset
|
22
|
-
unless data['partials'].nil?
|
23
|
-
data['partials'].each_pair do |name, partial_data|
|
24
|
-
self.partials[name].load(partial_data)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
unless data['layouts'].nil?
|
29
|
-
data['layouts'].each_pair do |name, layout_data|
|
30
|
-
self.layouts[name].load(layout_data, group_name)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def dump
|
36
|
-
partial_data = {}
|
37
|
-
partials.each_pair do |web_url, page|
|
38
|
-
partial_data[web_url] = page.dump
|
39
|
-
end
|
40
|
-
|
41
|
-
layout_data = {}
|
42
|
-
layouts.each_pair do |web_url, page|
|
43
|
-
layout_data[web_url] = page.dump
|
44
|
-
end
|
45
|
-
|
46
|
-
{
|
47
|
-
'layouts' => layout_data,
|
48
|
-
'partials' => partial_data
|
49
|
-
}
|
50
|
-
end
|
51
|
-
|
52
|
-
def reset
|
53
|
-
self.layouts = Hash.new { |hash, key| hash[key] = Layout.new }
|
54
|
-
self.partials = Hash.new { |hash, key| hash[key] = Page.new }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
class GenerateBackendVcl
|
3
|
-
attr_accessor :default_backend, :backend_groups, :template
|
4
|
-
|
5
|
-
def initialize(default_backend, backend_groups)
|
6
|
-
self.default_backend = default_backend
|
7
|
-
self.backend_groups = backend_groups
|
8
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/backend.vcl.erb").read
|
9
|
-
|
10
|
-
@backend_names = []
|
11
|
-
end
|
12
|
-
|
13
|
-
def core_backends
|
14
|
-
core_backends = []
|
15
|
-
self.backend_groups.each_pair do |group_name, backend_group|
|
16
|
-
if backend_group.core_backend
|
17
|
-
backend_group.backends.each do |backend|
|
18
|
-
core_backends << "#{Odania.varnish_sanitize(group_name)}_#{Odania.varnish_sanitize(backend.instance_name)}"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
core_backends
|
23
|
-
end
|
24
|
-
|
25
|
-
def backend_name_for(group_name, instance_name)
|
26
|
-
backend_name = "#{Odania.varnish_sanitize(group_name)}_#{Odania.varnish_sanitize(instance_name)}"
|
27
|
-
@backend_names << backend_name
|
28
|
-
backend_name
|
29
|
-
end
|
30
|
-
|
31
|
-
def backend_name_already_taken(group_name, instance_name)
|
32
|
-
backend_name = "#{Odania.varnish_sanitize(group_name)}_#{Odania.varnish_sanitize(instance_name)}"
|
33
|
-
if @backend_names.include? backend_name
|
34
|
-
$logger.error "The Backend #{backend_name} is already defined!"
|
35
|
-
return true
|
36
|
-
end
|
37
|
-
false
|
38
|
-
end
|
39
|
-
|
40
|
-
def render
|
41
|
-
Erubis::Eruby.new(self.template).result(binding)
|
42
|
-
end
|
43
|
-
|
44
|
-
def write(out_dir)
|
45
|
-
File.write("#{out_dir}/backend.vcl", self.render)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
class GenerateCatchAllVcl
|
3
|
-
attr_accessor :template
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/catch_all.vcl.erb").read
|
7
|
-
end
|
8
|
-
|
9
|
-
def render
|
10
|
-
Erubis::Eruby.new(self.template).result(binding)
|
11
|
-
end
|
12
|
-
|
13
|
-
def write(out_dir)
|
14
|
-
File.write("#{out_dir}/catch_all.vcl", self.render)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
class GenerateDefaultVcl
|
3
|
-
attr_accessor :template
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/default.vcl.erb").read
|
7
|
-
end
|
8
|
-
|
9
|
-
def render
|
10
|
-
Erubis::Eruby.new(self.template).result(binding)
|
11
|
-
end
|
12
|
-
|
13
|
-
def write(out_dir)
|
14
|
-
File.write("#{out_dir}/default.vcl", self.render)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
class GenerateFinalVcl
|
3
|
-
attr_accessor :template
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/final.vcl.erb").read
|
7
|
-
end
|
8
|
-
|
9
|
-
def render
|
10
|
-
Erubis::Eruby.new(self.template).result(binding)
|
11
|
-
end
|
12
|
-
|
13
|
-
def write(out_dir)
|
14
|
-
File.write("#{out_dir}/final.vcl", self.render)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
class GenerateGeneralVcl
|
3
|
-
attr_accessor :template
|
4
|
-
|
5
|
-
def initialize
|
6
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/general.vcl.erb").read
|
7
|
-
end
|
8
|
-
|
9
|
-
def render
|
10
|
-
Erubis::Eruby.new(self.template).result(binding)
|
11
|
-
end
|
12
|
-
|
13
|
-
def write(out_dir)
|
14
|
-
File.write("#{out_dir}/general.vcl", self.render)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
class GenerateRedirectsVcl
|
3
|
-
attr_accessor :redirects, :template
|
4
|
-
|
5
|
-
def initialize(redirects)
|
6
|
-
self.redirects = redirects
|
7
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/redirects.vcl.erb").read
|
8
|
-
end
|
9
|
-
|
10
|
-
def render
|
11
|
-
Erubis::Eruby.new(self.template).result(binding)
|
12
|
-
end
|
13
|
-
|
14
|
-
def write(out_dir)
|
15
|
-
File.write("#{out_dir}/redirects.vcl", self.render)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
class GenerateSiteAssetsVcl < GenerateSiteVcl
|
3
|
-
|
4
|
-
def initialize(domain, default_subdomains)
|
5
|
-
super(domain, default_subdomains)
|
6
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/site_assets.vcl.erb").read
|
7
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/general_site_assets.vcl.erb").read if '_general'.eql? domain.name
|
8
|
-
end
|
9
|
-
|
10
|
-
def write(out_dir)
|
11
|
-
File.write("#{out_dir}/sites/#{self.domain.name}_assets.vcl", self.render)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Odania
|
2
|
-
class GenerateSiteVcl
|
3
|
-
attr_accessor :domain, :template, :default_subdomains
|
4
|
-
|
5
|
-
def default_subdomain_for(domain)
|
6
|
-
return self.default_subdomains[domain.name] unless self.default_subdomains[domain.name].nil?
|
7
|
-
return self.default_subdomains['_general'] unless self.default_subdomains['_general'].nil?
|
8
|
-
'www'
|
9
|
-
end
|
10
|
-
|
11
|
-
def template_url_for(domain, page)
|
12
|
-
"&domain=#{domain.name}"+
|
13
|
-
"&plugin_url=#{page.plugin_url.nil? ? '/' : page.plugin_url}"+
|
14
|
-
"&group_name=#{Odania.varnish_sanitize(page.group_name)}"
|
15
|
-
end
|
16
|
-
|
17
|
-
def prepare_url(url)
|
18
|
-
return "/#{url}" unless '/'.eql? url[0]
|
19
|
-
url
|
20
|
-
end
|
21
|
-
|
22
|
-
def general_subdomain
|
23
|
-
self.domain['_general']
|
24
|
-
end
|
25
|
-
|
26
|
-
def initialize(domain, default_subdomains)
|
27
|
-
self.domain = domain
|
28
|
-
self.default_subdomains = default_subdomains
|
29
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/site.vcl.erb").read
|
30
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/general_site.vcl.erb").read if '_general'.eql? domain.name
|
31
|
-
end
|
32
|
-
|
33
|
-
def render
|
34
|
-
Erubis::Eruby.new(self.template).result(binding)
|
35
|
-
end
|
36
|
-
|
37
|
-
def write(out_dir)
|
38
|
-
File.write("#{out_dir}/sites/#{self.domain.name}.vcl", self.render)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require_relative 'generate_site_vcl'
|
2
|
-
require_relative 'generate_site_assets_vcl'
|
3
|
-
|
4
|
-
module Odania
|
5
|
-
class GenerateSitesVcl
|
6
|
-
attr_accessor :domains, :template, :default_subdomains
|
7
|
-
|
8
|
-
def initialize(domains, default_subdomains)
|
9
|
-
self.domains = domains
|
10
|
-
self.default_subdomains = default_subdomains
|
11
|
-
self.template = File.new("#{BASE_DIR}/templates/varnish/sites.vcl.erb").read
|
12
|
-
end
|
13
|
-
|
14
|
-
def render
|
15
|
-
Erubis::Eruby.new(self.template).result(binding)
|
16
|
-
end
|
17
|
-
|
18
|
-
def write(out_dir)
|
19
|
-
File.write("#{out_dir}/sites.vcl", self.render)
|
20
|
-
|
21
|
-
Dir.mkdir "#{out_dir}/sites" unless File.directory? "#{out_dir}/sites"
|
22
|
-
self.domains.each_pair do |domain_name, domain|
|
23
|
-
out = GenerateSiteVcl.new(domain, default_subdomains)
|
24
|
-
out.write out_dir
|
25
|
-
|
26
|
-
out = GenerateSiteAssetsVcl.new(domain, default_subdomains)
|
27
|
-
out.write out_dir
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
data/lib/odania/varnish.rb
DELETED
@@ -1,92 +0,0 @@
|
|
1
|
-
require_relative 'varnish/generators/generate_backend_vcl'
|
2
|
-
require_relative 'varnish/generators/generate_catch_all_vcl'
|
3
|
-
require_relative 'varnish/generators/generate_default_vcl'
|
4
|
-
require_relative 'varnish/generators/generate_final_vcl'
|
5
|
-
require_relative 'varnish/generators/generate_general_vcl'
|
6
|
-
require_relative 'varnish/generators/generate_redirects_vcl'
|
7
|
-
require_relative 'varnish/generators/generate_sites_vcl'
|
8
|
-
|
9
|
-
module Odania
|
10
|
-
class Varnish
|
11
|
-
def generate(out_dir='/etc/varnish')
|
12
|
-
FileUtils.mkdir_p out_dir unless File.directory? out_dir
|
13
|
-
global_config_json = Odania.plugin.get_global_config
|
14
|
-
global_config = Odania.plugin.plugin_config.load_global_config global_config_json
|
15
|
-
|
16
|
-
# Backend config
|
17
|
-
backend_groups = global_config.backend_groups
|
18
|
-
default_backend = global_config.default_backend
|
19
|
-
|
20
|
-
# Domain information config
|
21
|
-
domains = global_config.domains
|
22
|
-
default_subdomains = global_config.default_subdomains
|
23
|
-
|
24
|
-
# Generate catch all vcl
|
25
|
-
gen = GenerateCatchAllVcl.new
|
26
|
-
gen.write(out_dir)
|
27
|
-
|
28
|
-
# Generate catch all vcl
|
29
|
-
gen = GenerateGeneralVcl.new
|
30
|
-
gen.write(out_dir)
|
31
|
-
|
32
|
-
# Generate backend vcl
|
33
|
-
gen = GenerateBackendVcl.new(default_backend, backend_groups)
|
34
|
-
gen.write(out_dir)
|
35
|
-
|
36
|
-
# Generate vcl_recv
|
37
|
-
gen = GenerateSitesVcl.new(domains, default_subdomains)
|
38
|
-
gen.write(out_dir)
|
39
|
-
|
40
|
-
# Generate global redirects
|
41
|
-
gen = GenerateRedirectsVcl.new(global_config.default_redirects)
|
42
|
-
gen.write(out_dir)
|
43
|
-
|
44
|
-
# Generate main vcl
|
45
|
-
gen = GenerateDefaultVcl.new
|
46
|
-
gen.write(out_dir)
|
47
|
-
|
48
|
-
# Generate final vcl
|
49
|
-
gen = GenerateFinalVcl.new
|
50
|
-
gen.write(out_dir)
|
51
|
-
|
52
|
-
puts
|
53
|
-
$logger.info 'Registering internal varnish plugin'
|
54
|
-
register_plugin
|
55
|
-
end
|
56
|
-
|
57
|
-
def reload_config
|
58
|
-
$logger.info 'Updating varnish config'
|
59
|
-
current_number = 0
|
60
|
-
current_number = File.read('/tmp/current_varnish_config_number').to_i if File.exist? '/tmp/current_varnish_config_number'
|
61
|
-
current_number += 1
|
62
|
-
File.write '/tmp/current_varnish_config_number', current_number
|
63
|
-
|
64
|
-
cmd = "varnishadm vcl.load reload#{current_number} /etc/varnish/default.vcl"
|
65
|
-
$logger.info "CMD: #{cmd}"
|
66
|
-
$logger.info `#{cmd}`
|
67
|
-
cmd = "varnishadm vcl.use reload#{current_number}"
|
68
|
-
$logger.info "CMD: #{cmd}"
|
69
|
-
$logger.info `#{cmd}`
|
70
|
-
end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def register_plugin
|
75
|
-
plugin_config = JSON.parse File.read "#{BASE_DIR}/config/varnish_config.json"
|
76
|
-
|
77
|
-
ips = Odania.ips
|
78
|
-
plugin_config['plugin-config']['ips'] = ips
|
79
|
-
plugin_config['plugin-config']['ip'] = Odania.primary_ip(ips)
|
80
|
-
plugin_config['plugin-config']['port'] = 80
|
81
|
-
plugin_config['plugin-config']['tags'] = ["plugin-#{get_plugin_name}"]
|
82
|
-
puts JSON.pretty_generate plugin_config if $debug
|
83
|
-
|
84
|
-
plugin_instance_name = Odania.plugin.get_plugin_instance_name get_plugin_name
|
85
|
-
Odania.plugin.register plugin_instance_name, plugin_config
|
86
|
-
end
|
87
|
-
|
88
|
-
def get_plugin_name
|
89
|
-
'odania_varnish'
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|