odania 0.0.36 → 0.0.37
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/odania/config.rb +1 -0
- data/lib/odania/config/global_config.rb +23 -0
- data/lib/odania/config/page_base.rb +4 -20
- data/lib/odania/config/plugin_config.rb +4 -1
- data/lib/odania/config/subdomain_config.rb +121 -0
- data/lib/odania/plugin.rb +12 -0
- data/lib/odania/version.rb +1 -1
- data/spec/fixtures/global_config.json +9 -21
- data/spec/fixtures/plugin_config_1.json +8 -2
- data/spec/lib/odania/config/global_config_spec.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 34635dadd6875c21d30dc12b8611e92cdcfc69dc
|
4
|
+
data.tar.gz: 985d41d81e514e86895acc024692c987611d0264
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de518f1f33f55d597c05c53d4b37418afe543354e16be1b4b9c88a304ed05b53768002741dd577e0d134c60ea07b8af94e58c00ecb2d0421a2633c355856f4ed
|
7
|
+
data.tar.gz: c4be69142d66458b3e8b5fbb19455a1a1fb85f82d3a2ff3893f0923ea513f654723bae5048de3deec043c39e3c10021bddc7f13e8a3917782deacb343e750e55
|
data/Gemfile.lock
CHANGED
data/lib/odania/config.rb
CHANGED
@@ -9,6 +9,7 @@ module Odania
|
|
9
9
|
@default_backend_groups = config['default_backend_groups'] unless config['default_backend_groups'].nil?
|
10
10
|
@valid_domains = config['valid_domains'] unless config['valid_domains'].nil?
|
11
11
|
@default_domains = config['default_domains'] unless config['default_domains'].nil?
|
12
|
+
@partials = config['partials'] unless config['partials'].nil?
|
12
13
|
|
13
14
|
unless config['domains'].nil?
|
14
15
|
config['domains'].each_pair do |name, data|
|
@@ -68,9 +69,24 @@ module Odania
|
|
68
69
|
config = self.dump
|
69
70
|
puts JSON.pretty_generate config if $debug
|
70
71
|
Odania.plugin.set_global_config config
|
72
|
+
|
73
|
+
generate_subdomain_configs config
|
74
|
+
|
71
75
|
config
|
72
76
|
end
|
73
77
|
|
78
|
+
# Generate a config per subdomain
|
79
|
+
def generate_subdomain_configs(config)
|
80
|
+
$logger.info 'Generating subdomain configs'
|
81
|
+
@valid_domains.each do |domain, subdomains|
|
82
|
+
subdomains.each do |subdomain|
|
83
|
+
$logger.info "Generating Subdomain Config for Domain: #{domain} Subdomain: #{subdomain}"
|
84
|
+
subdomain_config = SubdomainConfig.new(config, domain, subdomain).generate
|
85
|
+
Odania.plugin.set_subdomain_config "#{subdomain}.#{domain}", subdomain_config
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
74
90
|
# Add the configuration from the plugin
|
75
91
|
def add_plugin_config(plugin_cfg)
|
76
92
|
config_section = plugin_cfg['config']
|
@@ -84,6 +100,7 @@ module Odania
|
|
84
100
|
@plugin_config[group_name] = plugin_cfg['plugin-config']
|
85
101
|
@valid_domains.deep_merge!(plugin_cfg['valid_domains']) unless plugin_cfg['valid_domains'].nil?
|
86
102
|
@default_domains.deep_merge!(plugin_cfg['default_domains']) unless plugin_cfg['default_domains'].nil?
|
103
|
+
@partials.deep_merge!(plugin_cfg['partials']) unless plugin_cfg['partials'].nil?
|
87
104
|
|
88
105
|
# Add this service as a default backend if specified
|
89
106
|
@default_backend_groups << group_name if plugin_cfg['plugin-config']['default']
|
@@ -126,6 +143,7 @@ module Odania
|
|
126
143
|
@backend_groups = Hash.new { |hash, key| hash[key] = BackendGroup.new(key) }
|
127
144
|
@valid_domains = {}
|
128
145
|
@default_domains = {}
|
146
|
+
@partials = {}
|
129
147
|
|
130
148
|
@domains['_general'].add_subdomain('_general')
|
131
149
|
end
|
@@ -153,6 +171,10 @@ module Odania
|
|
153
171
|
@default_domains
|
154
172
|
end
|
155
173
|
|
174
|
+
def partials
|
175
|
+
@partials
|
176
|
+
end
|
177
|
+
|
156
178
|
def default_redirects
|
157
179
|
general = @domains['_general'].subdomain('_general')
|
158
180
|
return {} if general.nil?
|
@@ -164,6 +186,7 @@ module Odania
|
|
164
186
|
cfg['default_backend_groups'] = @default_backend_groups
|
165
187
|
cfg['default_domains'] = @default_domains
|
166
188
|
cfg['valid_domains'] = @valid_domains
|
189
|
+
cfg['partials'] = @partials
|
167
190
|
cfg
|
168
191
|
end
|
169
192
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Odania
|
2
2
|
module Config
|
3
3
|
class PageBase
|
4
|
-
attr_accessor :assets
|
4
|
+
attr_accessor :assets
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
reset
|
@@ -15,13 +15,6 @@ module Odania
|
|
15
15
|
self.assets[name].load(asset_data, group_name)
|
16
16
|
end
|
17
17
|
end
|
18
|
-
|
19
|
-
unless data['partials'].nil?
|
20
|
-
data['partials'].each_pair do |name, partial_data|
|
21
|
-
duplicates[:partials] << name if self.partials.key? name
|
22
|
-
self.partials[name].load(partial_data, group_name)
|
23
|
-
end
|
24
|
-
end
|
25
18
|
duplicates
|
26
19
|
end
|
27
20
|
|
@@ -31,15 +24,12 @@ module Odania
|
|
31
24
|
|
32
25
|
def reset
|
33
26
|
self.assets = Hash.new { |hash, key| hash[key] = Page.new }
|
34
|
-
self.partials = Hash.new { |hash, key| hash[key] = Page.new }
|
35
27
|
|
36
|
-
@plugins = {:
|
28
|
+
@plugins = {:assets => Hash.new { |hash, key| hash[key] = [] }}
|
37
29
|
end
|
38
30
|
|
39
31
|
def [](type)
|
40
|
-
|
41
|
-
return self.assets if :assets.eql? type
|
42
|
-
self.partials
|
32
|
+
self.assets
|
43
33
|
end
|
44
34
|
|
45
35
|
def dump
|
@@ -48,14 +38,8 @@ module Odania
|
|
48
38
|
asset_data[web_url] = page.dump
|
49
39
|
end
|
50
40
|
|
51
|
-
partial_data = {}
|
52
|
-
partials.each_pair do |web_url, page|
|
53
|
-
partial_data[web_url] = page.dump
|
54
|
-
end
|
55
|
-
|
56
41
|
{
|
57
|
-
'assets' => asset_data
|
58
|
-
'partials' => partial_data
|
42
|
+
'assets' => asset_data
|
59
43
|
}
|
60
44
|
end
|
61
45
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Odania
|
2
2
|
module Config
|
3
3
|
class PluginConfig
|
4
|
-
attr_accessor :domains, :config, :valid_domains, :default_domains, :plugin_config
|
4
|
+
attr_accessor :domains, :config, :valid_domains, :default_domains, :plugin_config, :partials
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
reset
|
@@ -14,6 +14,7 @@ module Odania
|
|
14
14
|
@plugin_config = data['plugin-config'] unless data['plugin-config'].nil?
|
15
15
|
@valid_domains = data['valid_domains'] unless data['valid_domains'].nil?
|
16
16
|
@default_domains = data['default_domains'] unless data['default_domains'].nil?
|
17
|
+
@partials = data['partials'] unless data['partials'].nil?
|
17
18
|
unless data['domains'].nil?
|
18
19
|
data['domains'].each_pair do |name, domain_data|
|
19
20
|
@domains[name].load(domain_data)
|
@@ -33,6 +34,7 @@ module Odania
|
|
33
34
|
@plugin_config = {}
|
34
35
|
@default_domains = {}
|
35
36
|
@valid_domains = {}
|
37
|
+
@partials = {}
|
36
38
|
@domains = Hash.new { |hash, key| hash[key] = Domain.new(key) }
|
37
39
|
end
|
38
40
|
|
@@ -47,6 +49,7 @@ module Odania
|
|
47
49
|
'config' => config,
|
48
50
|
'default_domains' => @default_domains,
|
49
51
|
'valid_domains' => @valid_domains,
|
52
|
+
'partials' => @partials,
|
50
53
|
'domains' => domain_data
|
51
54
|
}
|
52
55
|
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
module Odania
|
2
|
+
module Config
|
3
|
+
class SubdomainConfig
|
4
|
+
|
5
|
+
def initialize(global_config, domain, subdomain)
|
6
|
+
@global_config = global_config
|
7
|
+
@domain = domain
|
8
|
+
@subdomain = subdomain
|
9
|
+
end
|
10
|
+
|
11
|
+
def generate
|
12
|
+
@layout = get_layout_name
|
13
|
+
config = {
|
14
|
+
layout: @layout,
|
15
|
+
config: generate_merged_config,
|
16
|
+
partials: generate_merged_partials
|
17
|
+
}
|
18
|
+
|
19
|
+
layout_config = get_layout_config @layout
|
20
|
+
layout_config.delete('assets')
|
21
|
+
config[:styles] = layout_config['config']['styles']
|
22
|
+
|
23
|
+
if $debug
|
24
|
+
$logger.debug 'Generated config:'
|
25
|
+
$logger.debug JSON.pretty_generate(config)
|
26
|
+
end
|
27
|
+
|
28
|
+
config
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def get_layout_name
|
34
|
+
# subdomain specific layouts
|
35
|
+
result = retrieve_hash_path @global_config, ['domains', @domain, @subdomain, 'config', 'layout']
|
36
|
+
return result unless result.nil?
|
37
|
+
|
38
|
+
# domain specific layouts
|
39
|
+
result = retrieve_hash_path @global_config, ['domains', @domain, '_general', 'config', 'layout']
|
40
|
+
return result unless result.nil?
|
41
|
+
|
42
|
+
# general layouts
|
43
|
+
result = retrieve_hash_path @global_config, %w(domains _general _general config layout)
|
44
|
+
return result unless result.nil?
|
45
|
+
|
46
|
+
# general layouts
|
47
|
+
result = retrieve_hash_path @global_config, %w(config layout)
|
48
|
+
return result unless result.nil?
|
49
|
+
|
50
|
+
'simple'
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_layout_config(layout)
|
54
|
+
# subdomain specific layouts
|
55
|
+
result = retrieve_hash_path @global_config, ['domains', @domain, @subdomain, 'layouts', layout]
|
56
|
+
return result unless result.nil?
|
57
|
+
|
58
|
+
# domain specific layouts
|
59
|
+
result = retrieve_hash_path @global_config, ['domains', @domain, '_general', 'layouts', layout]
|
60
|
+
return result unless result.nil?
|
61
|
+
|
62
|
+
# general layouts
|
63
|
+
result = retrieve_hash_path @global_config, ['domains', '_general', '_general', 'layouts', layout]
|
64
|
+
return result unless result.nil?
|
65
|
+
|
66
|
+
{}
|
67
|
+
end
|
68
|
+
|
69
|
+
def generate_merged_config
|
70
|
+
config = retrieve_hash_path @global_config, %w(domains _general _general config)
|
71
|
+
config = {} if config.nil?
|
72
|
+
|
73
|
+
# domain specific layouts
|
74
|
+
result = retrieve_hash_path @global_config, ['domains', @domain, '_general', 'config']
|
75
|
+
config.deep_merge!(result) unless result.nil?
|
76
|
+
|
77
|
+
# subdomain specific layouts
|
78
|
+
result = retrieve_hash_path @global_config, ['domains', @domain, @subdomain, 'config']
|
79
|
+
config.deep_merge!(result) unless result.nil?
|
80
|
+
|
81
|
+
config
|
82
|
+
end
|
83
|
+
|
84
|
+
def generate_merged_partials
|
85
|
+
partials = retrieve_hash_path @global_config, %w(partials _general _general default)
|
86
|
+
partials = {} if partials.nil?
|
87
|
+
|
88
|
+
# general specific layout
|
89
|
+
result = retrieve_hash_path @global_config, ['partials', '_general', '_general', 'layouts', @layout]
|
90
|
+
partials.deep_merge!(result) unless result.nil?
|
91
|
+
|
92
|
+
# domain specific
|
93
|
+
result = retrieve_hash_path @global_config, ['partials', @domain, '_general', 'default']
|
94
|
+
partials.deep_merge!(result) unless result.nil?
|
95
|
+
|
96
|
+
# domain specific layout
|
97
|
+
result = retrieve_hash_path @global_config, ['partials', @domain, '_general', 'layouts', @layout]
|
98
|
+
partials.deep_merge!(result) unless result.nil?
|
99
|
+
|
100
|
+
# subdomain
|
101
|
+
result = retrieve_hash_path @global_config, ['partials', @domain, @subdomain, 'default']
|
102
|
+
partials.deep_merge!(result) unless result.nil?
|
103
|
+
|
104
|
+
# subdomain specific layout
|
105
|
+
result = retrieve_hash_path @global_config, ['partials', @domain, @subdomain, 'layouts', @layout]
|
106
|
+
partials.deep_merge!(result) unless result.nil?
|
107
|
+
|
108
|
+
partials
|
109
|
+
end
|
110
|
+
|
111
|
+
def retrieve_hash_path(hash, path)
|
112
|
+
key = path.shift
|
113
|
+
|
114
|
+
return nil until hash.has_key? key
|
115
|
+
return hash[key] if path.empty?
|
116
|
+
retrieve_hash_path hash[key], path
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/lib/odania/plugin.rb
CHANGED
@@ -51,6 +51,14 @@ module Odania
|
|
51
51
|
@consul.config.get get_global_plugin_config_path
|
52
52
|
end
|
53
53
|
|
54
|
+
def set_subdomain_config(full_domain, config)
|
55
|
+
@consul.config.set get_subdomain_config_path(full_domain), config
|
56
|
+
end
|
57
|
+
|
58
|
+
def get_subdomain_config(full_domain)
|
59
|
+
@consul.config.get get_subdomain_config_path(full_domain)
|
60
|
+
end
|
61
|
+
|
54
62
|
def get_domain_config_for(domain, global_config=nil)
|
55
63
|
global_config = get_global_config if global_config.nil?
|
56
64
|
|
@@ -64,6 +72,10 @@ module Odania
|
|
64
72
|
|
65
73
|
private
|
66
74
|
|
75
|
+
def get_subdomain_config_path(full_domain)
|
76
|
+
"subdomain_config/#{full_domain}"
|
77
|
+
end
|
78
|
+
|
67
79
|
def get_global_plugin_config_path
|
68
80
|
'global_plugins_config'
|
69
81
|
end
|
data/lib/odania/version.rb
CHANGED
@@ -40,15 +40,10 @@
|
|
40
40
|
"assets": {
|
41
41
|
},
|
42
42
|
"layouts": {
|
43
|
-
},
|
44
|
-
"partials": {
|
45
43
|
}
|
46
44
|
}
|
47
45
|
},
|
48
46
|
"example.com": {
|
49
|
-
"_general": {
|
50
|
-
"config": {}
|
51
|
-
},
|
52
47
|
"_general": {
|
53
48
|
"config": {
|
54
49
|
},
|
@@ -59,8 +54,7 @@
|
|
59
54
|
}
|
60
55
|
},
|
61
56
|
"assets": {},
|
62
|
-
"layouts": {}
|
63
|
-
"partials": {}
|
57
|
+
"layouts": {}
|
64
58
|
},
|
65
59
|
"www": {
|
66
60
|
"dynamic": {
|
@@ -126,22 +120,16 @@
|
|
126
120
|
}
|
127
121
|
}
|
128
122
|
}
|
129
|
-
},
|
130
|
-
"partials": {
|
131
|
-
"footer": {
|
132
|
-
"name": "footer",
|
133
|
-
"group_name": "static-content",
|
134
|
-
"plugin_url": "partials/footer.html",
|
135
|
-
"cacheable": true,
|
136
|
-
"expires": 60
|
137
|
-
},
|
138
|
-
"tracking": {
|
139
|
-
"name": "tracking",
|
140
|
-
"group_name": "static-content",
|
141
|
-
"plugin_url": "partials/tracking.html"
|
142
|
-
}
|
143
123
|
}
|
144
124
|
}
|
145
125
|
}
|
126
|
+
},
|
127
|
+
"partials": {
|
128
|
+
"example.com": {
|
129
|
+
"www": {
|
130
|
+
"tracking": "partials/tracking.html",
|
131
|
+
"footer": "partials/footer.html"
|
132
|
+
}
|
133
|
+
}
|
146
134
|
}
|
147
135
|
}
|
@@ -31,7 +31,7 @@ describe Odania::Config::GlobalConfig do
|
|
31
31
|
duplicates = subject.duplicates
|
32
32
|
expect(subject.duplicates).not_to be_empty
|
33
33
|
expect(duplicates).to have_key(:config)
|
34
|
-
expect(duplicates).to have_key(:
|
34
|
+
expect(duplicates).to have_key(:assets)
|
35
35
|
expect(duplicates).to have_key(:redirect)
|
36
36
|
end
|
37
37
|
|
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.37
|
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-06-
|
11
|
+
date: 2016-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -212,6 +212,7 @@ files:
|
|
212
212
|
- lib/odania/config/plugin_config.rb
|
213
213
|
- lib/odania/config/style.rb
|
214
214
|
- lib/odania/config/sub_domain.rb
|
215
|
+
- lib/odania/config/subdomain_config.rb
|
215
216
|
- lib/odania/consul.rb
|
216
217
|
- lib/odania/plugin.rb
|
217
218
|
- lib/odania/version.rb
|