beyond 0.0.1

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.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/beyond/application.js +13 -0
  6. data/app/assets/stylesheets/beyond/application.css +13 -0
  7. data/app/controllers/beyond/application_controller.rb +4 -0
  8. data/app/controllers/beyond/plugins_controller.rb +43 -0
  9. data/app/controllers/beyond/tenants_controller.rb +68 -0
  10. data/app/helpers/beyond/application_helper.rb +4 -0
  11. data/app/models/beyond/plugin.rb +40 -0
  12. data/app/models/beyond/tenant.rb +62 -0
  13. data/app/models/beyond/user.rb +8 -0
  14. data/app/views/beyond/plugins/new.html.haml +20 -0
  15. data/app/views/beyond/tenants/edit.html.haml +16 -0
  16. data/app/views/beyond/tenants/new.html.haml +4 -0
  17. data/app/views/beyond/tenants/show.html.haml +14 -0
  18. data/app/views/beyond/users/_new.html.haml +16 -0
  19. data/app/views/layouts/beyond/application.html.erb +17 -0
  20. data/config/initializers/devise.rb +255 -0
  21. data/config/locales/devise.en.yml +59 -0
  22. data/config/routes.rb +13 -0
  23. data/db/migrate/20140204173749_devise_create_beyond_users.rb +42 -0
  24. data/db/migrate/20140204173856_create_beyond_plugins.rb +17 -0
  25. data/db/migrate/20140204173902_create_beyond_tenants.rb +10 -0
  26. data/lib/beyond/engine.rb +16 -0
  27. data/lib/beyond/version.rb +3 -0
  28. data/lib/beyond.rb +5 -0
  29. data/lib/tasks/beyond_tasks.rake +4 -0
  30. data/test/beyond_test.rb +7 -0
  31. data/test/dummy/README.rdoc +28 -0
  32. data/test/dummy/Rakefile +6 -0
  33. data/test/dummy/app/assets/javascripts/application.js +13 -0
  34. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  35. data/test/dummy/app/controllers/application_controller.rb +5 -0
  36. data/test/dummy/app/helpers/application_helper.rb +2 -0
  37. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  38. data/test/dummy/bin/bundle +3 -0
  39. data/test/dummy/bin/rails +4 -0
  40. data/test/dummy/bin/rake +4 -0
  41. data/test/dummy/config/application.rb +23 -0
  42. data/test/dummy/config/application.yml +3 -0
  43. data/test/dummy/config/boot.rb +5 -0
  44. data/test/dummy/config/database.yml +25 -0
  45. data/test/dummy/config/environment.rb +5 -0
  46. data/test/dummy/config/environments/development.rb +29 -0
  47. data/test/dummy/config/environments/production.rb +80 -0
  48. data/test/dummy/config/environments/test.rb +36 -0
  49. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  50. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  51. data/test/dummy/config/initializers/inflections.rb +16 -0
  52. data/test/dummy/config/initializers/mime_types.rb +5 -0
  53. data/test/dummy/config/initializers/secret_token.rb +12 -0
  54. data/test/dummy/config/initializers/session_store.rb +3 -0
  55. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  56. data/test/dummy/config/locales/en.yml +23 -0
  57. data/test/dummy/config/routes.rb +4 -0
  58. data/test/dummy/config.ru +4 -0
  59. data/test/dummy/db/development.sqlite3 +0 -0
  60. data/test/dummy/db/schema.rb +55 -0
  61. data/test/dummy/log/development.log +6931 -0
  62. data/test/dummy/public/404.html +58 -0
  63. data/test/dummy/public/422.html +58 -0
  64. data/test/dummy/public/500.html +57 -0
  65. data/test/dummy/public/favicon.ico +0 -0
  66. data/test/dummy/tmp/cache/assets/development/sprockets/329c8e74ee84b2fbddd8695906f28ca4 +0 -0
  67. data/test/dummy/tmp/cache/assets/development/sprockets/43d3076c25d714cbb447da5a78c73911 +0 -0
  68. data/test/dummy/tmp/cache/assets/development/sprockets/8fb0c7e5315821c90e3641f1b22d0947 +0 -0
  69. data/test/dummy/tmp/cache/assets/development/sprockets/a6ad7cf3aadcbe2d521f45adc1432fa8 +0 -0
  70. data/test/dummy/tmp/cache/assets/development/sprockets/a778481f9e2ae19e9b47c1a12a5f36f1 +0 -0
  71. data/test/dummy/tmp/cache/assets/development/sprockets/ae14fa652db78218572bb9d1bf21b675 +0 -0
  72. data/test/fixtures/beyond/plugins.yml +11 -0
  73. data/test/fixtures/beyond/tenants.yml +11 -0
  74. data/test/fixtures/beyond/users.yml +11 -0
  75. data/test/integration/navigation_test.rb +10 -0
  76. data/test/models/beyond/plugin_test.rb +9 -0
  77. data/test/models/beyond/tenant_test.rb +9 -0
  78. data/test/models/beyond/user_test.rb +9 -0
  79. data/test/test_helper.rb +15 -0
  80. metadata +270 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4dbe8e9e9ea68a2608032efd90e213c6b9f62950
4
+ data.tar.gz: 177062d61956865b13f23d5c7c0015c759d2f12e
5
+ SHA512:
6
+ metadata.gz: bb0db302cd4b0c240e52668a628e05e9f7129a84d4f854561d2ce3162c5cd29271b9f699c66ea47de0e665d71ce34abdd51f92b43d9e5b398da924a5adefc80a
7
+ data.tar.gz: 2688a1f6f49bc058100f0e8d2190d73df33cbc08eabc90c3636adcafe1c23b98091e707aa67a19f1b9d6bed648fee85faac2ad36f79c209f16eae41215081a37
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Beyond
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Beyond'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,4 @@
1
+ module Beyond
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,43 @@
1
+ module Beyond
2
+ class PluginsController < ApplicationController
3
+ def new
4
+ @plugin = Plugin.new
5
+ end
6
+
7
+ def create
8
+ tenant_name = params[:plugin].delete :tenant
9
+ @plugin = Plugin.new(plugin_params)
10
+ @plugin.tenant = Tenant.find_by_name(tenant_name)
11
+ if @plugin.save
12
+ redirect_to root_url, notice: 'You have successfully uploaded a new plugin!'
13
+ else
14
+ errors = @plugin.errors.messages.map { |k, v| k.to_s+' ' + v.join(' and ')+' ' }
15
+ redirect_to root_url, alert: 'There was an error while trying to create your plugin. ' + errors.join(' ')
16
+ end
17
+ end
18
+
19
+ def start
20
+ begin
21
+ Plugin.find(params[:id]).start
22
+ redirect_to root_url, notice: 'Plugin started'
23
+ rescue
24
+ redirect_to root_url, alert: 'Error: couldn\'t start plugin'
25
+ end
26
+ end
27
+
28
+ def stop
29
+ begin
30
+ Plugin.find(params[:id]).stop
31
+ redirect_to root_url, notice: 'Plugin stoped'
32
+ rescue
33
+ redirect_to root_url, alert: 'Error: couldn\'t stop plugin'
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def plugin_params
40
+ params.require(:plugin).permit(:name, :description, :public, :archive)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,68 @@
1
+ module Beyond
2
+ class TenantsController < ApplicationController
3
+ def new
4
+ @tenant = Tenant.new
5
+ end
6
+
7
+ def create
8
+ tenant = Tenant.new(create_params)
9
+ tenant.user = current_user
10
+ begin
11
+ if tenant.save
12
+ redirect_to root_url, notice: "You have successfully created #{tenant.name}"
13
+ else
14
+ errors = tenant.errors.messages.map { |k, v| k.to_s+' ' + v.join(' and ')+' ' }
15
+ redirect_to root_url, alert: "There was an error while trying to create #{tenant.name}. " + errors.join(' ')
16
+ end
17
+ rescue
18
+ redirect_to root_url, alert: "There was an error while trying to create #{tenant.name}. "
19
+ end
20
+ end
21
+
22
+ def show
23
+ @tenant = Tenant.find(params[:id])
24
+ end
25
+
26
+ def edit
27
+ @tenant = Tenant.find(params[:id])
28
+ @configs = @tenant.configs.group_by { |_, v| v['category'] }
29
+ end
30
+
31
+ def update
32
+ tenant = Tenant.find(params[:id])
33
+ changes = params.select { |k, _| k =~ /^config_.+/ }
34
+ changes = Hash[changes.map { |k, v| [k.to_s.sub(/^config_/, ''), v] }]
35
+ begin
36
+ tenant.update_configs changes
37
+ rescue
38
+ redirect_to root_url, alert: 'There was an error while trying to save your configurations to file.'
39
+ return
40
+ end
41
+ redirect_to root_url, notice: 'You have successfully updated you configurations!'
42
+ end
43
+
44
+ def start
45
+ begin
46
+ Tenant.find(params[:id]).start
47
+ redirect_to root_url, notice: 'Tenant started'
48
+ rescue
49
+ redirect_to root_url, alert: 'Error: couldn\'t start tenant'
50
+ end
51
+ end
52
+
53
+ def stop
54
+ begin
55
+ Tenant.find(params[:id]).stop
56
+ redirect_to root_url, notice: 'Tenant stoped'
57
+ rescue
58
+ redirect_to root_url, alert: 'Error: couldn\'t stop tenant'
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def create_params
65
+ params.require(:tenant).permit(:name)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,4 @@
1
+ module Beyond
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,40 @@
1
+ module Beyond
2
+ class Plugin < ActiveRecord::Base
3
+ belongs_to :tenant
4
+
5
+ validates :name, presence: true, format: {with: /\A[a-z_A-Z]+\z/, message: 'Only letters, underscore and numbers allowed.'}
6
+ validates :description, presence: true
7
+
8
+ has_attached_file :archive, path: File.join(ENV['tenants_plugins_dir'], ':plugin_tenant_name', ':filename')
9
+
10
+ validates_attachment :archive, :presence => true,
11
+ :content_type => { :content_type => "application/x-gzip" },
12
+ :size => { :in => 0..10.megabytes }
13
+
14
+ def extract
15
+ Dir.chdir File.join(ENV['tenants_plugins_dir'], tenant.name) do
16
+ unless Kernel.system "tar xzf #{archive_file_name}"
17
+ throw "Can't extract archive"
18
+ end
19
+ end
20
+ end
21
+
22
+ def stop
23
+ Dir.chdir File.join(ENV['tenants_plugins_dir'], tenant.name) do
24
+ FileUtils.rm_r(name)
25
+ end
26
+ update_attribute(:activated, false)
27
+ end
28
+
29
+ def start
30
+ extract
31
+ update_attribute(:activated, true)
32
+ end
33
+
34
+ private
35
+
36
+ Paperclip.interpolates :plugin_tenant_name do |attachment, style|
37
+ attachment.instance.tenant.name
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,62 @@
1
+ module Beyond
2
+ class Tenant < ActiveRecord::Base
3
+ belongs_to :user
4
+ has_many :plugins
5
+
6
+ validates :name, presence: true, uniqueness: true
7
+ validates_format_of :name, :with => /\A[0-9_a-z]+\z/
8
+
9
+ after_create :deploy
10
+
11
+ def configs
12
+ YAML.load_file(File.join(ENV['tenants_configs_dir'], name + '.yml'))
13
+ end
14
+
15
+ def update_configs changes
16
+ conf = configs
17
+ changes.each do |k, v|
18
+ if conf[k]['type'] == 'bool'
19
+ conf[k]['value'] = (v == 'true')
20
+ else
21
+ conf[k]['value'] = v
22
+ end
23
+ end
24
+ file = File.join(ENV['tenants_configs_dir'], name + '.yml')
25
+ File.open file, 'w' do |f|
26
+ f.print conf.to_yaml
27
+ end
28
+ PLUGINS.notify :on_update_configs, self
29
+ end
30
+
31
+ def deploy
32
+ unless Kernel.system("#{ENV['kamino_bin']} deploy -name='#{name}'")
33
+ throw 'Error creating tenant'
34
+ end
35
+ PLUGINS.notify :on_deploy, self
36
+ end
37
+
38
+ def stop
39
+ unless Kernel.system("docker stop #{name}")
40
+ throw 'Error stoping tenant'
41
+ end
42
+ PLUGINS.notify :on_stop, self
43
+ end
44
+
45
+ def start
46
+ unless Kernel.system("docker start #{name}")
47
+ throw 'Error starting tenant'
48
+ end
49
+ PLUGINS.notify :on_start, self
50
+ end
51
+
52
+ def working?
53
+ !!(`docker top #{name}`.match /\d+/)
54
+ end
55
+
56
+ private
57
+
58
+ def kamino_dir
59
+ File.dirname(ENV['kamino_bin'])
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,8 @@
1
+ module Beyond
2
+ class User < ActiveRecord::Base
3
+ # Include default devise modules. Others available are:
4
+ # :confirmable, :lockable, :timeoutable and :omniauthable
5
+ devise :database_authenticatable, :registerable,
6
+ :recoverable, :rememberable, :trackable, :validatable
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ %h1 Plugins#new
2
+ = form_for @plugin, :url => plugins_path, :html => { :multipart => true } do |form|
3
+ = form.label :name
4
+ = form.text_field :name
5
+ %br/
6
+ = form.label :description
7
+ = form.text_field :description
8
+ %br/
9
+ = form.label :public
10
+ = form.check_box :public
11
+ %br/
12
+ = form.label :archive
13
+ = form.file_field :archive
14
+ %br/
15
+ = form.label :tenant
16
+ %br/
17
+ - current_user.tenants.each do |tenant|
18
+ = form.radio_button(:tenant, tenant.name)+' '+tenant.name
19
+ %br/
20
+ = form.submit
@@ -0,0 +1,16 @@
1
+ %h2= @tenant.name
2
+ %br/
3
+ = form_tag(tenant_path, method: :put) do
4
+ - @configs.each do |category|
5
+ %h3= category.first
6
+ %br/
7
+ - category.last.each do |config|
8
+ = label_tag config.first
9
+ = name = 'config_' + config.first; |
10
+ case config.last['type'] |
11
+ when 'string' then text_field_tag name, config.last['value'] |
12
+ when 'int' then number_field_tag name, config.last['value'] |
13
+ when 'bool' then radio_button_tag(name, 'true', config.last['value'])+' true'+radio_button_tag(name, 'false', !config.last['value'])+' false' |
14
+ end |
15
+ %br/
16
+ = submit_tag
@@ -0,0 +1,4 @@
1
+ %h1 Create new tenant
2
+ = form_for @tenant do |f|
3
+ = f.text_field :name
4
+ = f.submit
@@ -0,0 +1,14 @@
1
+ %h1= @tenant.name
2
+ = link_to 'Change configurations', edit_tenant_path(@tenant)
3
+ - if @tenant.working?
4
+ = button_to 'Stop tenant', action: :stop
5
+ - else
6
+ = button_to 'Start tenant', action: :start
7
+
8
+ %h3 Plugins
9
+ - @tenant.plugins.each do |p|
10
+ = p.name
11
+ - if p.activated
12
+ = button_to 'Stop plugin', plugin_stop_path(p)
13
+ - else
14
+ = button_to 'Start plugin', plugin_start_path(p)
@@ -0,0 +1,16 @@
1
+ .sideform
2
+ = form_for(User.new, :as => :user, :url => session_path(:user)) do |f|
3
+ %div
4
+ = f.label :email
5
+ %br/
6
+ = f.email_field :email, :autofocus => true
7
+ %div
8
+ = f.label :password
9
+ %br/
10
+ = f.password_field :password
11
+ %div
12
+ = f.check_box :remember_me
13
+ = f.label :remember_me
14
+ %div= f.submit "Sign in", class: 'btn btn-primary', style: 'background: #FF6600'
15
+ %br
16
+ = link_to 'Register', new_user_registration_path
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Beyond</title>
5
+ <%= stylesheet_link_tag "beyond/application", media: "all" %>
6
+ <%= javascript_include_tag "beyond/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+
12
+ <p class="notice"><%= notice %></p>
13
+ <p class="alert"><%= alert %></p>
14
+ <%= yield %>
15
+
16
+ </body>
17
+ </html>