odania 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSE.txt → MIT-LICENSE} +1 -3
  3. data/README.md +3 -3
  4. data/Rakefile +33 -3
  5. data/app/assets/config/odania_manifest.js +0 -0
  6. data/app/assets/javascripts/application.js +13 -0
  7. data/app/assets/javascripts/textAngular.js +15 -0
  8. data/app/assets/javascripts/textAngular/textAngular-rangy.min.js +478 -0
  9. data/app/assets/javascripts/textAngular/textAngular-sanitize.min.js +322 -0
  10. data/app/assets/javascripts/textAngular/textAngular.min.js +1481 -0
  11. data/app/assets/stylesheets/scaffold.css +80 -0
  12. data/app/assets/stylesheets/textAngular/application.css +15 -0
  13. data/app/assets/stylesheets/textAngular/textAngular.css +204 -0
  14. data/app/controllers/admin/home_controller.rb +2 -0
  15. data/app/controllers/admin/languages_controller.rb +74 -0
  16. data/app/controllers/admin_controller.rb +4 -0
  17. data/app/controllers/application_controller.rb +3 -0
  18. data/app/controllers/categories_controller.rb +34 -0
  19. data/app/controllers/home_controller.rb +11 -0
  20. data/app/controllers/protected/home_controller.rb +2 -0
  21. data/app/controllers/protected_controller.rb +22 -0
  22. data/app/controllers/registration_controller.rb +12 -0
  23. data/app/helpers/standard_form_builder.rb +71 -0
  24. data/app/helpers/standard_form_helper.rb +13 -0
  25. data/app/models/admin.rb +37 -0
  26. data/app/models/language.rb +5 -0
  27. data/app/models/user.rb +47 -0
  28. data/app/views/admin/home/index.html.erb +1 -0
  29. data/app/views/admin/languages/_form.html.erb +16 -0
  30. data/app/views/admin/languages/_language.json.jbuilder +2 -0
  31. data/app/views/admin/languages/edit.html.erb +6 -0
  32. data/app/views/admin/languages/index.html.erb +27 -0
  33. data/app/views/admin/languages/index.json.jbuilder +1 -0
  34. data/app/views/admin/languages/new.html.erb +5 -0
  35. data/app/views/admin/languages/show.html.erb +9 -0
  36. data/app/views/admin/languages/show.json.jbuilder +1 -0
  37. data/app/views/categories/index.html.erb +9 -0
  38. data/app/views/categories/show.html.erb +16 -0
  39. data/app/views/devise/confirmations/new.html.erb +11 -0
  40. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  41. data/app/views/devise/mailer/email_changed.html.erb +7 -0
  42. data/app/views/devise/mailer/password_change.html.erb +4 -0
  43. data/app/views/devise/mailer/reset_password_instructions.html.erb +9 -0
  44. data/app/views/devise/mailer/unlock_instructions.html.erb +8 -0
  45. data/app/views/devise/passwords/edit.html.erb +13 -0
  46. data/app/views/devise/passwords/new.html.erb +11 -0
  47. data/app/views/devise/registrations/edit.html.erb +39 -0
  48. data/app/views/devise/registrations/new.html.erb +15 -0
  49. data/app/views/devise/sessions/new.html.erb +14 -0
  50. data/app/views/devise/shared/_links.html.erb +25 -0
  51. data/app/views/devise/unlocks/new.html.erb +11 -0
  52. data/app/views/home/index.html.erb +11 -0
  53. data/app/views/languages/_form.html.erb +20 -0
  54. data/app/views/languages/edit.html.erb +6 -0
  55. data/app/views/languages/index.html.erb +27 -0
  56. data/app/views/languages/new.html.erb +5 -0
  57. data/app/views/languages/show.html.erb +9 -0
  58. data/app/views/protected/home/index.html.erb +1 -0
  59. data/config/initializers/elasticsearch.rb +5 -0
  60. data/config/locales/devise.en.yml +64 -0
  61. data/config/routes.rb +23 -0
  62. data/db/seeds.rb +5 -0
  63. data/lib/odania.rb +7 -56
  64. data/lib/odania/engine.rb +14 -0
  65. data/lib/odania/version.rb +1 -1
  66. data/lib/tasks/odania_tasks.rake +4 -0
  67. data/lib/templates/erb/scaffold/_form.html.erb +27 -0
  68. data/lib/templates/erb/scaffold/edit.html.erb +6 -0
  69. data/lib/templates/erb/scaffold/index.html.erb +31 -0
  70. data/lib/templates/erb/scaffold/new.html.erb +5 -0
  71. data/lib/templates/erb/scaffold/show.html.erb +11 -0
  72. metadata +129 -84
  73. data/.codeclimate.yml +0 -30
  74. data/.gitignore +0 -17
  75. data/.rspec +0 -2
  76. data/.rubocop.yml +0 -1156
  77. data/.travis.yml +0 -20
  78. data/Gemfile +0 -4
  79. data/Gemfile.lock +0 -113
  80. data/Guardfile +0 -31
  81. data/features/plugin.feature +0 -35
  82. data/features/step_definitions/plugin_steps.rb +0 -75
  83. data/features/support/env.rb +0 -1
  84. data/lib/odania/config.rb +0 -17
  85. data/lib/odania/config/backend.rb +0 -31
  86. data/lib/odania/config/backend_group.rb +0 -43
  87. data/lib/odania/config/domain.rb +0 -59
  88. data/lib/odania/config/duplicates.rb +0 -28
  89. data/lib/odania/config/global_config.rb +0 -210
  90. data/lib/odania/config/layout.rb +0 -30
  91. data/lib/odania/config/page.rb +0 -29
  92. data/lib/odania/config/page_base.rb +0 -47
  93. data/lib/odania/config/plugin_config.rb +0 -58
  94. data/lib/odania/config/style.rb +0 -36
  95. data/lib/odania/config/sub_domain.rb +0 -113
  96. data/lib/odania/config/subdomain_config.rb +0 -124
  97. data/lib/odania/consul.rb +0 -138
  98. data/lib/odania/plugin.rb +0 -103
  99. data/odania.gemspec +0 -34
  100. data/spec/fixtures/global_config.json +0 -135
  101. data/spec/fixtures/plugin_config_1.json +0 -102
  102. data/spec/lib/odania/config/global_config_spec.rb +0 -69
  103. data/spec/lib/odania/config/plugin_config_spec.rb +0 -31
  104. data/spec/lib/odania/plugin_spec.rb +0 -25
  105. data/spec/lib/odania_spec.rb +0 -10
  106. data/spec/spec_helper.rb +0 -19
  107. data/spec/support/consul_mock.rb +0 -123
  108. data/tasks/odania.rake +0 -8
  109. data/tasks/rspec.rake +0 -7
