chefdepartie 0.0.3 → 0.0.4

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: ffda5a4e9b1258d25ba59354dbdb73148af675b4
4
- data.tar.gz: ad14a0b279ec6541be45be51ef4fbbbd350c6367
3
+ metadata.gz: 4798d0d48e4fa238966cc55491e6febb0fe5db10
4
+ data.tar.gz: 0ccc4bc0eb60298ba3c32c4910dff89a24c823f2
5
5
  SHA512:
6
- metadata.gz: ff88fbed52f7d75d518a8b1924bf9c4b179bd0d67ee110dcc778d21040658f3c5d5b4663df905c05c883d260ad04eb207c341670ba0a535b9770b49966200323
7
- data.tar.gz: abf7fa5b9c495221ae3425e7150716ef8f93120eb7a0164772f8294d270f9f972066143798892a481dd25fa79ec0eb72cae2eb3be56acee4da992f104b177325
6
+ metadata.gz: 6244d41cd09e6ddb218c0c04019fc5cc817becf94805cce27f7f280fe062c914242902bacd2614835e7c66465ed005ac9bdadeeed15ab289ea65f8a11a0ab9bd
7
+ data.tar.gz: 9f51599b27ca12a0783bc3f37398e9e08054bd90b8b33c45641a289e25ea58d1e9aae0f2a1bda87cf30eb13658e51ece493f24517b947c67638ff277c5732b0e
data/Gemfile CHANGED
@@ -5,4 +5,3 @@ gemspec
5
5
  group :test do
6
6
  gem 'simplecov', '=0.10.0'
7
7
  end
8
-
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- chefdepartie (0.0.3)
4
+ chefdepartie (0.0.4)
5
5
  chef (~> 12.3.0)
6
6
  chef-zero (~> 4.2.2)
7
7
  librarian-chef (~> 0.0.4)
@@ -42,7 +42,7 @@ GEM
42
42
  diff-lcs (1.2.5)
43
43
  docile (1.1.5)
44
44
  erubis (2.7.0)
45
- ffi (1.9.8)
45
+ ffi (1.9.10)
46
46
  ffi-yajl (2.2.0)
47
47
  libyajl2 (~> 1.2)
48
48
  hashie (2.1.2)
@@ -67,7 +67,7 @@ GEM
67
67
  mixlib-config (2.2.1)
68
68
  mixlib-log (1.6.0)
69
69
  mixlib-shellout (2.1.0)
70
- multi_json (1.11.1)
70
+ multi_json (1.11.2)
71
71
  net-scp (1.2.1)
72
72
  net-ssh (>= 2.6.5)
73
73
  net-ssh (2.9.2)
@@ -76,9 +76,10 @@ GEM
76
76
  net-ssh-multi (1.2.1)
77
77
  net-ssh (>= 2.6.5)
78
78
  net-ssh-gateway (>= 1.2.0)
79
- ohai (8.4.0)
79
+ net-telnet (0.1.1)
80
+ ohai (8.5.0)
80
81
  ffi (~> 1.9)
81
- ffi-yajl (>= 1.1, < 3.0)
82
+ ffi-yajl (~> 2.2)
82
83
  ipaddress
83
84
  mime-types (~> 2.0)
84
85
  mixlib-cli
@@ -93,13 +94,13 @@ GEM
93
94
  coderay (~> 1.1.0)
94
95
  method_source (~> 0.8.1)
95
96
  slop (~> 3.4)
96
- rack (1.6.2)
97
+ rack (1.6.4)
97
98
  rake (10.4.2)
98
99
  rspec (3.3.0)
99
100
  rspec-core (~> 3.3.0)
100
101
  rspec-expectations (~> 3.3.0)
101
102
  rspec-mocks (~> 3.3.0)
102
- rspec-core (3.3.0)
103
+ rspec-core (3.3.1)
103
104
  rspec-support (~> 3.3.0)
104
105
  rspec-expectations (3.3.0)
105
106
  diff-lcs (>= 1.2.0, < 2.0)
@@ -107,27 +108,30 @@ GEM
107
108
  rspec-its (1.2.0)
108
109
  rspec-core (>= 3.0.0)
109
110
  rspec-expectations (>= 3.0.0)
110
- rspec-mocks (3.3.0)
111
+ rspec-mocks (3.3.1)
111
112
  diff-lcs (>= 1.2.0, < 2.0)
112
113
  rspec-support (~> 3.3.0)
113
114
  rspec-support (3.3.0)
114
115
  rspec_junit_formatter (0.2.3)
115
116
  builder (< 4)
116
117
  rspec-core (>= 2, < 4, != 2.12.0)
117
- serverspec (2.18.0)
118
+ serverspec (2.19.0)
118
119
  multi_json
119
120
  rspec (~> 3.0)
120
121
  rspec-its
121
122
  specinfra (~> 2.35)
123
+ sfl (2.2)
122
124
  simplecov (0.10.0)
123
125
  docile (~> 1.1.0)
124
126
  json (~> 1.8)
125
127
  simplecov-html (~> 0.10.0)
126
128
  simplecov-html (0.10.0)
127
129
  slop (3.6.0)
128
- specinfra (2.35.1)
130
+ specinfra (2.37.1)
129
131
  net-scp
130
- net-ssh
132
+ net-ssh (~> 2.7)
133
+ net-telnet
134
+ sfl
131
135
  systemu (2.6.5)
132
136
  thor (0.19.1)
133
137
  uuidtools (2.1.5)
data/chefdepartie.gemspec CHANGED
@@ -13,10 +13,10 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = 'https://rubygems.org/gems/chefdepartie'
14
14
  spec.license = 'MIT'
15
15
 
16
- spec.files = `git ls-files`.split($/)
16
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
21
  spec.add_runtime_dependency 'chef', '~> 12.3.0'
22
22
  spec.add_runtime_dependency 'chef-zero', '~> 4.2.2'
data/lib/chefdepartie.rb CHANGED
@@ -5,31 +5,57 @@ require_relative 'chefdepartie/role'
5
5
  require_relative 'chefdepartie/cookbook'
6
6
  require_relative 'chefdepartie/databag'
7
7
 
8
+ # Chefdepartie root namespace for core module commands
8
9
  module Chefdepartie
9
10
  def self.run(**kwargs)
10
-
11
11
  # Load the configuration
12
- config = kwargs[:config]
13
- Chef::Config.from_file(config)
12
+ config_file = kwargs[:config_file] || ENV['CHEFDEPARTIE_CONFIG']
13
+ load_config(config_file, kwargs[:config])
14
+ background = kwargs[:background]
14
15
 
15
16
  # Start the chef-zero server
16
- server_thread = start_server
17
+ self.server_thread = start_server(background)
17
18
 
18
19
  # Upload everything
19
20
  upload_all
20
21
 
21
- # Now that everything has been uploaded, we'll join the server thread
22
- puts "Ready"
23
- server_thread.join
22
+ # Notify that the chef server is ready
23
+ puts 'Ready'
24
+
25
+ # Join the chef server thread now that everything has been uploaded
26
+ self.server_thread.join unless background
27
+ end
28
+
29
+ def self.stop
30
+ puts 'Stopping server'
31
+ server_thread.stop
32
+ end
33
+
34
+ private
35
+
36
+ def self.server_thread=(thread)
37
+ @@server_thread = thread
24
38
  end
25
39
 
26
- private
40
+ def self.server_thread
41
+ @@server_thread
42
+ end
27
43
 
28
44
  def self.upload_all
29
45
  Chefdepartie::Roles.upload_all
30
46
  Chefdepartie::Databags.upload_all
31
47
  Chefdepartie::Cookbooks.upload_all
32
48
  end
33
- end
34
49
 
35
- Chefdepartie.run(config: ENV['CHEFDEPARTIE_CONFIG']) # FIXME: use something better than an env var to get the config
50
+ def self.load_config(config_file, config)
51
+ # Load config from config file if provided
52
+ Chef::Config.from_file(config_file) if File.exist?(config_file)
53
+
54
+ # Load config from hash
55
+ if config && config.is_a?(Hash)
56
+ config.each do |k, v|
57
+ Chef::Config.send(k.to_sym, v)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -5,21 +5,21 @@ require 'librarian'
5
5
  require 'librarian/chef'
6
6
 
7
7
  module Chefdepartie
8
+ # Handle finding and uploading cookbooks
8
9
  module Cookbooks
9
-
10
10
  def self.upload_all
11
11
  cookbooks = File.dirname(Chef::Config[:cookbook_path])
12
12
  Dir.chdir(cookbooks) do
13
- puts "Uploading librarian cookbooks"
13
+ puts 'Uploading librarian cookbooks'
14
14
  upload_cheffile
15
15
 
16
- puts "Uploading site cookbooks"
17
- books = Dir["cookbooks/*"]
16
+ puts 'Uploading site cookbooks'
17
+ books = Dir['cookbooks/*']
18
18
  upload_site_cookbooks(books)
19
19
  end
20
20
  end
21
21
 
22
- private
22
+ private
23
23
 
24
24
  def self.upload_cookbooks(path, books)
25
25
  loader = Chef::CookbookLoader.new(path)
@@ -27,14 +27,14 @@ module Chefdepartie
27
27
  books = books.collect do |name|
28
28
  status = :new
29
29
  cookbook = loader.load_cookbook(name)
30
- raise "could not load cookbook #{name} " if cookbook.nil?
30
+ fail "could not load cookbook #{name} " if cookbook.nil?
31
31
  cookbook
32
32
  end.compact
33
33
 
34
34
  rest = Chef::REST.new(Chef::Config[:chef_server_url])
35
35
 
36
36
  begin
37
- Chef::CookbookUploader.new(books, {force: true, rest: rest}).upload_cookbooks
37
+ Chef::CookbookUploader.new(books, force: true, rest: rest).upload_cookbooks
38
38
  rescue SystemExit => e
39
39
  raise "Cookbook upload exited with status #{e.status}"
40
40
  end
@@ -59,8 +59,8 @@ module Chefdepartie
59
59
 
