bagboy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/app/assets/javascripts/bagboy/application.js +16 -0
  5. data/app/assets/javascripts/bagboy/form.coffee +4 -0
  6. data/app/assets/javascripts/bagboy/foundation.min.js +10 -0
  7. data/app/assets/javascripts/bagboy/jquery.js +26 -0
  8. data/app/assets/javascripts/bagboy/modernizr.js +8 -0
  9. data/app/assets/javascripts/bagboy/pages.coffee +3 -0
  10. data/app/assets/javascripts/bagboy/sessions.js +2 -0
  11. data/app/assets/javascripts/bagboy/users.js +2 -0
  12. data/app/assets/stylesheets/bagboy/application.scss +18 -0
  13. data/app/assets/stylesheets/bagboy/foundation.css +5263 -0
  14. data/app/assets/stylesheets/bagboy/normalize.css +423 -0
  15. data/app/assets/stylesheets/bagboy/pages.scss +20 -0
  16. data/app/controllers/bagboy/application_controller.rb +36 -0
  17. data/app/controllers/bagboy/data_bag_items_controller.rb +50 -0
  18. data/app/controllers/bagboy/data_bag_template_items_controller.rb +25 -0
  19. data/app/controllers/bagboy/data_bag_templates_controller.rb +16 -0
  20. data/app/controllers/bagboy/data_bags_controller.rb +40 -0
  21. data/app/controllers/bagboy/pages_controller.rb +20 -0
  22. data/app/controllers/bagboy/sessions_controller.rb +27 -0
  23. data/app/controllers/bagboy/users_controller.rb +58 -0
  24. data/app/helpers/bagboy/application_helper.rb +4 -0
  25. data/app/helpers/bagboy/pages_helper.rb +4 -0
  26. data/app/helpers/bagboy/sessions_helper.rb +4 -0
  27. data/app/helpers/bagboy/users_helper.rb +4 -0
  28. data/app/models/bagboy/template.rb +33 -0
  29. data/app/models/bagboy/user.rb +9 -0
  30. data/app/views/bagboy/data_bag_items/_form.html.haml +20 -0
  31. data/app/views/bagboy/data_bag_items/edit.html.haml +18 -0
  32. data/app/views/bagboy/data_bag_items/index.html.haml +29 -0
  33. data/app/views/bagboy/data_bag_items/new.html.haml +22 -0
  34. data/app/views/bagboy/data_bag_templates/show.html.haml +45 -0
  35. data/app/views/bagboy/data_bags/_form.html.haml +10 -0
  36. data/app/views/bagboy/data_bags/index.html.haml +23 -0
  37. data/app/views/bagboy/data_bags/new.html.haml +10 -0
  38. data/app/views/bagboy/data_bags/show.html.haml +32 -0
  39. data/app/views/bagboy/pages/index.html.haml +29 -0
  40. data/app/views/bagboy/sessions/new.html.haml +17 -0
  41. data/app/views/bagboy/users/_form.html.haml +15 -0
  42. data/app/views/bagboy/users/edit.html.haml +13 -0
  43. data/app/views/bagboy/users/index.html.haml +27 -0
  44. data/app/views/bagboy/users/new.html.haml +10 -0
  45. data/app/views/bagboy/users/show.html.haml +11 -0
  46. data/app/views/layouts/bagboy/_form_errors.html.haml +7 -0
  47. data/app/views/layouts/bagboy/_header.html.haml +51 -0
  48. data/app/views/layouts/bagboy/application.html.haml +20 -0
  49. data/config/initializers/gems.rb +1 -0
  50. data/config/routes.rb +37 -0
  51. data/db/migrate/20140506101012_create_bagboy_users.rb +10 -0
  52. data/db/migrate/20140507134332_create_bagboy_templates.rb +9 -0
  53. data/lib/bagboy.rb +21 -0
  54. data/lib/bagboy/chef/data_bags/bag.rb +74 -0
  55. data/lib/bagboy/chef/data_bags/item.rb +100 -0
  56. data/lib/bagboy/chef/data_bags_helper.rb +48 -0
  57. data/lib/bagboy/chef/knife.rb +39 -0
  58. data/lib/bagboy/core/file_helper.rb +25 -0
  59. data/lib/bagboy/core/scm/base.rb +17 -0
  60. data/lib/bagboy/core/scm/git.rb +33 -0
  61. data/lib/bagboy/core/scm/none.rb +19 -0
  62. data/lib/bagboy/core/scm_helper.rb +37 -0
  63. data/lib/bagboy/engine.rb +14 -0
  64. data/lib/bagboy/version.rb +3 -0
  65. data/lib/tasks/bagboy_tasks.rake +4 -0
  66. metadata +304 -0
