kitchen-shopify-provisioner 0.0.4 → 0.0.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb937d5d96774f6e3f54736be0695e10d60c147e
4
- data.tar.gz: e2a8966b6573d0da2d67c03ffecee46c949e7517
3
+ metadata.gz: b8ba983510d9360b08949c63a273c09ef99ca096
4
+ data.tar.gz: 7c4ec3c584fbda4694eb678de512f530dc34c181
5
5
  SHA512:
6
- metadata.gz: a7763d8526f133dafc7433912eeba512a48d7849dc7dec564ca839535062042ab080290ae5a6de6d148a9970311afdc2536c4fa0ec826d274c3c08ac305723a7
7
- data.tar.gz: 03e914fa94831b27b5451dc7faf51f5a04cf6ee86b70f01b40cfbbebc775ee2e232ef99c3e5478aa1de3a71f0f0c06fb9494e02e9d5706cefda631cc585fb5f6
6
+ metadata.gz: 701608b8713d78a6844fd0271e4fdaf88aa7d29106bf554560aefd723c7add1bd102b48398389dee0c842f8a532574d6f86ddefd97ab3e2b65cdae86ab0381f6
7
+ data.tar.gz: 1522bcfafd650550159644c4e414efbc4c134670e23e7e6bdb9be541eaf52da2a5927a57dde833c9cc714db08fcb4c492f1cab8a77aab280d54895d1c8eba95b
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  s.description = s.summary
14
14
  s.homepage = 'https://github.com/shopify/kitchen-shopify-provisioner'
15
15
 
16
- s.files = `git ls-files`.split($/)
17
- s.test_files = s.files.grep(%r{spec})
16
+ s.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ s.test_files = s.files.grep(/spec/)
18
18
  s.require_paths = ['lib']
19
19
 
20
20
  s.add_runtime_dependency 'chef', ['~> 12']
@@ -1,3 +1,3 @@
1
1
  module KitchenShopifyProvisioner
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'.freeze
3
3
  end
@@ -1,35 +1,71 @@
1
1
  require 'kitchen/provisioner/chef_zero'
2
2
  require 'chef-config/config'
3
3
  require 'chef/role'
4
+ require 'chef/data_bag_item'
5
+ require 'chef/encrypted_data_bag_item'
6
+ require 'chef/encrypted_data_bag_item/check_encrypted'
4
7
 
5
8
  module Kitchen
6
9
  module Provisioner
7
-
8
10
  # We'll sneak some code in before the default chef zero provisioner runs
9
11
  # This will allow us to convert our roles to JSON, and flatten at once
10
12
  class ChefZeroShopify < ChefZero
11
13
  def create_sandbox
12
- tmpdir = Dir.mktmpdir('chef-flattened-roles')
14
+ tmpdir = Dir.mktmpdir('chef-shopify-inject')
13
15
 
14
16
  at_exit do
15
17
  FileUtils.rm_rf(tmpdir)
16
18
  end
17
19
 
20
+ flatten_roles(config, tmpdir) unless config[:roles_path].nil?
21
+ decrypt_data_bags(config, tmpdir) unless config[:data_bags_path].nil?
22
+ super
23
+ rescue => e
24
+ puts e.message
25
+ puts e.backtrace
26
+ raise 'Failed extend the shopify provisioner!'
27
+ end
28
+
29
+ private
30
+
31
+ def flatten_roles(config, tmpdir)
18
32
  # This block generates exceptions if we don't have a roles directory in ./
19
- # or :roles_path is not configured in .kitchen.yml. So just call the
20
- # superclass version and be done with it.
21
- unless config[:roles_path].nil?
22
- Dir.glob(File.join(config[:roles_path], '**', '*.rb')).each do |rb_file|
23
- obj = ::Chef::Role.new
24
- obj.from_file(rb_file)
25
- json_file = rb_file.sub(/\.rb$/, '.json').gsub(config[:roles_path], '').sub(/^\//, '').split('/').join('--')
26
- File.write(File.join(tmpdir, json_file), ::Chef::JSONCompat.to_json_pretty(obj))
27
- end
33
+ # or :roles_path is not configured in .kitchen.yml.
34
+ flat_roles = File.join(tmpdir, 'roles')
35
+ FileUtils.mkdir_p(flat_roles)
28
36
 
29
- config[:roles_path] = tmpdir
37
+ Dir.glob(File.join(config[:roles_path], '**', '*.rb')).each do |rb_file|
38
+ obj = ::Chef::Role.new
39
+ obj.from_file(rb_file)
40
+ json_file = rb_file.sub(/\.rb$/, '.json').gsub(config[:roles_path], '').sub(%r{^\/}, '').split('/').join('--')
41
+ File.write(File.join(flat_roles, json_file), ::Chef::JSONCompat.to_json_pretty(obj))
30
42
  end
31
43
 
32
- super
44
+ config[:roles_path] = flat_roles
45
+ end
46
+
47
+ def decrypt_data_bags(config, tmpdir)
48
+ plain_data_bags = File.join(tmpdir, 'data_bags')
49
+ secret = File.read(config[:encrypted_data_bag_secret_key_path]).strip
50
+
51
+ data_bags = Dir.glob(File.join(config[:data_bags_path], '*'))
52
+ data_bags.each do |data_bag|
53
+ bag_name = File.basename(data_bag)
54
+ files = Dir.glob(File.join(data_bag, '*.json')).flatten
55
+ files.each do |item_file|
56
+ raw_data = ::Chef::JSONCompat.from_json(IO.read(item_file))
57
+ raw_data = ::Chef::EncryptedDataBagItem.new(raw_data, secret).to_hash if encrypted_data_bag?(raw_data)
58
+ json_dump = ::Chef::JSONCompat.to_json_pretty(raw_data)
59
+ plain_file = File.join(plain_data_bags, bag_name, File.basename(item_file))
60
+ FileUtils.mkdir_p(File.dirname(plain_file))
61
+ File.write(plain_file, json_dump)
62
+ end
63
+ end
64
+ config[:data_bags_path] = plain_data_bags
65
+ end
66
+
67
+ def encrypted_data_bag?(raw_data)
68
+ Class.new.extend(::Chef::EncryptedDataBagItem::CheckEncrypted).encrypted?(raw_data)
33
69
  end
34
70
  end
35
71
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  RSpec.configure do |config|
2
- config.order = "random"
3
- config.expect_with(:rspec) {|c| c.syntax = :expect }
2
+ config.order = 'random'
3
+ config.expect_with(:rspec) { |c| c.syntax = :expect }
4
4
  end
5
5
 
6
6
  class BogusInstance
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-shopify-provisioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Hamel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-06 00:00:00.000000000 Z
11
+ date: 2016-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef