knife-solo_data_bag 1.0.0.beta.1 → 1.0.0.beta.2

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.
data/.gitignore CHANGED
@@ -16,3 +16,6 @@ spec/reports
16
16
  test/tmp
17
17
  test/version_tmp
18
18
  tmp
19
+ .kitchen/
20
+ .kitchen.local.yml
21
+ test/integration/data/packages
@@ -0,0 +1,13 @@
1
+ ---
2
+ driver:
3
+ name: vagrant
4
+
5
+ provisioner:
6
+ name: shell
7
+ script: test/integration/bootstrap.sh
8
+
9
+ platforms:
10
+ - name: centos-6.4
11
+
12
+ suites:
13
+ - name: default
data/Gemfile CHANGED
@@ -2,3 +2,6 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in knife-solo_data_bag.gemspec
4
4
  gemspec
5
+
6
+ gem 'test-kitchen', '~> 1.2'
7
+ gem 'kitchen-vagrant'
data/Rakefile CHANGED
@@ -9,3 +9,10 @@ desc 'Run specs'
9
9
  RSpec::Core::RakeTask.new do |t|
10
10
  t.rspec_opts = %w(-fs --color)
11
11
  end
12
+
13
+ begin
14
+ require 'kitchen/rake_tasks'
15
+ Kitchen::RakeTasks.new
16
+ rescue LoadError
17
+ puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI']
18
+ end
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'chef', '11.10.0'
4
+
5
+ gemspec :path => "../"
@@ -1,5 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'chef', '~> 11.4.4'
3
+ gem 'chef', '11.4.4'
4
4
 
5
5
  gemspec :path => "../"
@@ -1,5 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'chef', '~> 11.6.2'
3
+ gem 'chef', '11.6.2'
4
4
 
5
5
  gemspec :path => "../"
@@ -1,5 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'chef', '~> 11.8.0'
3
+ gem 'chef', '11.8.0'
4
4
 
5
5
  gemspec :path => "../"
@@ -1,5 +1,5 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'chef', '~> 11.8.2'
3
+ gem 'chef', '11.8.2'
4
4
 
5
5
  gemspec :path => "../"
@@ -19,6 +19,12 @@ module KnifeSoloDataBag
19
19
  Chef::Config[:data_bag_path]
20
20
  end
21
21
 
22
+ def persist_bag_item(item)
23
+ File.open bag_item_path, 'w' do |f|
24
+ f.write JSON.pretty_generate(item.raw_data)
25
+ end
26
+ end
27
+
22
28
  def secret_path
23
29
  Chef::Config[:encrypted_data_bag_secret]
24
30
  end
@@ -1,93 +1,95 @@
1
- module KnifeSoloDataBag
1
+ require 'chef/knife'
2
2
 
3
- class SoloDataBagCreate < Chef::Knife
3
+ class Chef
4
+ class Knife
4
5
 
5
- require 'chef/data_bag'
6
- require 'chef/encrypted_data_bag_item'
7
- require 'chef/knife/helpers'
8
- require 'fileutils'
6
+ class SoloDataBagCreate < Knife
9
7
 
10
- include KnifeSoloDataBag::Helpers
8
+ deps do
9
+ require 'chef/data_bag'
10
+ require 'fileutils'
11
+ require 'chef/encrypted_data_bag_item'
12
+ require 'chef/json_compat'
13
+ require 'chef/knife/helpers'
14
+ end
11
15
 
12
- banner 'knife solo data bag create BAG [ITEM] (options)'
13
- category 'solo data bag'
16
+ require 'chef/knife/solo_data_bag_helpers'
17
+ include Chef::Knife::SoloDataBagHelpers
14
18
 
15
- attr_reader :bag_name, :item_name
19
+ banner 'knife solo data bag create BAG [ITEM] (options)'
20
+ category 'solo data bag'
16
21
 
17
- option :secret,
18
- :short => '-s SECRET',
19
- :long => '--secret SECRET',
20
- :description => 'The secret key to use to encrypt data bag item values'
22
+ attr_reader :bag_name, :item_name
21
23
 
22
- option :secret_file,
23
- :long => '--secret-file SECRET_FILE',
24
- :description => 'A file containing the secret key to use to encrypt data bag item values'
24
+ option :secret,
25
+ :short => '-s SECRET',
26
+ :long => '--secret SECRET',
27
+ :description => 'The secret key to use to encrypt data bag item values'
25
28
 
26
- option :json_string,
27
- :short => '-j JSON_STRING',
28
- :long => '--json JSON_STRING',
29
- :description => 'The data bag json string that can be passed at the CLI'
29
+ option :secret_file,
30
+ :long => '--secret-file SECRET_FILE',
31
+ :description => 'A file containing the secret key to use to encrypt data bag item values'
30
32
 
31
- option :json_file,
32
- :long => '--json-file JSON_FILE',
33
- :description => 'A file contining the data bag json string'
33
+ option :json_string,
34
+ :short => '-j JSON_STRING',
35
+ :long => '--json JSON_STRING',
36
+ :description => 'The data bag json string that can be passed at the CLI'
34
37
 
35
- option :data_bag_path,
36
- :long => '--data-bag-path DATA_BAG_PATH',
37
- :description => 'The path to data bag'
38
+ option :json_file,
39
+ :long => '--json-file JSON_FILE',
40
+ :description => 'A file contining the data bag json string'
38
41
 
39
- def run
40
- @bag_name, @item_name = @name_args
41
- ensure_valid_arguments
42
- create_bag_directory
43
- create_bag_item if item_name
44
- end
42
+ option :data_bag_path,
43
+ :long => '--data-bag-path DATA_BAG_PATH',
44
+ :description => 'The path to data bag'
45
45
 
46
- private
47
- def bag_item_content(content)
48
- return content unless should_be_encrypted?
49
- Chef::EncryptedDataBagItem.encrypt_data_bag_item content, secret_key
50
- end
46
+ def run
47
+ @bag_name, @item_name = @name_args
48
+ ensure_valid_arguments
49
+ create_bag_directory
50
+ create_bag_item if item_name
51
+ end
51
52
 
52
- def create_bag_directory
53
- FileUtils.mkdir_p bag_path unless File.exists? bag_path
54
- end
53
+ private
54
+ def bag_item_content(content)
55
+ return content unless should_be_encrypted?
56
+ Chef::EncryptedDataBagItem.encrypt_data_bag_item content, secret_key
57
+ end
55
58
 
56
- def create_item_object
57
- item = nil
58
- case
59
- when config[:json_string]
60
- item = Chef::DataBagItem.from_hash bag_item_content(convert_json_string)
61
- when config[:json_file]
62
- json_string = JSON.parse(File.read(config[:json_file]))
63
- item = Chef::DataBagItem.from_hash bag_item_content(json_string)
64
- else
65
- create_object({'id' => item_name}, "data_bag_item[#{item_name}]") do |output|
66
- item = Chef::DataBagItem.from_hash bag_item_content(output)
67
- end
59
+ def create_bag_directory
60
+ FileUtils.mkdir_p bag_path unless File.exists? bag_path
68
61
  end
69
- item
70
- end
71
62
 
72
- def create_bag_item
73
- item = create_item_object
74
- item.data_bag bag_name
75
- persist_bag_item item
76
- end
63
+ def create_item_object
64
+ item = nil
65
+ case
66
+ when config[:json_string]
67
+ item = Chef::DataBagItem.from_hash bag_item_content(convert_json_string)
68
+ when config[:json_file]
69
+ json_string = JSON.parse(File.read(config[:json_file]))
70
+ item = Chef::DataBagItem.from_hash bag_item_content(json_string)
71
+ else
72
+ create_object({'id' => item_name}, "data_bag_item[#{item_name}]") do |output|
73
+ item = Chef::DataBagItem.from_hash bag_item_content(output)
74
+ end
75
+ end
76
+ item
77
+ end
77
78
 
78
- def ensure_valid_arguments
79
- validate_bag_name_provided
80
- validate_bags_path_exists
81
- validate_multiple_secrets_were_not_provided
82
- validate_json_string unless config[:json_string].nil?
83
- end
79
+ def create_bag_item
80
+ item = create_item_object
81
+ item.data_bag bag_name
82
+ persist_bag_item item
83
+ end
84
84
 
85
- def persist_bag_item(item)
86
- File.open bag_item_path, 'w' do |f|
87
- f.write item.to_json
85
+ def ensure_valid_arguments
86
+ validate_bag_name_provided
87
+ validate_bags_path_exists
88
+ validate_multiple_secrets_were_not_provided
89
+ validate_json_string unless config[:json_string].nil?
88
90
  end
91
+
89
92
  end
90
93
 
91
94
  end
92
-
93
95
  end
@@ -1,77 +1,78 @@
1
- module KnifeSoloDataBag
1
+ require 'chef/knife'
2
2
 
3
- class SoloDataBagEdit < Chef::Knife
3
+ class Chef
4
+ class Knife
4
5
 