60
60
  def self.upload_cheffile
61
61
  unless ENV['NO_LIBRARIAN']
62
- system("librarian-chef install")
63
- upload_cookbooks("tmp/librarian/cookbooks", cheffile_cookbooks.map(&:name))
62
+ system('librarian-chef install')
63
+ upload_cookbooks('tmp/librarian/cookbooks', cheffile_cookbooks.map(&:name))
64
64
  end
65
65
  end
66
66
 
@@ -13,7 +13,7 @@ module ChefZero
13
13
  def self.normalize_data_bag_item(data_bag_item, data_bag_name, id, method)
14
14
  if method == 'DELETE'
15
15
  # TODO SERIOUSLY, WHO DOES THIS MANY EXCEPTIONS IN THEIR INTERFACE
16
- if !(data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data'])
16
+ unless data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
17
17
  data_bag_item['id'] ||= id
18
18
  data_bag_item = { 'raw_data' => data_bag_item }
19
19
  data_bag_item['chef_type'] ||= 'data_bag_item'
@@ -24,7 +24,7 @@ module ChefZero
24
24
  else
25
25
  # If it's not already wrapped with raw_data, wrap it.
26
26
  if data_bag_item['json_class'] == 'Chef::DataBagItem' && data_bag_item['raw_data']
27
- #data_bag_item = data_bag_item['raw_data']
27
+ # data_bag_item = data_bag_item['raw_data']
28
28
  end
29
29
  # Argh. We don't do this on GET, but we do on PUT and POST????
30
30
  if %w(PUT POST).include?(method)
@@ -42,13 +42,13 @@ end
42
42
  module Chefdepartie
43
43
  module Databags
44
44
  def self.upload_all
45
- puts "Uploading databags"
45
+ puts 'Uploading databags'
46
46
  cookbooks = File.dirname(Chef::Config[:cookbook_path])
47
- bags = Dir[File.join(cookbooks,'data_bags','/*')]
47
+ bags = Dir[File.join(cookbooks, 'data_bags', '/*')]
48
48
  upload_all_data_bags(bags)
49
49
  end
50
50
 
51
- private
51
+ private
52
52
 
53
53
  def self.upload_data_bag_items(items)
54
54
  current_bags = Chef::DataBag.list.keys.to_set
@@ -75,7 +75,7 @@ module Chefdepartie
75
75
 
76
76
  data_bags.each do |data_bag|
77
77
  bag_name = File.basename(data_bag)
78
- files = Dir.glob(File.join(data_bag,"*.json")).flatten
78
+ files = Dir.glob(File.join(data_bag, '*.json')).flatten
79
79
 
80
80
  files.each do |item_file|
81
81
  raw_data = Chef::JSONCompat.from_json(IO.read(item_file))
@@ -96,8 +96,8 @@ module Chefdepartie
96
96
 
97
97
  def self.is_encrypted_data_bag?(raw_data)
98
98
  # TODO: use Chef::EncryptedDataBagItem::CheckEncrypted when we move to Chef 12
99
- first_sub_item = Array(raw_data.find { |k, v| k != 'id' }).last
100
- !!(first_sub_item.kind_of?(Hash) && first_sub_item['encrypted_data'] && first_sub_item['cipher'])
99
+ first_sub_item = Array(raw_data.find { |k, _v| k != 'id' }).last
100
+ !!(first_sub_item.is_a?(Hash) && first_sub_item['encrypted_data'] && first_sub_item['cipher'])
101
101
  end
102
102
  end
103
103
  end
@@ -3,16 +3,15 @@ require 'chef/role'
3
3
 
4
4
  module Chefdepartie
5
5
  module Roles
6
-
7
6
  def self.upload_all
8
- puts "Uploading roles"
7
+ puts 'Uploading roles'
9
8
  cookbooks = File.dirname(Chef::Config[:cookbook_path])
10
9
  roles = []
11
- Find.find(File.join(cookbooks,'roles')){ |f| roles << f if f =~ /\.rb$/}
10
+ Find.find(File.join(cookbooks, 'roles')) { |f| roles << f if f =~ /\.rb$/ }
12
11
  upload_site_roles(roles)
13
12
  end
14
13
 
15
- private
14
+ private
16
15
 
17
16
  def self.upload_site_roles(files)
18
17
  roles = {}
@@ -1,11 +1,16 @@
1
1
  require 'chef_zero/server'
2
2
  require 'uri/generic'
3
3
 
4
- def start_server
4
+ def start_server(background)
5
5
  port = URI(Chef::Config[:chef_server_url]).port
6
6
  server = ChefZero::Server.new(host: '0.0.0.0', port: port)
7
- Thread.new do
8
- server.start#_background
7
+
8
+ if background
9
+ server.start_background
10
+ server
11
+ else
12
+ Thread.new do
13
+ server.start
14
+ end
9
15
  end
10
16
  end
11
-
@@ -1,3 +1,4 @@
1
+ # Store version info
1
2
  module Chefdepartie
2
- VERSION='0.0.3'
3
+ VERSION = '0.0.4'
3
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chefdepartie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dale Hamel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-09 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef