bagboy 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 (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,50 @@
1
+ require_dependency "bagboy/application_controller"
2
+
3
+ module Bagboy
4
+ class DataBagItemsController < ApplicationController
5
+
6
+ def index
7
+ @bag = @bag_helper.data_bag( params[:bag] )
8
+ @item = @bag.item( params[:item] )
9
+
10
+ render :index
11
+ end
12
+
13
+ def edit
14
+ @bag = @bag_helper.data_bag( params[:bag] )
15
+ @item = @bag.item( params[:item] )
16
+ @template = Template::find_or_create_by({data_bag_name: @bag.name})
17
+
18
+ render :edit
19
+ end
20
+
21
+ def update
22
+ @bag = @bag_helper.data_bag( params[:bag] )
23
+ @item = @bag.item( params[:item] )
24
+ @template = Template::find_or_create_by({data_bag_name: @bag.name})
25
+
26
+ @item.update params[:data_bag_template_item].permit!, @template.parsed_data
27
+
28
+ redirect_to data_bag_items_path({bag: @bag.name, item: @item.name})
29
+ end
30
+
31
+ def new
32
+ @bag = @bag_helper.data_bag( params[:bag] )
33
+ @item = Chef::DataBags::Item.new
34
+ @template = Template::find_or_create_by({data_bag_name: @bag.name})
35
+
36
+ render :new
37
+ end
38
+
39
+ def create
40
+ @bag = @bag_helper.data_bag( params[:bag] )
41
+ @item = @bag.item params[:data_bag_template_item][:name]
42
+ @template = Template::find_or_create_by({data_bag_name: @bag.name})
43
+
44
+ @item.update params[:data_bag_template_item_data].permit!, @template.parsed_data
45
+
46
+ redirect_to data_bag_items_path({bag: @bag.name, item: @item.name})
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,25 @@
1
+ require_dependency "bagboy/application_controller"
2
+
3
+ module Bagboy
4
+ class DataBagTemplateItemsController < ApplicationController
5
+
6
+ def create
7
+ bag = @bag_helper.data_bag params[:bag]
8
+ template = Template::find_or_create_by({data_bag_name: bag.name})
9
+
10
+ template.item( params[:data_bag_template_item][:name], params[:data_bag_template_item][:type] )
11
+
12
+ redirect_to data_bag_template_path( bag.name )
13
+ end
14
+
15
+ def delete
16
+ bag = @bag_helper.data_bag params[:bag]
17
+ template = Template::find_or_create_by({data_bag_name: bag.name})
18
+
19
+ template.delete_item( params[:data_bag_template_item][:name] )
20
+
21
+ redirect_to data_bag_template_path( bag.name )
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ require_dependency "bagboy/application_controller"
2
+
3
+ module Bagboy
4
+ class DataBagTemplatesController < ApplicationController
5
+
6
+ def show
7
+ @bag = @bag_helper.data_bag( params[:bag] )
8
+ @template = Template::find_or_create_by({data_bag_name: @bag.name})
9
+ render :show
10
+ end
11
+
12
+ def edit
13
+ render :edit
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ require_dependency "bagboy/application_controller"
2
+
3
+ module Bagboy
4
+ class DataBagsController < ApplicationController
5
+
6
+ def index
7
+ render :index
8
+ end
9
+
10
+ def show
11
+ @bag = @bag_helper.data_bag params[:bag]
12
+ @items = @bag.items
13
+ render :show
14
+ end
15
+
16
+ def new
17
+ @bag = Bagboy::Chef::DataBags::Bag.new
18
+ render :new
19
+ end
20
+
21
+ def create
22
+ opts = data_bag_params
23
+ opts[:path] = @bag_helper.data_bag_directory( opts[:name] )
24
+ @bag = Bagboy::Chef::DataBags::Bag.new( opts )
25
+
26
+ if @bag.create
27
+ redirect_to data_bags_path
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ private
34
+
35
+ def data_bag_params
36
+ params.require(:data_bag).permit(:name, :path)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,20 @@
1
+ require_dependency "bagboy/application_controller"
2
+
3
+ module Bagboy
4
+ class PagesController < ApplicationController
5
+
6
+ def index
7
+ render :index
8
+ end
9
+
10
+ def update
11
+ if @scm.pull
12
+ flash = { success: 'You have successfully updated your chef-repo' }
13
+ else
14
+ flash = { error: 'Something went wrong' }
15
+ end
16
+ redirect_to request.referer, flash: flash
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ require_dependency "bagboy/application_controller"
2
+
3
+ module Bagboy
4
+ class SessionsController < ApplicationController
5
+
6
+ def new
7
+ render 'new'
8
+ end
9
+
10
+ def create
11
+ user = Bagboy::User.find_by_email(params[:email])
12
+ if user && user.authenticate(params[:password])
13
+ session[:user_id] = user.id
14
+ redirect_to root_url, flash: {success: 'You have successfuly logged in!'}
15
+ else
16
+ flash.now.alert = 'Invalid email or password'
17
+ render "new"
18
+ end
19
+ end
20
+
21
+ def destroy
22
+ session[:user_id] = nil
23
+ redirect_to root_url, flash: { success: 'You have successfuly logged out!'}
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,58 @@
1
+ require_dependency "bagboy/application_controller"
2
+
3
+ module Bagboy
4
+ class UsersController < ApplicationController
5
+
6
+ def show
7
+ @user = Bagboy::User.find(params[:id])
8
+ render :show
9
+ end
10
+
11
+ def index
12
+ @users = Bagboy::User.all
13
+ render :index
14
+ end
15
+
16
+ def new
17
+ @user = Bagboy::User.new
18
+ render :new
19
+ end
20
+
21
+ def create
22
+ @user = Bagboy::User.new(user_params)
23
+ if @user.save
24
+ redirect_to users_path, flash: { success: "You have succesfully created #{@user.email}"}
25
+ else
26
+ render 'new'
27
+ end
28
+ end
29
+
30
+ def edit
31
+ @user = Bagboy::User.find(params[:id])
32
+ render :edit
33
+ end
34
+
35
+ def update
36
+ @user = Bagboy::User.find(params[:id])
37
+ @user.update_attributes( user_params )
38
+ if ( @user.save )
39
+ redirect_to user_path( @user.id ), flash: { success: "You have succesfully updated #{@user.email}!"}
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ def delete
46
+ @user = Bagboy::User.find(params[:id])
47
+ @user.delete
48
+ redirect_to users_path, flash: { success: "#{@user.email} successfuly deleted!"}
49
+ end
50
+
51
+ private
52
+
53
+ def user_params
54
+ params.require(:user).permit(:email, :password, :password_confirmation)
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,4 @@
1
+ module Bagboy
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Bagboy
2
+ module PagesHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Bagboy
2
+ module SessionsHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Bagboy
2
+ module UsersHelper
3
+ end
4
+ end
@@ -0,0 +1,33 @@
1
+ module Bagboy
2
+ class Template < ActiveRecord::Base
3
+
4
+ before_save :check_id
5
+
6
+ def check_id
7
+ data = parsed_data
8
+ data['id'] = 'text' if data['id'] == nil
9
+ self.data = data.to_json
10
+ end
11
+
12
+ def parsed_data
13
+ self.data ||= '{}'
14
+ JSON.parse( self.data )
15
+ end
16
+
17
+ def item ( key, value )
18
+ data = parsed_data
19
+ data[key.downcase] = value
20
+ data = Hash[data.sort_by { |key, value| key }]
21
+ self.data = data.to_json
22
+ save
23
+ end
24
+
25
+ def delete_item ( key )
26
+ data = parsed_data
27
+ data.delete key
28
+ self.data = data.to_json
29
+ save
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,9 @@
1
+ module Bagboy
2
+ class User < ActiveRecord::Base
3
+ has_secure_password
4
+
5
+ validates_uniqueness_of :email
6
+ validates_presence_of :email
7
+ validates_presence_of :password, on: :create
8
+ end
9
+ end
@@ -0,0 +1,20 @@
1
+ - template.parsed_data.each do |key, value|
2
+ .row
3
+ .large-2.columns
4
+ %label.right.inline{ for: "#{namespace}_#{key}" }= key
5
+ .large-10.columns
6
+ - if value == 'text'
7
+ %input{ type: 'text', id: "#{namespace}_#{key}", name: "#{namespace}[#{key}]", placeholder: '', value: item.data[key] || '' }
8
+ - elsif value == 'password'
9
+ %input{ type: 'text', id: "#{namespace}_#{key}", name: "#{namespace}[#{key}]", placeholder: '', value: '' }
10
+ %span.secondary.label{ style: 'margin-bottom: 1em'} Leave blank to not change password
11
+ - elsif value == 'array'
12
+ - @item.data[key].to_a.each do |data_item|
13
+ %input{ type: 'text', id: "#{namespace}_#{key}", name: "#{namespace}[#{key}][]", placeholder: '', value: data_item || '' }
14
+ %div{id: "array_#{key}"}
15
+ - div_id = "#array_#{key}"
16
+ - id = "#{namespace}_#{key}"
17
+ - name = "#{namespace}[#{key}][]"
18
+ %a.button.tiny.success{ href: '#', id: "array_button_#{key}", onclick: "addElement('#{div_id}','#{id}','#{name}')" }
19
+ %i.fa.fa-plus
20
+ Add Item
@@ -0,0 +1,18 @@
1
+ %h1= "Editing #{@item.name}"
2
+
3
+ .button-bar
4
+ %ul.button-group
5
+ %li
6
+ %a.button.tiny{href: data_bag_items_path({bag: @bag.name, item: @item.name})}= "Back to #{@item.name}"
7
+ %ul.button-group
8
+ %li
9
+ %a.button.tiny{href: data_bag_path(@bag.name)}= "Back to #{@bag.name}"
10
+
11
+ %hr
12
+
13
+ %form{ action: update_data_bag_item_path({bag: @bag.name, item: @item.name}), method: 'post' }
14
+ = render 'form', template: @template, item: @item, namespace: 'data_bag_template_item'
15
+ .row
16
+ .large-2.columns
17
+ .large-10.columns
18
+ %button.button.small{ type: 'submit' } Submit
@@ -0,0 +1,29 @@
1
+ %h1= "Item: #{@item.name}"
2
+ %h3.subheader= "From #{@bag.name} data bag"
3
+
4
+ .button-bar
5
+ %ul.button-group
6
+ %li
7
+ %a.button.tiny{href: edit_data_bag_item_path({bag: @bag.name, item: @item.name})} Edit
8
+ %ul.button-group
9
+ %li
10
+ %a.button.tiny{href: data_bag_path(@bag.name)}= "Back to #{@bag.name}"
11
+
12
+ %hr
13
+
14
+ %table
15
+ %thead
16
+ %tr
17
+ %th{ width: '200' } Key
18
+ %th Value
19
+ %tbody
20
+ - @item.data.each do |key, value|
21
+ %tr
22
+ %td= key
23
+ %td
24
+ - if value.kind_of?(Array)
25
+ %ul
26
+ - value.each do |value_item|
27
+ %li= value_item
28
+ - else
29
+ = value
@@ -0,0 +1,22 @@
1
+ %h1 New Item
2
+
3
+ .button-bar
4
+ %ul.button-group
5
+ %li
6
+ %a.button.tiny{href: data_bag_path(@bag.name)}= "Back to #{@bag.name}"
7
+
8
+ %hr
9
+
10
+ %form{ action: create_data_bag_item_path({bag: @bag.name}), method: 'post' }
11
+ .row
12
+ .large-2.columns
13
+ %label.right.inline{ for: "data_bag_template_item" } Name
14
+ .large-10.columns
15
+ %input{ type: 'text', id: "data_bag_template_item", name: "data_bag_template_item[name]"}
16
+ %hr
17
+ = render 'form', template: @template, item: @item, namespace: 'data_bag_template_item_data'
18
+
19
+ .row
20
+ .large-2.columns
21
+ .large-10.columns
22
+ %button.button.small{ type: 'submit' } Submit
@@ -0,0 +1,45 @@
1
+ %h1= "Template for #{@bag.name}"
2
+
3
+ %hr
4
+
5
+ - unless @template.parsed_data.empty?
6
+ %table
7
+ %thead
8
+ %tr
9
+ %td Field Name
10
+ %td Field Type
11
+ %td
12
+ %tbody
13
+ - @template.parsed_data.each do |key, value|
14
+ %tr
15
+ %td= key
16
+ %td= value
17
+ %td
18
+ %form.tabled{ action: delete_data_bag_template_item_path, method: 'post' }
19
+ %input{ type: 'hidden', name: 'data_bag_template_item[name]', value: key }
20
+ %button.button.alert.tiny{ type: 'submit' } Delete
21
+ - else
22
+ No Fields
23
+
24
+ %hr
25
+
26
+ %h3 New Field
27
+ %form{ action: create_data_bag_template_item_path, method: 'post' }
28
+ .row
29
+ .large-2.columns
30
+ %label.right.inline{ for: 'data_bag_template_item_name' } Name
31
+ .large-10.columns
32
+ %input{ type: 'text', id: 'data_bag_template_item_name', name: 'data_bag_template_item[name]', placeholder: 'Name' }
33
+ .row
34
+ .large-2.columns
35
+ %label.right.inline{ for: 'data_bag_template_item_type' } Type
36
+ .large-10.columns
37
+ %select{ id: 'data_bag_template_item_type', name: 'data_bag_template_item[type]'}
38
+ %option{value: "text"} Text
39
+ %option{value: "array"} Array
40
+ %option{value: "password"} Password
41
+
42
+ .row
43
+ .large-2.columns
44
+ .large-10.columns
45
+ %button.button.small{ type: 'submit' } Submit