5
- require 'chef/knife/helpers'
6
+ class SoloDataBagEdit < Knife
6
7
 
7
- include KnifeSoloDataBag::Helpers
8
+ deps do
9
+ require 'chef/knife/helpers'
10
+ require 'chef/knife/solo_data_bag_helpers'
11
+ end
8
12
 
9
- banner 'knife solo data bag edit BAG ITEM (options)'
10
- category 'solo data bag'
13
+ include Chef::Knife::SoloDataBagHelpers
11
14
 
12
- attr_reader :bag_name, :item_name
15
+ banner 'knife solo data bag edit BAG ITEM (options)'
16
+ category 'solo data bag'
13
17
 
14
- option :secret,
15
- :short => '-s SECRET',
16
- :long => '--secret SECRET',
17
- :description => 'The secret key to use to encrypt data bag item values'
18
+ attr_reader :bag_name, :item_name
18
19
 
19
- option :secret_file,
20
- :long => '--secret-file SECRET_FILE',
21
- :description => 'A file containing the secret key to use to encrypt data bag item values'
20
+ option :secret,
21
+ :short => '-s SECRET',
22
+ :long => '--secret SECRET',
23
+ :description => 'The secret key to use to encrypt data bag item values'
22
24
 
23
- option :data_bag_path,
24
- :long => '--data-bag-path DATA_BAG_PATH',
25
- :description => 'The path to data bag'
25
+ option :secret_file,
26
+ :long => '--secret-file SECRET_FILE',
27
+ :description => 'A file containing the secret key to use to encrypt data bag item values'
26
28
 
27
- def run
28
- Chef::Config[:solo] = true
29
- @bag_name, @item_name = @name_args
30
- ensure_valid_arguments
31
- edit_content
32
- end
29
+ option :data_bag_path,
30
+ :long => '--data-bag-path DATA_BAG_PATH',
31
+ :description => 'The path to data bag'
33
32
 
34
- private
35
- def edit_content
36
- updated_content = edit_data existing_bag_item_content
37
- item = Chef::DataBagItem.from_hash format_editted_content(updated_content)
38
- item.data_bag bag_name
39
- persist_bag_item item
40
- end
33
+ def run
34
+ Chef::Config[:solo] = true
35
+ @bag_name, @item_name = @name_args
36
+ ensure_valid_arguments
37
+ edit_content
38
+ end
41
39
 
42
- def existing_bag_item_content
43
- content = Chef::DataBagItem.load(bag_name, item_name).raw_data
40
+ private
41
+ def edit_content
42
+ updated_content = edit_data existing_bag_item_content
43
+ item = Chef::DataBagItem.from_hash format_editted_content(updated_content)
44
+ item.data_bag bag_name
45
+ persist_bag_item item
46
+ end
44
47
 
45
- return content unless should_be_encrypted?
46
- Chef::EncryptedDataBagItem.new(content, secret_key).to_hash
47
- end
48
+ def existing_bag_item_content
49
+ content = Chef::DataBagItem.load(bag_name, item_name).raw_data
48
50
 
49
- def format_editted_content(content)
50
- return content unless should_be_encrypted?
51
- Chef::EncryptedDataBagItem.encrypt_data_bag_item content, secret_key
52
- end
51
+ return content unless should_be_encrypted?
52
+ Chef::EncryptedDataBagItem.new(content, secret_key).to_hash
53
+ end
53
54
 
54
- def ensure_valid_arguments
55
- validate_bag_name_provided
56
- validate_item_name_provided
57
- validate_bags_path_exists
58
- validate_multiple_secrets_were_not_provided
59
- end
55
+ def format_editted_content(content)
56
+ return content unless should_be_encrypted?
57
+ Chef::EncryptedDataBagItem.encrypt_data_bag_item content, secret_key
58
+ end
60
59
 
61
- def persist_bag_item(item)
62
- File.open bag_item_path, 'w' do |f|
63
- f.write JSON.pretty_generate(JSON.parse(item.to_json))
60
+ def ensure_valid_arguments
61
+ validate_bag_name_provided
62
+ validate_item_name_provided
63
+ validate_bags_path_exists
64
+ validate_multiple_secrets_were_not_provided
64
65
  end
65
- end
66
66
 
67
- def validate_item_name_provided
68
- unless item_name
69
- show_usage
70
- ui.fatal 'You must supply a name for the item'
71
- exit 1
67
+ def validate_item_name_provided
68
+ unless item_name
69
+ show_usage
70
+ ui.fatal 'You must supply a name for the item'
71
+ exit 1
72
+ end
72
73
  end