@@ -1,102 +0,0 @@
1
- {
2
- "plugin-config": {
3
- "name": "odania-core",
4
- "default": true,
5
- "author": [
6
- "Mike Petersen <mike@odania-it.com>"
7
- ],
8
- "url": "http://www.odania.com",
9
- "sites": [
10
- "www.domain.de"
11
- ]
12
- },
13
- "config": {
14
- "title": "This is my awesome title"
15
- },
16
- "valid_domains": {
17
- "example.com": [
18
- "www"
19
- ]
20
- },
21
- "default_domains": {
22
- "example.com": [
23
- "www"
24
- ]
25
- },
26
- "domains": {
27
- "_general": {
28
- "_general": {
29
- "redirects": {},
30
- "config": {},
31
- "web": {},
32
- "assets": {},
33
- "layouts": {
34
- "main": {
35
- "config": {
36
- "styles": {
37
- "_general": {
38
- "entry_point": "application.html.erb"
39
- },
40
- "left_menu": {
41
- "entry_point": "application.html.erb"
42
- }
43
- }
44
- },
45
- "assets": {
46
- "layouts/mac-beath/img/favicon/favicon.png": {
47
- "plugin_url": "layouts/mac-beath/img/favicon/favicon.png",
48
- "cacheable": true,
49
- "expires": 60
50
- },
51
- "layouts/mac-beath/img/photos/t12.jpg": {
52
- "plugin_url": "layouts/mac-beath/img/photos/t12.jpg"
53
- }
54
- },
55
- "partials": {
56
- "layouts/simple/application_part1.html": {
57
- "plugin_url": "layouts/simple/application_part1.html.erb",
58
- "cacheable": true,
59
- "expires": 60
60
- }
61
- }
62
- }
63
- },
64
- "partials": {
65
- "footer": {
66
- "plugin_url": "partials/footer.html",
67
- "cacheable": true,
68
- "expires": 60
69
- }
70
- }
71
- }
72
- },
73
- "example.com": {
74
- "www": {
75
- "redirects": {
76
- "^/test": "/test2"
77
- },
78
- "config": {},
79
- "web": {
80
- "/imprint": {
81
- "plugin_url": "/my-imprint",
82
- "cacheable": true,
83
- "expires": 60
84
- },
85
- "/": {
86
- "plugin_url": "/my-home",
87
- "cacheable": false
88
- }
89
- },
90
- "assets": {},
91
- "layouts": {}
92
- }
93
- }
94
- },
95
- "partials": {
96
- "_general": {
97
- "_general": {
98
-
99
- }
100
- }
101
- }
102
- }
@@ -1,69 +0,0 @@
1
- describe Odania::Config::GlobalConfig do
2
- let(:cfg1) {
3
- JSON.parse File.read("#{BASE_DIR}/spec/fixtures/plugin_config_1.json")
4
- }
5
- let(:global_cfg) {
6
- JSON.parse File.read("#{BASE_DIR}/spec/fixtures/global_config.json")
7
- }
8
-
9
- context 'configuration' do
10
- it 'add configuration' do
11
- expect(subject.add_plugin_config(cfg1)).to be(true)
12
-
13
- cfg_result = subject.dump
14
- expect(cfg_result['domains']['example.com']['www']['redirects']).to eql(cfg1['domains']['example.com']['www']['redirects'])
15
- expect(cfg_result['domains']['example.com']['www']['config']).to eql(cfg1['domains']['example.com']['www']['config'])
16
-
17
- %w(web assets partials).each do |type|
18
- cfg1['domains']['example.com']['www'][type].each_pair do |path, data|
19
-
20
- expect(cfg_result['domains']['example.com']['www'][type][path]['plugin_url']).to eql(data['plugin_url'])
21
- end
22
- end
23
-
24
- end
25
-
26
- it 'detects duplicates' do
27
- expect(subject.add_plugin_config(cfg1)).to be(true)
28
- expect(subject.duplicates).to be_empty
29
- expect(subject.add_plugin_config(cfg1)).to be(true)
30
-
31
- duplicates = subject.duplicates
32
- expect(subject.duplicates).not_to be_empty
33
- expect(duplicates).to have_key(:config)
34
- expect(duplicates).to have_key(:assets)
35
- expect(duplicates).to have_key(:redirect)
36
- end
37
-
38
- it 'generate global configuration' do
39
- cfg_name = cfg1['plugin-config']['name']
40
- $consul_mock.config.set("plugins_config/#{cfg_name}", cfg1)
41
-
42
- $consul_mock.service.services = {
43
- cfg_name => [
44
- OpenStruct.new({
45
- 'Node' => 'agent-one',
46
- 'Address' => '172.20.20.1',
47
- 'ServiceID' => "#{cfg_name}_1",
48
- 'ServiceName' => cfg_name,
49
- 'ServiceTags' => [],
50
- 'ServicePort' => 80,
51
- 'ServiceAddress' => '172.20.20.1'
52
- }),
53
- OpenStruct.new({
54
- 'Node' => 'agent-two',
55
- 'Address' => '172.20.20.2',
56
- 'ServiceID' => "#{cfg_name}_2",
57
- 'ServiceName' => cfg_name,
58
- 'ServiceTags' => [],
59
- 'ServicePort' => 80,
60
- 'ServiceAddress' => '172.20.20.1'
61
- })
62
- ]
63
- }
64
-
65
- global_config = subject.generate_global_config
66
- expect(global_config).not_to be_empty
67
- end
68
- end
69
- end
@@ -1,31 +0,0 @@
1
- describe Odania::Config::PluginConfig do
2
- let(:cfg) {
3
- JSON.parse File.read("#{BASE_DIR}/spec/fixtures/plugin_config_1.json")
4
- }
5
-
6
- context 'configuration' do
7
- it 'should be valid' do
8
- expect(subject.config).to be_a(Hash)
9
- expect(subject.domains).to be_a(Hash)
10
- subject.domains.each_pair do |domain, data|
11
- expect(data).to be_a(Odania::Config::Domain)
12
- end
13
- end
14
-
15
- it 'loads configuration' do
16
- expect(subject.load(cfg)).to be(true)
17
-
18
- expect(subject.config).to eql(cfg['config'])
19
- expect(subject.plugin_config).to eql(cfg['plugin-config'])
20
- expect(subject.domains.keys).to eql(cfg['domains'].keys)
21
- end
22
-
23
- it 'dumps the same config' do
24
- expect(subject.load(cfg)).to be(true)
25
- result = subject.dump
26
- diff = HashDiff.best_diff result, cfg
27
- puts "Best diff: #{diff.inspect}"
28
- expect(result).to eql(cfg)
29
- end
30
- end
31
- end
@@ -1,25 +0,0 @@
1
- describe Odania::Plugin do
2
- context 'services' do
3
- let(:subject) {
4
- Odania::Plugin.new($consul_mock)
5
- }
6
-
7
- let(:cfg) {
8
- JSON.parse File.read("#{BASE_DIR}/spec/fixtures/plugin_config_1.json")
9
- }
10
-
11
- it 'registers a plugin' do
12
- cfg_name = cfg['plugin-config']['name']
13
- instance_name = 'cfg_instance_1'
14
- key_name = "#{cfg_name}|#{instance_name}"
15
- expect(subject.register(instance_name, cfg)).to eql(key_name)
16
- expect($consul_mock.configuration["plugins_config/#{cfg_name}"]).to eql(cfg)
17
- end
18
-
19
- it 'deregisters a plugin' do
20
- instance_name = 'cfg_instance_1'
21
- subject.register(instance_name, cfg)
22
- expect(subject.deregister(instance_name)).to be_truthy
23
- end
24
- end
25
- end
@@ -1,10 +0,0 @@
1
- describe Odania do
2
-
3
- describe 'odania' do
4
- let(:ips) { subject.ips }
5
-
6
- it 'retrieve ips' do
7
- expect(ips).not_to be_empty
8
- end
9
- end
10
- end
@@ -1,19 +0,0 @@
1
- ENV['ENVIRONMENT'] = 'test'
2
-
3
- require 'codeclimate-test-reporter'
4
- CodeClimate::TestReporter.start
5
-
6
- require 'odania'
7
- require_relative 'support/consul_mock'
8
-
9
- require 'hashdiff'
10
-
11
- RSpec.configure do |config|
12
- config.before(:each) do
13
- $consul_mock = ConsulMock.new
14
-
15
- allow(Odania).to receive(:plugin) do
16
- Odania::Plugin.new($consul_mock)
17
- end
18
- end
19
- end
@@ -1,123 +0,0 @@
1
- class ConsulMock < Odania::Consul
2
- attr_reader :service, :config, :event, :health
3
- attr_accessor :configuration
4
-
5
- def initialize
6
- self.configuration = {
7
- 'global_plugins_config' => {
8
- 'domains' => {}
9
- }
10
- }
11
-
12
- @service = Service.new
13
- @config = Config.new(self.configuration)
14
- @event = Event.new
15
- @health = Health.new
16
- end
17
-
18
- class Config
19
- def initialize(configuration)
20
- @configuration = configuration
21
- end
22
-
23
- def get(path)
24
- @configuration[path]
25
- end
26
-
27
- def get_all(path)
28
- result = {}
29
- @configuration.each_pair do |key, value|
30
- result[key] = value if key.start_with? path
31
- end
32
-
33
- result
34
- end
35
-
36
- def set(key, value)
37
- @configuration[key] = value
38
- end
39
-
40
- def delete(key)
41
- @configuration.delete[key]
42
- end
43
- end
44
-
45
- class Service
46
- attr_accessor :services
47
-
48
- def initialize
49
- @services = {}
50
- end
51
-
52
- def get_all
53
- @services
54
- end
55
-
56
- def get_all_for(plugin_name)
57
- result = []
58
- @services.each_pair do |key, val|
59
- result << val if key.start_with? plugin_name
60
- end
61
- result
62
- end
63
-
64
- def get(key, scope=:first)
65
- @services[key]
66
- end
67
-
68
- def register(consul_config)
69
- @services[consul_config['id']] = consul_config
70
- end
71
-
72
- def deregister(name)
73
- @services.delete name
74
- end
75
-
76
- def build_config(plugin_name, plugin_instance_name, ip, tags=[], port=80)
77
- {
78
- 'id' => plugin_instance_name,
79
- 'name' => plugin_name,
80
- 'tags' => tags,
81
- 'address' => ip,
82
- 'port' => port,
83
- 'token' => plugin_instance_name,
84
- 'checks' => [
85
- {
86
- 'id' => plugin_name,
87
- 'name' => "HTTP on port #{port}",
88
- 'http' => "http://#{ip}:#{port}/health",
89
- 'interval' => '10s',
90
- 'timeout' => '1s'
91
- }
92
- ]
93
- }
94
- end
95
- end
96
-
97
- class Event
98
- def initialize
99
- @events = Hash.new { |hash, key| hash[key] = [] }
100
- end
101
-
102
- def fire(key, value)
103
- @events[key] << value
104
- end
105
- end
106
-
107
- class Health
108
- def initialize
109
- @health_states = [
110
- {'Node' => '04977bad2036', 'CheckID' => 'serfHealth', 'Name' => 'Serf Health Status', 'Status' => 'passing', 'Notes' => '', 'Output' => 'Agent alive and reachable', 'ServiceID' => '', 'ServiceName' => ''},
111
- {'Node' => '04977bad2036', 'CheckID' => 'service_1', 'Name' => "Service 'static-content' check", 'Status' => 'passing', 'Notes' => '', 'Output' => 'HTTP GET http://172.17.0.4:80/health: 200 OK Output: OK', 'ServiceID' => 'static_content_1', 'ServiceName' => 'static-content'}
112
- ]
113
- end
114
-
115
- def state(state=:any)
116
- @health_states
117
- end
118
-
119
- def service(name)
120
- Diplomat::Health.service(name)
121
- end
122
- end
123
- end
@@ -1,8 +0,0 @@
1
- namespace :odania do
2
- namespace :global do
3
- desc 'Generate the global config'
4
- task :generate_config do
5
- Odania.plugin.plugin_config.generate_global_config
6
- end
7
- end
8
- end
@@ -1,7 +0,0 @@
1
- begin
2
- require 'rspec/core/rake_task'
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
- rescue LoadError
6
- # rspec is not available
7
- end