@@ -0,0 +1,10 @@
1
+ %form{ action: create_data_bag_path, method: 'post' }
2
+ .row
3
+ .large-2.columns
4
+ %label.right.inline{ for: 'data_bag_name' } Name
5
+ .large-10.columns
6
+ %input{ type: 'text', id: 'data_bag_name', name: 'data_bag[name]', placeholder: 'Name' }
7
+ .row
8
+ .large-2.columns
9
+ .large-10.columns
10
+ %button.button.small{ type: 'submit' } Submit
@@ -0,0 +1,23 @@
1
+ %h1 Data Bags
2
+
3
+ .button-bar
4
+ %ul.button-group
5
+ %li
6
+ %a.button.tiny{ href: new_data_bag_path } New Data Bag
7
+
8
+ %hr
9
+
10
+ %table
11
+ %thead
12
+ %tr
13
+ %th Name
14
+ %th
15
+ %th
16
+ %tbody
17
+ - @bags.each do |bag|
18
+ %tr
19
+ %td
20
+ %a{href: data_bag_path(bag.name)}= bag.name
21
+ %td
22
+ %a{href: data_bag_path(bag.name)} View
23
+ %td Delete
@@ -0,0 +1,10 @@
1
+ %h1 New Data Bag
2
+
3
+ .button-bar
4
+ %ul.button-group
5
+ %li
6
+ %a.button.tiny{ href: data_bags_path } Back to Data Bags
7
+
8
+ %hr
9
+
10
+ = render 'form'
@@ -0,0 +1,32 @@
1
+ %h1= "Items for #{@bag.name}"
2
+
3
+ .button-bar
4
+ %ul.button-group
5
+ %li
6
+ %a.button.tiny{ href: new_data_bag_item_path(@bag.name) } New Item
7
+ %li
8
+ %a.button.tiny{ href: data_bag_template_path(@bag.name) } Template
9
+ %ul.button-group
10
+ %li
11
+ %a.button.tiny{ href: data_bags_path } Back to Data Bags
12
+
13
+ %hr
14
+
15
+ %table
16
+ %thead
17
+ %tr
18
+ %th Name
19
+ %th
20
+ %th
21
+ %th
22
+ %tbody
23
+ - @items.each do |item|
24
+ %tr
25
+ %td
26
+ %a{href: data_bag_items_path({bag: @bag.name, item: item.name})}= item.name
27
+ %td
28
+ %a{href: data_bag_items_path({bag: @bag.name, item: item.name})} View
29
+ %td
30
+ %a{href: edit_data_bag_item_path({bag: @bag.name, item: item.name})} Edit
31
+
32
+ %td Delete
@@ -0,0 +1,29 @@
1
+ %h1 Overview
2
+
3
+ %hr
4
+
5
+ %table
6
+ %thead
7
+ %tr
8
+ %th Key
9
+ %th Value
10
+ %tbody
11
+ %tr
12
+ %td chef_repo path
13
+ %td= Bagboy.chef_repo
14
+ - if Bagboy.site_name != ''
15
+ %tr
16
+ %td Site Name
17
+ %td= Bagboy.site_name
18
+ %tr
19
+ %td SCM
20
+ %td= Bagboy.scm
21
+ - if Bagboy.key_path != ''
22
+ %tr
23
+ %td Key Path
24
+ %td= Bagboy.key_path
25
+ - if Bagboy.config_path != ''
26
+ %tr
27
+ %td Config Path
28
+ %td= Bagboy.config_path
29
+
@@ -0,0 +1,17 @@
1
+ %h1 Please Sign In to Continue
2
+
3
+ %hr
4
+
5
+ %form{ action: bagboy_signin_path, method: 'post' }
6
+ .row
7
+ .large-12.columns
8
+ %input{ type: 'text', name: 'email', placeholder: 'E-Mail' }
9
+ .row
10
+ .large-12.columns
11
+ %input{ type: 'password', name: 'password', placeholder: 'Password' }
12
+ .row
13
+ .large-12.columns
14
+ %button.button.tiny{ type: 'submit', id: 'submit' } Submit
15
+
16
+ - if Bagboy::User.count == 0
17
+ = link_to 'Create User', bagboy_signup_path
@@ -0,0 +1,15 @@
1
+ = render 'layouts/bagboy/form_errors', { model: user }
2
+
3
+ %form{ action: path, method: 'post' }
4
+ .row
5
+ .large-12.columns
6
+ %input{ type: 'text', id: 'user_email', name: 'user[email]', placeholder: 'E-Mail', value: user.email }
7
+ .row
8
+ .large-12.columns
9
+ %input{ type: 'password', id: 'user_password', name: 'user[password]', placeholder: 'Password' }
10
+ .row
11
+ .large-12.columns
12
+ %input{ type: 'password', id: 'user_password_confirmation', name: 'user[password_confirmation]', placeholder: 'Password Confirmation' }
13
+ .row
14
+ .large-12.columns
15
+ %button.button.tiny{ type: 'submit', id: 'submit' } Submit
@@ -0,0 +1,13 @@
1
+ %h1= "Editing #{@user.email}"
2
+
3
+ .button-bar
4
+ %ul.button-group
5
+ %li
6
+ %a.button.tiny{ href: user_path( @user.id ) }= "Back to #{@user.email}"
7
+ %ul.button-group
8
+ %li
9
+ %a.button.tiny{ href: users_path } Back to Users
10
+
11
+ %hr
12
+
13
+ = render 'form', {path: update_user_path(@user.id), user: @user}
@@ -0,0 +1,27 @@
1
+ %h1 Users
2
+
3
+ .button-bar
4
+ %ul.button-group
5
+ %li
6
+ %a.button.tiny{ href: new_user_path } New User
7
+
8
+ %hr
9
+
10
+ %table
11
+ %thead
12
+ %tr
13
+ %th Email
14
+ %th
15
+ %th
16
+ %th
17
+ %tbody
18
+ - @users.each do |user|
19
+ %tr
20
+ %td
21
+ %a{ href: user_path(user.id) }= user.email
22
+ %td
23
+ %a{ href: user_path(user.id) } View
24
+ %td
25
+ %a{ href: edit_user_path(user.id) } Edit
26
+ %td
27
+ %a.confirm{ href: delete_user_path(user.id) } Delete
@@ -0,0 +1,10 @@
1
+ %h1 Create a New User
2
+
3
+ .button-bar
4
+ %ul.button-group
5
+ %li
6
+ %a.button.tiny{ href: users_path } Back to Users
7
+
8
+ %hr
9
+
10
+ = render 'form', {path: bagboy_signup_path, user: @user}
@@ -0,0 +1,11 @@
1
+ %h1= @user.email
2
+
3
+ .button-bar
4
+ %ul.button-group
5
+ %li
6
+ %a.button.tiny{ href: edit_user_path( @user.id ) }= "Edit #{@user.email}"
7
+ %ul.button-group
8
+ %li
9
+ %a.button.tiny{ href: users_path } Back to Users
10
+
11
+ %hr
@@ -0,0 +1,7 @@
1
+ - unless model.errors.empty?
2
+ %div{"data-alert" => "", class: "alert-box alert"}
3
+ - model.errors.messages.each do |name, error|
4
+ %h5= "#{name.to_s.gsub('_', ' ').capitalize}:"
5
+ %ul
6
+ - error.each do |error_message|
7
+ %li= error_message
@@ -0,0 +1,51 @@
1
+ %nav.top-bar{"data-topbar" => ""}
2
+ %ul.title-area
3
+ %li.name
4
+ %h1
5
+ %a{ href: root_path }= Bagboy.site_name
6
+
7
+ %li.toggle-topbar.menu-icon
8
+ %a{ href: root_path }
9
+ %span Menu
10
+
11
+ %section.top-bar-section
12
+ %ul.left
13
+
14
+ %li.has-dropdown
15
+ %a{ href: data_bags_path }
16
+ %i.fa.fa-archive
17
+ Data Bags
18
+ %ul.dropdown
19
+ %li
20
+ %a{ href: new_data_bag_path }
21
+ %i.fa.fa-plus
22
+ New Data Bag
23
+ - @bags.each do |bag|
24
+ %li
25
+ %a{href: data_bag_path(bag.name)}= bag.name
26
+ %li.has-dropdown
27
+ %a{ href: users_path }
28
+ %i.fa.fa-users
29
+ Users
30
+ %ul.dropdown
31
+ %li
32
+ %a{ href: new_user_path }
33
+ %i.fa.fa-plus
34
+ New User
35
+ %li
36
+ %a{ href: update_path, id: 'chef_repo_update' }
37
+ %i.fa.fa-refresh
38
+ Update chef-repo
39
+
40
+ %ul.right
41
+
42
+ - if current_user
43
+ %li.has-dropdown
44
+ %a{ href: user_path(current_user.id) }
45
+ %i.fa.fa-user
46
+ =current_user.email
47
+ %ul.dropdown
48
+ %li.has-dropdown
49
+ %a{ href: signout_path }
50
+ %i.fa.fa-sign-out
51
+ Logout
@@ -0,0 +1,20 @@
1
+ !!!
2
+ %html
3
+ %head
4
+ %title= "#{Bagboy.site_name}"
5
+ %link{href: "//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css", rel: "stylesheet"}/
6
+ = javascript_include_tag "bagboy/application"
7
+ = stylesheet_link_tag "bagboy/application", media: "all"
8
+ = csrf_meta_tags
9
+ %meta{content: "width=device-width, initial-scale=1.0", name: "viewport"}/
10
+ %body
11
+ = render 'layouts/bagboy/header'
12
+ - flash.each do |name, msg|
13
+ %div{"data-alert" => "", class: "alert-box #{name}"}
14
+ = msg
15
+ %a.close{href: "#"} ×
16
+ .row
17
+ .large-12.columns
18
+ = yield
19
+ :javascript
20
+ $(document).foundation();
@@ -0,0 +1 @@
1
+ require 'haml'
@@ -0,0 +1,37 @@
1
+ Bagboy::Engine.routes.draw do
2
+
3
+ root to: 'pages#index'
4
+
5
+ get '/update', to: 'pages#update', as: 'update'
6
+
7
+ get '/signin', to: 'sessions#new', as: 'bagboy_signin'
8
+ post '/signin', to: 'sessions#create'
9
+ get '/signout', to: 'sessions#destroy', as: 'signout'
10
+
11
+ get '/signup', to: 'users#new', as: 'bagboy_signup'
12
+ post '/signup', to: 'users#create'
13
+
14
+ get '/users', to: 'users#index', as: 'users'
15
+ get '/users/new', to: 'users#new', as: 'new_user'
16
+ get '/users/edit/:id', to: 'users#edit', as: 'edit_user'
17
+ post '/users/edit/:id', to: 'users#update', as: 'update_user'
18
+ get '/users/delete/:id', to: 'users#delete', as: 'delete_user'
19
+ get '/user/:id', to: 'users#show', as: 'user'
20
+
21
+ get '/data_bags/:bag/items/new', to: 'data_bag_items#new', as: 'new_data_bag_item'
22
+ post '/data_bags/:bag/items/new', to: 'data_bag_items#create', as: 'create_data_bag_item'
23
+ get '/data_bags/:bag/items/:item/edit', to: 'data_bag_items#edit', as: 'edit_data_bag_item'
24
+ post '/data_bags/:bag/items/:item/edit', to: 'data_bag_items#update', as: 'update_data_bag_item'
25
+ get '/data_bags/:bag/items/:item', to: 'data_bag_items#index', as: 'data_bag_items'
26
+
27
+ get '/data_bags/:bag/template', to: 'data_bag_templates#show', as: 'data_bag_template'
28
+
29
+ post '/data_bags/:bag/template/item', to: 'data_bag_template_items#create', as: 'create_data_bag_template_item'
30
+ post '/data_bags/:bag/template/item/delete', to: 'data_bag_template_items#delete', as: 'delete_data_bag_template_item'
31
+
32
+ get '/data_bags', to: 'data_bags#index', as: 'data_bags'
33
+ get '/data_bags/new', to: 'data_bags#new', as: 'new_data_bag'
34
+ post '/data_bags/new', to: 'data_bags#create', as: 'create_data_bag'
35
+ get '/data_bags/:bag', to: 'data_bags#show', as: 'data_bag'
36
+
37
+ end
@@ -0,0 +1,10 @@
1
+ class CreateBagboyUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :bagboy_users do |t|
4
+ t.string :username
5
+ t.string :email
6
+ t.string :password_digest
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ class CreateBagboyTemplates < ActiveRecord::Migration
2
+ def change
3
+ create_table :bagboy_templates do |t|
4
+ t.text :data
5
+ t.string :data_bag_name
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ require 'bagboy/engine'
2
+ require 'bagboy/core/file_helper'
3
+ require 'bagboy/core/scm_helper'
4
+ require 'bagboy/chef/knife'
5
+ require 'bagboy/chef/data_bags_helper'
6
+
7
+ module Bagboy
8
+ mattr_accessor :chef_repo, :site_name, :password_hash, :scm, :key_path, :config_path
9
+
10
+ self.chef_repo = ''
11
+ self.site_name = 'Bagboy'
12
+ self.password_hash = ''
13
+ self.scm = 'none'
14
+ self.key_path = ''
15
+ self.config_path = ''
16
+
17
+ def self.config(&block)
18
+ yield(self)
19
+ end
20
+
21
+ end
@@ -0,0 +1,74 @@
1
+ module Bagboy
2
+ module Chef
3
+ module DataBags
4
+ class Bag
5
+
6
+ attr_reader :name
7
+
8
+ def initialize( opts = {} )
9
+ @path = opts[:path] || ''
10
+ @name = opts[:name] || ''
11
+ @file = opts[:file] || Core::FileHelper.instance
12
+ @scm = opts[:scm] || Core::SCMHelper.instance
13
+ @knife = opts[:knife] || Bagboy::Chef::Knife.instance
14
+ end
15
+
16
+ def items
17
+ get_items @file.get_files( @path )
18
+ end
19
+
20
+ def item( name )
21
+ name = name.gsub(/[^\w\-]/, '_')
22
+ path = item_path( name + '.json' )
23
+ Item.new( {path: path, name: name, bag: @name} )
24
+ end
25
+
26
+ def create
27
+ pull
28
+ if unique?
29
+ Dir.mkdir @path
30
+ sync
31
+ true
32
+ else
33
+ false
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def sync
40
+ @knife.create_data_bag @name
41
+ end
42
+
43
+ def pull
44
+ @scm.pull
45
+ end
46
+
47
+ def get_items( items )
48
+ data_items = []
49
+ items.each do |item|
50
+ path = item_path item
51
+ name = item.sub('.json', '')
52
+ data_items << Item.new( {path: path, name: name} )
53
+ end
54
+ data_items
55
+ end
56
+
57
+ def item_path ( item )
58
+ File.join( @path, item )
59
+ end
60
+
61
+ def unique?
62
+ return false if @name == ''
63
+ return false if @file.get_files(data_bags_path).include?(@name)
64
+ true
65
+ end
66
+
67
+ def data_bags_path
68
+ File.expand_path( File.join(@path, '/..'))
69
+ end
70
+
71
+ end
72
+ end
73
+ end
74
+ end