74
+
73
75
  end
74
76
 
75
77
  end
76
-
77
78
  end
@@ -0,0 +1,83 @@
1
+ require 'chef/knife'
2
+
3
+ class Chef
4
+ class Knife
5
+
6
+ module SoloDataBagHelpers
7
+
8
+ def bag_item_path
9
+ File.expand_path File.join(bag_path, "#{item_name}.json")
10
+ end
11
+
12
+ def bag_path
13
+ File.expand_path File.join(bags_path, bag_name)
14
+ end
15
+
16
+ def bags_path
17
+ if config[:data_bag_path]
18
+ Chef::Config[:data_bag_path] = config[:data_bag_path]
19
+ end
20
+
21
+ Chef::Config[:data_bag_path]
22
+ end
23
+
24
+ def persist_bag_item(item)
25
+ File.open bag_item_path, 'w' do |f|
26
+ f.write JSON.pretty_generate(item.raw_data)
27
+ end
28
+ end
29
+
30
+ def secret_path
31
+ Chef::Config[:encrypted_data_bag_secret]
32
+ end
33
+
34
+ def secret_key
35
+ return config[:secret] if config[:secret]
36
+ Chef::EncryptedDataBagItem.load_secret(config[:secret_file] || secret_path)
37
+ end
38
+
39
+ def should_be_encrypted?
40
+ config[:secret] || config[:secret_file] || secret_path
41
+ end
42
+
43
+ def convert_json_string
44
+ JSON.parse config[:json_string]
45
+ end
46
+
47
+ def validate_bag_name_provided
48
+ unless bag_name
49
+ show_usage
50
+ ui.fatal 'You must supply a name for the data bag'
51
+ exit 1
52
+ end
53
+ end
54
+
55
+ def validate_bags_path_exists
56
+ unless File.directory? bags_path
57
+ raise Chef::Exceptions::InvalidDataBagPath,
58
+ "Configured data bag path '#{bags_path}' is invalid"
59
+ end
60
+ end
61
+
62
+ def validate_json_string
63
+ begin
64
+ JSON.parse config[:json_string], :create_additions => false
65
+ rescue => error
66
+ raise "Syntax error in #{config[:json_string]}: #{error.message}"
67
+ end
68
+ end
69
+
70
+ def validate_multiple_secrets_were_not_provided
71
+ if config[:secret] && config[:secret_file]
72
+ show_usage
73
+ ui.fatal 'Please specify either --secret or --secret-file only'
74
+ exit 1
75
+ elsif (config[:secret] && secret_path) || (config[:secret_file] && secret_path)
76
+ ui.warn 'The encrypted_data_bag_secret option defined in knife.rb was overriden by the command line.'
77
+ end
78
+ end
79
+
80
+ end
81
+
82
+ end
83
+ end
@@ -1,36 +1,42 @@
1
- module KnifeSoloDataBag
1
+ require 'chef/knife'
2
2
 
3
- class SoloDataBagList < Chef::Knife
3
+ class Chef
4
+ class Knife
4
5
 
5
- require 'chef/knife/helpers'
6
+ class SoloDataBagList < Knife
6
7
 
7
- include KnifeSoloDataBag::Helpers
8
+ deps do
9
+ require 'chef/knife/helpers'
10
+ end
8
11
 
9
- banner 'knife solo data bag list (options)'
10
- category 'solo data bag'
12
+ include Chef::Knife::SoloDataBagHelpers
11
13
 
12
- attr_reader :bag_name
14
+ banner 'knife solo data bag list (options)'
15
+ category 'solo data bag'
13
16
 
14
- option :data_bag_path,
15
- :long => '--data-bag-path DATA_BAG_PATH',
16
- :description => 'The path to data bag'
17
+ attr_reader :bag_name
17
18
 
18
- def run
19
- ensure_valid_arguments
20
- output format_for_display(bags)
21
- end
19
+ option :data_bag_path,
20
+ :long => '--data-bag-path DATA_BAG_PATH',
21
+ :description => 'The path to data bag'
22
22
 
23
- private
24
- def bags
25
- Dir.entries(bags_path).select do |i|
26
- File.directory?(File.expand_path(File.join(bags_path, i))) && i != '.' && i != '..'
23
+ def run
24
+ ensure_valid_arguments
25
+ output format_for_display(bags)
26
+ end
27
+
28
+ private
29
+ def bags
30
+ Dir.entries(bags_path).select do |i|
31
+ File.directory?(File.expand_path(File.join(bags_path, i))) && i != '.' && i != '..'
32
+ end
33
+ end
34
+
35
+ def ensure_valid_arguments
36
+ validate_bags_path_exists
27
37
  end
28
- end
29
38
 
30
- def ensure_valid_arguments
31
- validate_bags_path_exists
32
39
  end
33
40
 
34
41
  end
35
-
36
42
  end
@@ -1,61 +1,67 @@
1
- module KnifeSoloDataBag
1
+ require 'chef/knife'
2
2
 
3
- class SoloDataBagShow < Chef::Knife
3
+ class Chef
4
+ class Knife
4
5
 
5
- require 'chef/knife/helpers'
6
+ class SoloDataBagShow < Knife
6
7
 
7
- include KnifeSoloDataBag::Helpers
8
+ deps do
9
+ require 'chef/knife/helpers'
10
+ end
8
11
 
9
- banner 'knife solo data bag show BAG [ITEM] (options)'
10
- category 'solo data bag'
12
+ include Chef::Knife::SoloDataBagHelpers
11
13
 
12
- attr_reader :bag_name, :item_name
14
+ banner 'knife solo data bag show BAG [ITEM] (options)'
15
+ category 'solo data bag'
13
16
 
14
- option :secret,
15
- :short => '-s SECRET',
16
- :long => '--secret SECRET',
17
- :description => 'The secret key to use to encrypt data bag item values'
17
+ attr_reader :bag_name, :item_name
18
18
 
19
- option :secret_file,
20
- :long => '--secret-file SECRET_FILE',
21
- :description => 'A file containing the secret key to use to encrypt data bag item values'
19
+ option :secret,
20
+ :short => '-s SECRET',
21
+ :long => '--secret SECRET',
22
+ :description => 'The secret key to use to encrypt data bag item values'
22
23
 
23
- option :data_bag_path,
24
- :long => '--data-bag-path DATA_BAG_PATH',
25
- :description => 'The path to data bag'
24
+ option :secret_file,
25
+ :long => '--secret-file SECRET_FILE',
26
+ :description => 'A file containing the secret key to use to encrypt data bag item values'
26
27
 
27
- def run
28
- Chef::Config[:solo] = true
29
- @bag_name, @item_name = @name_args
30
- ensure_valid_arguments
31
- display_content
32
- end
28
+ option :data_bag_path,
29
+ :long => '--data-bag-path DATA_BAG_PATH',
30
+ :description => 'The path to data bag'
33
31
 
34
- private
35
- def bag_content
36
- Chef::DataBag.load bag_name
37
- end
32
+ def run
33
+ Chef::Config[:solo] = true
34
+ @bag_name, @item_name = @name_args
35
+ ensure_valid_arguments
36
+ display_content
37
+ end
38
38
 
39
- def bag_item_content
40
- if should_be_encrypted?
41
- raw = Chef::EncryptedDataBagItem.load(bag_name, item_name, secret_key)
42
- raw.to_hash
43
- else
44
- Chef::DataBagItem.load(bag_name, item_name).raw_data
39
+ private
40
+ def bag_content
41
+ Chef::DataBag.load bag_name
45
42
  end
46
- end
47
43
 
48
- def display_content
49
- content = item_name ? bag_item_content : bag_content
50
- output format_for_display(content)
51
- end
44
+ def bag_item_content
45
+ if should_be_encrypted?
46
+ raw = Chef::EncryptedDataBagItem.load(bag_name, item_name, secret_key)
47
+ raw.to_hash
48
+ else
49
+ Chef::DataBagItem.load(bag_name, item_name).raw_data
50
+ end
51
+ end
52
+
53
+ def display_content
54
+ content = item_name ? bag_item_content : bag_content
55
+ output format_for_display(content)
56
+ end
57
+
58
+ def ensure_valid_arguments
59
+ validate_bag_name_provided
60
+ validate_bags_path_exists
61
+ validate_multiple_secrets_were_not_provided
62
+ end
52
63
 
53
- def ensure_valid_arguments
54
- validate_bag_name_provided
55
- validate_bags_path_exists
56
- validate_multiple_secrets_were_not_provided
57
64
  end
58
65
 
59
66
  end
60
-
61
67
  end
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module SoloDataBag
3
- VERSION = '1.0.0.beta.1'
3
+ VERSION = '1.0.0.beta.2'
4
4
  end
5
5
  end
@@ -1,5 +1,13 @@
1
+ $:.unshift File.expand_path('../../lib', __FILE__)
2
+
1
3
  require 'fakefs/safe'
2
- require 'knife-solo_data_bag'
4
+
5
+ require 'chef'
6
+ require 'chef/knife'
7
+ require 'chef/knife/solo_data_bag_create'
8
+ require 'chef/knife/solo_data_bag_edit'
9
+ require 'chef/knife/solo_data_bag_list'
10
+ require 'chef/knife/solo_data_bag_show'
3
11
 
4
12
  ['contexts', 'helpers', 'matchers'].each do |dir|
5
13
  Dir[File.expand_path(File.join(File.dirname(__FILE__),dir,'*.rb'))].each {|f| require f}
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe KnifeSoloDataBag::SoloDataBagCreate do
3
+ describe Chef::Knife::SoloDataBagCreate do
4
4
  before do
5
5
  @knife = subject
6
6
  end
@@ -46,9 +46,14 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
46
46
 
47
47
  it 'should create the data bag item' do
48
48
  @knife.run
49
- JSON.parse(File.read(@item_path))['raw_data'].should == @input_data
49
+ JSON.parse(File.read(@item_path)).should == @input_data
50
50
  end
51
51
 
52
+ it 'should write pretty json' do
53
+ @knife.run
54
+ File.read(@item_path).should == JSON.pretty_generate(@input_data)
55
+ end
56
+
52
57
  context 'with --data-bag-path' do
53
58
  before do
54
59
  @override_bags_path = '/opt/bags'
@@ -71,7 +76,7 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
71
76
 
72
77
  it 'should create the encrypted data bag item' do
73
78
  @knife.run
74
- content = JSON.parse(File.read(@item_path))['raw_data']
79
+ content = JSON.parse(File.read(@item_path))
75
80
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
76
81
  content.should have_key k
77
82
  content[k].should_not == @input_data[k]
@@ -91,7 +96,7 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
91
96
 
92
97
  it 'should create the encrypted data bag item' do
93
98
  @knife.run
94
- content = JSON.parse(File.read(@item_path))['raw_data']
99
+ content = JSON.parse(File.read(@item_path))
95
100
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
96
101
  content.should have_key k
97
102
  content[k].should_not == @input_data[k]
@@ -112,7 +117,7 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
112
117
 
113
118
  it 'creates the encrypted data bag item' do
114
119
  @knife.run
115
- content = JSON.parse(File.read(@item_path))['raw_data']
120
+ content = JSON.parse(File.read(@item_path))
116
121
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
117
122
  content.should have_key k
118
123
  content[k].should_not == @input_data[k]
@@ -133,7 +138,7 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
133
138
 
134
139
  it 'should create the data bag item' do
135
140
  @knife.run
136
- JSON.parse(File.read(@item_path))['raw_data'].should == @input_data
141
+ JSON.parse(File.read(@item_path)).should == @input_data
137
142
  end
138
143
 
139
144
  context 'when encrypting with -s or --secret' do
@@ -144,7 +149,7 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
144
149
 
145
150
  it 'should create the encrypted data bag item' do
146
151
  @knife.run
147
- content = JSON.parse(File.read(@item_path))['raw_data']
152
+ content = JSON.parse(File.read(@item_path))
148
153
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
149
154
  content.should have_key k
150
155
  content[k].should_not == @input_data[k]
@@ -164,7 +169,7 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
164
169
 
165
170
  it 'should create the encrypted data bag item' do
166
171
  @knife.run
167
- content = JSON.parse(File.read(@item_path))['raw_data']
172
+ content = JSON.parse(File.read(@item_path))
168
173
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
169
174
  content.should have_key k
170
175
  content[k].should_not == @input_data[k]
@@ -185,7 +190,7 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
185
190
 
186
191
  it 'creates the encrypted data bag item' do
187
192
  @knife.run
188
- content = JSON.parse(File.read(@item_path))['raw_data']
193
+ content = JSON.parse(File.read(@item_path))
189
194
  @input_data.keys.reject{|i| i == 'id'}.each do |k|
190
195
  content.should have_key k
191
196
  content[k].should_not == @input_data[k]
@@ -207,7 +212,7 @@ describe KnifeSoloDataBag::SoloDataBagCreate do
207
212
 
208
213
  it 'creates the data bag item' do
209
214
  @knife.run
210
- JSON.parse(File.read(@item_path))['raw_data'].should == @input_data
215
+ JSON.parse(File.read(@item_path)).should == @input_data
211
216
  end
212
217
  end
213
218
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe KnifeSoloDataBag::SoloDataBagEdit do
3
+ describe Chef::Knife::SoloDataBagEdit do
4
4
  before do
5
5
  @knife = subject
6
6
  end
@@ -55,21 +55,13 @@ describe KnifeSoloDataBag::SoloDataBagEdit do
55
55
 
56
56
  it 'should edit the data bag item' do
57
57
  @knife.run
58
- JSON.parse(File.read(@item_path))['raw_data'].should == @updated_data
58
+ JSON.parse(File.read(@item_path)).should == @updated_data
59
59
  end
60
60
 
61
61
  it 'should write pretty json' do
62
62
  @knife.run
63
- File.read(@item_path).should == %q({
64
- "name": "data_bag_item_bag_1_foo",
65
- "json_class": "Chef::DataBagItem",
66
- "chef_type": "data_bag_item",
67
- "data_bag": "bag_1",
68
- "raw_data": {
69
- "id": "foo",
70
- "who": "sue"
71
- }
72
- })
63
+ data = JSON.pretty_generate(:id => 'foo', :who => 'sue')
64
+ File.read(@item_path).should == data
73
65
  end
74
66
 
75
67
  context 'with --data-bag-path' do
@@ -83,7 +75,7 @@ describe KnifeSoloDataBag::SoloDataBagEdit do
83
75
 
84
76
  it 'uses the data bag path from the override' do
85
77
  @knife.run
86
- data = JSON.parse(File.read(@override_item_path))['raw_data']
78
+ data = JSON.parse(File.read(@override_item_path))
87
79
  data.should == @updated_data
88
80
  end
89
81
  end
@@ -98,7 +90,7 @@ describe KnifeSoloDataBag::SoloDataBagEdit do
98
90
 
99
91
  it 'should edit the encrypted data bag item' do
100
92
  @knife.run
101
- content = JSON.parse(File.read(@item_path))['raw_data']
93
+ content = JSON.parse(File.read(@item_path))
102
94
  content['who'].should_not == @orig_data['who']
103
95
  content['who'].should_not be_nil
104
96
  end
@@ -118,7 +110,7 @@ describe KnifeSoloDataBag::SoloDataBagEdit do
118
110
 
119
111
  it 'should edit the encrypted data bag item' do
120
112
  @knife.run
121
- content = JSON.parse(File.read(@item_path))['raw_data']
113
+ content = JSON.parse(File.read(@item_path))
122
114
  content['who'].should_not == @orig_data['who']
123
115
  content['who'].should_not be_nil
124
116
  end
@@ -140,7 +132,7 @@ describe KnifeSoloDataBag::SoloDataBagEdit do
140
132
 
141
133
  it 'should edit the encrypted data bag item' do
142
134
  @knife.run
143
- content = JSON.parse(File.read(@item_path))['raw_data']
135
+ content = JSON.parse(File.read(@item_path))
144
136
  content['who'].should_not == @orig_data['who']
145
137
  content['who'].should_not be_nil
146
138
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe KnifeSoloDataBag::SoloDataBagList do
3
+ describe Chef::Knife::SoloDataBagList do
4
4
  before do
5
5
  @knife = subject
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe KnifeSoloDataBag::SoloDataBagShow do
3
+ describe Chef::Knife::SoloDataBagShow do
4
4
  before do
5
5
  @knife = subject
6
6
  end
@@ -0,0 +1,46 @@
1
+ #!/bin/bash
2
+
3
+ set -e
4
+
5
+ function download_chef_version() {
6
+ echo -e "Installing curl..."
7
+ yum install -y curl
8
+ echo "Done"
9
+
10
+ echo -e "Downloading chef install script..."
11
+ curl -o /tmp/kitchen/data/chef_install.sh https://www.opscode.com/chef/install.sh
12
+ chmod +x /tmp/kitchen/data/chef_install.sh
13
+ echo "Done"
14
+ /tmp/kitchen/data/chef_install.sh -v $1
15
+ }
16
+
17
+ for version in 11.2.0-1 11.4.4-2 11.6.2-1 11.8.2-1 11.10.0-1; do
18
+ echo "##############################"
19
+ echo "# Processing $version"
20
+ echo "##############################"
21
+
22
+ if [ ! -f /tmp/kitchen/data/packages/chef-$version.el6.x86_64.rpm ]; then
23
+ download_chef_version $version
24
+ else
25
+ rpm -ivh --quiet /tmp/kitchen/data/packages/chef-$version*.rpm
26
+ fi
27
+
28
+ echo -e "Installing knife-solo_data_bag..."
29
+ /opt/chef/embedded/bin/gem install -q /tmp/kitchen/data/packages/*1.0.0.gem --no-ri --no-rdoc
30
+ echo "Done"
31
+
32
+ knife solo data bag create foo bar --data-bag-path /tmp/kitchen/data/data_bags -j '{ "id": "bar", "my": "data" }'
33
+
34
+ chef-solo -c /tmp/kitchen/data/solo.rb -o foo -l info
35
+
36
+ knife solo data bag show foo bar --data-bag-path /tmp/kitchen/data/data_bags
37
+
38
+ echo -e "Cleaning up..."
39
+ rpm -e --quiet chef
40
+
41
+ rm -fr /opt/chef
42
+ rm -fr /tmp/kitchend/data/data_bags/foo
43
+ echo "Done"
44
+ done
45
+
46
+ exit 0
@@ -0,0 +1,2 @@
1
+ name 'foo'
2
+ version '0.1.0'
@@ -0,0 +1,5 @@
1
+ item = data_bag_item('foo', 'bar')
2
+
3
+ unless item['my'] == 'data'
4
+ Chef::Application.fatal! "data is incorrect. item == #{item.inspect}"
5
+ end
@@ -0,0 +1,2 @@
1
+ cookbook_path ['/tmp/kitchen/data/cookbooks']
2
+ data_bag_path '/tmp/kitchen/data/data_bags'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-solo_data_bag
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta.1
4
+ version: 1.0.0.beta.2
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-05 00:00:00.000000000 Z
12
+ date: 2014-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -67,6 +67,7 @@ extensions: []
67
67
  extra_rdoc_files: []
68
68
  files:
69
69
  - .gitignore
70
+ - .kitchen.yml
70
71
  - .rspec
71
72
  - .ruby-gemset
72
73
  - .travis.yml
@@ -75,6 +76,7 @@ files:
75
76
  - LICENSE
76
77
  - README.md
77
78
  - Rakefile
79
+ - gemfiles/Gemfile.chef.11.10.0
78
80
  - gemfiles/Gemfile.chef.11.4.4
79
81
  - gemfiles/Gemfile.chef.11.6.2
80
82
  - gemfiles/Gemfile.chef.11.8.0
@@ -83,9 +85,9 @@ files:
83
85
  - lib/chef/knife/helpers.rb
84
86
  - lib/chef/knife/solo_data_bag_create.rb
85
87
  - lib/chef/knife/solo_data_bag_edit.rb
88
+ - lib/chef/knife/solo_data_bag_helpers.rb
86
89
  - lib/chef/knife/solo_data_bag_list.rb
87
90
  - lib/chef/knife/solo_data_bag_show.rb
88
- - lib/knife-solo_data_bag.rb
89
91
  - lib/knife-solo_data_bag/version.rb
90
92
  - spec/contexts/bag_name_not_provided.rb
91
93
  - spec/contexts/bag_path_is_not_valid.rb
@@ -96,6 +98,10 @@ files:
96
98
  - spec/unit/solo_data_bag_edit_spec.rb
97
99
  - spec/unit/solo_data_bag_list_spec.rb
98
100
  - spec/unit/solo_data_bag_show_spec.rb
101
+ - test/integration/bootstrap.sh
102
+ - test/integration/data/cookbooks/foo/metadata.rb
103
+ - test/integration/data/cookbooks/foo/recipes/default.rb
104
+ - test/integration/data/solo.rb
99
105
  homepage: https://github.com/thbishop/knife-solo_data_bag
100
106
  licenses: []
101
107
  post_install_message:
@@ -130,3 +136,7 @@ test_files:
130
136
  - spec/unit/solo_data_bag_edit_spec.rb
131
137
  - spec/unit/solo_data_bag_list_spec.rb
132
138
  - spec/unit/solo_data_bag_show_spec.rb
139
+ - test/integration/bootstrap.sh
140
+ - test/integration/data/cookbooks/foo/metadata.rb
141
+ - test/integration/data/cookbooks/foo/recipes/default.rb
142
+ - test/integration/data/solo.rb
@@ -1,11 +0,0 @@
1
- require 'chef/exceptions'
2
- require 'chef/knife'
3
- require 'chef/knife/solo_data_bag_create'
4
- require 'chef/knife/solo_data_bag_edit'
5
- require 'chef/knife/solo_data_bag_list'
6
- require 'chef/knife/solo_data_bag_show'
7
- require 'knife-solo_data_bag/version'
8
-
9
- module Knife
10
- module SoloDataBag; end
11
- end