knife-axe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ knife-axe
2
+ =========
3
+
4
+ installation:
5
+ ```
6
+ $ gem install diffy
7
+ $ cp axe*.rb ~/.chef/plugins/knife
8
+ ```
9
+ usage:
10
+ ```
11
+ $ knife axe role ~/chef-repo/role/role42.rb
12
+ $ knife axe env ~/chef-repo/environments/environment42.rb
13
+ $ knife axe data bag databagname ~/chef-repo/data_bags/databagname/item42.rb
14
+ ```
15
+
@@ -0,0 +1,53 @@
1
+ class Chef
2
+ class Knife
3
+ class AxeDataBag < Chef::Knife
4
+ deps do
5
+ require 'json'
6
+ require 'diffy'
7
+ require 'chef/knife/core/object_loader'
8
+ end
9
+
10
+ banner 'knife axe data bag DATABAG FILENAME'
11
+
12
+ def run
13
+ if @name_args[0].nil?
14
+ show_usage
15
+ ui.fatal("You must specify a data bag")
16
+ exit 1
17
+ end
18
+
19
+ if @name_args[1].nil?
20
+ show_usage
21
+ ui.fatal("You must specify a item file")
22
+ exit 1
23
+ end
24
+
25
+ loader = Chef::Knife::Core::ObjectLoader.new(Chef::DataBagItem, ui)
26
+
27
+ item_name = File.basename(@name_args[1]).split('.')[0]
28
+ item_ff = loader.load_from("data_bags", databag, item_file)
29
+ item_fc = Chef::DataBagItem.load(databag, item_ff.to_hash["id"]).raw_data
30
+
31
+ dbag = Chef::DataBagItem.new
32
+ dbag.data_bag(@name_args[0])
33
+
34
+ diff = Diffy::Diff.new(
35
+ JSON.pretty_generate(item_fc.to_hash),
36
+ JSON.pretty_generate(item_ff.to_hash),
37
+ :context => 1)
38
+
39
+ if diff.to_s(:text).empty?
40
+ ui.warn("Role #{role_fc.name} has not been changed")
41
+ else
42
+ puts "You are going to update data bag #{databag}/#{item_name}:"
43
+ puts "\n#{diff.to_s(:color)}\n"
44
+
45
+ ui.confirm("Continue")
46
+ dbag.raw_data = item_ff
47
+ dbag.save
48
+ ui.msg("Saved new version of data bag item #{databag}/#{item_name}")
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,58 @@
1
+ class Chef
2
+ class Knife
3
+ class AxeEnv < Chef::Knife
4
+ deps do
5
+ require 'json'
6
+ require 'diffy'
7
+ require 'chef/knife/core/object_loader'
8
+ end
9
+
10
+ banner 'knife axe env FILENAME'
11
+
12
+ def yesno
13
+ puts "Continue? [y/n]"
14
+ yn = STDIN.gets.chomp()
15
+ if yn == 'y' or yn == 'Y'
16
+ return 0
17
+ elsif yn == 'n' or yn == 'N'
18
+ puts "You chose 'n'. I'm done here."
19
+ exit 0
20
+ else
21
+ yesno
22
+ end
23
+ end
24
+
25
+ def run
26
+ if @name_args[0].nil?
27
+ show_usage
28
+ ui.fatal("You must specify a environment file")
29
+ exit 1
30
+ end
31
+
32
+ loader = Chef::Knife::Core::ObjectLoader.new(Chef::Environment, ui)
33
+
34
+ @name_args.each do |env_file|
35
+ env_name = File.basename(env_file).split('.')[0]
36
+ env_ff = loader.load_from("environments", env_file)
37
+ env_fc = Chef::Environment.load(env_ff.to_hash["name"])
38
+
39
+ diff = Diffy::Diff.new(
40
+ JSON.pretty_generate(env_fc.to_hash),
41
+ JSON.pretty_generate(env_ff.to_hash),
42
+ :context => 1)
43
+
44
+ if diff.to_s(:text).empty?
45
+ ui.warn("Environment #{env_fc.name} has not been changed")
46
+ else
47
+ puts "You are going to update environment #{env_name}:"
48
+ puts "\n#{diff.to_s(:color)}\n"
49
+
50
+ ui.confirm("Continue")
51
+ env_ff.save
52
+ ui.msg("Saved new version of environment #{env_fc.name}")
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,45 @@
1
+ class Chef
2
+ class Knife
3
+ class AxeRole < Chef::Knife
4
+ deps do
5
+ require 'json'
6
+ require 'diffy'
7
+ require 'chef/knife/core/object_loader'
8
+ end
9
+
10
+ banner 'knife axe role FILE'
11
+
12
+ def run
13
+ if @name_args[0].nil?
14
+ show_usage
15
+ ui.fatal("You must specify a role file")
16
+ exit 1
17
+ end
18
+
19
+ loader = Chef::Knife::Core::ObjectLoader.new(Chef::Role, ui)
20
+
21
+ @name_args.each do |role_file|
22
+ role_name = File.basename(role_file).split('.')[0]
23
+ role_ff = loader.load_from("roles", role_file)
24
+ role_fc = Chef::Role.load(role_ff.to_hash["name"])
25
+
26
+ diff = Diffy::Diff.new(
27
+ JSON.pretty_generate(role_fc.to_hash),
28
+ JSON.pretty_generate(role_ff.to_hash),
29
+ :context => 1)
30
+
31
+ if diff.to_s(:text).empty?
32
+ ui.warn("Role #{role_fc.name} has not been changed")
33
+ else
34
+ puts "You are going to update role #{role_fc.name}:"
35
+ puts "\n#{diff.to_s(:color)}\n"
36
+
37
+ ui.confirm("Continue")
38
+ role_ff.save
39
+ ui.msg("Saved new version of role #{role_fc.name}")
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: knife-axe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Marcin Cabaj
9
+ - Sam Clements
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-01-27 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: diffy
17
+ requirement: !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 3.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ version: 3.0.1
31
+ description: ''
32
+ email:
33
+ - marcin.cabaj@datasift.com
34
+ - sam.clements@datasift.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - lib/chef/knife/axe_env.rb
40
+ - lib/chef/knife/axe_databag.rb
41
+ - lib/chef/knife/axe_role.rb
42
+ - README.md
43
+ homepage: https://github.com/faja/knife-axe
44
+ licenses:
45
+ - ''
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 1.8.25
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: ''
68
+ test_files: []