chef-dk 1.1.16 → 1.2.20

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 (34) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +12 -4
  3. data/Gemfile.lock +84 -68
  4. data/Rakefile +9 -0
  5. data/acceptance/Gemfile +3 -0
  6. data/acceptance/Gemfile.lock +43 -27
  7. data/chef-dk.gemspec +3 -2
  8. data/lib/chef-dk/command/install.rb +1 -1
  9. data/lib/chef-dk/exceptions.rb +10 -0
  10. data/lib/chef-dk/policyfile/chef_server_cookbook_source.rb +52 -8
  11. data/lib/chef-dk/policyfile/community_cookbook_source.rb +0 -1
  12. data/lib/chef-dk/policyfile/cookbook_location_specification.rb +2 -2
  13. data/lib/chef-dk/policyfile/dsl.rb +4 -2
  14. data/lib/chef-dk/policyfile/source_uri.rb +57 -0
  15. data/lib/chef-dk/policyfile/storage_config.rb +3 -0
  16. data/lib/chef-dk/policyfile_compiler.rb +4 -4
  17. data/lib/chef-dk/policyfile_services/install.rb +4 -2
  18. data/lib/chef-dk/skeletons/code_generator/files/default/delivery-project.toml +14 -3
  19. data/lib/chef-dk/skeletons/code_generator/files/default/repo/cookbooks/example/metadata.rb +3 -0
  20. data/lib/chef-dk/skeletons/code_generator/recipes/build_cookbook.rb +2 -0
  21. data/lib/chef-dk/skeletons/code_generator/templates/default/repo/gitignore.erb +121 -4
  22. data/lib/chef-dk/version.rb +1 -1
  23. data/omnibus_overrides.rb +2 -0
  24. data/spec/unit/command/generator_commands/cookbook_spec.rb +16 -5
  25. data/spec/unit/command/install_spec.rb +2 -2
  26. data/spec/unit/fixtures/cookbooks_api/chef_server_universe.json +56 -0
  27. data/spec/unit/fixtures/cookbooks_api/pruned_chef_server_universe.json +30 -0
  28. data/spec/unit/policyfile/chef_server_cookbook_source_spec.rb +29 -8
  29. data/spec/unit/policyfile/cookbook_location_specification_spec.rb +22 -0
  30. data/spec/unit/policyfile/source_uri_spec.rb +36 -0
  31. data/spec/unit/policyfile/storage_config_spec.rb +12 -0
  32. data/spec/unit/policyfile_services/push_spec.rb +16 -0
  33. data/version_policy.rb +9 -5
  34. metadata +40 -13
data/Rakefile CHANGED
@@ -21,3 +21,12 @@ require_relative "tasks/bundle"
21
21
  require_relative "tasks/dependencies"
22
22
  require_relative "tasks/github_changelog_generator"
23
23
  require_relative "tasks/announce"
24
+
25
+ desc "Keep the Dockerfile up-to-date"
26
+ task :update_dockerfile do
27
+ require "mixlib/install"
28
+ latest_stable_version = Mixlib::Install.available_versions("chefdk", "stable").last
29
+ text = File.read("Dockerfile")
30
+ new_text = text.gsub(/^ARG VERSION=[\d\.]+$/, "ARG VERSION=#{latest_stable_version}")
31
+ File.open("Dockerfile", "w+") { |f| f.write(new_text) }
32
+ end
@@ -10,6 +10,9 @@ gem "winrm-fs"
10
10
  gem "winrm-elevated"
11
11
  gem "berkshelf"
12
12
 
13
+ # Workaround to address https://github.com/sickill/rainbow/issues/44
14
+ gem "rainbow", ">= 2.1.0", "< 2.2"
15
+
13
16
  # TODO remove this when we update Chef to use the new api exposed in 3.5.1
14
17
  gem "rspec-core", "= 3.4.4"
15
18
 
@@ -12,15 +12,15 @@ GEM
12
12
  addressable (2.5.0)
13
13
  public_suffix (~> 2.0, >= 2.0.2)
14
14
  artifactory (2.5.1)
15
- aws-sdk (2.6.35)
16
- aws-sdk-resources (= 2.6.35)
17
- aws-sdk-core (2.6.35)
15
+ aws-sdk (2.7.2)
16
+ aws-sdk-resources (= 2.7.2)
17
+ aws-sdk-core (2.7.2)
18
18
  aws-sigv4 (~> 1.0)
19
19
  jmespath (~> 1.0)
20
- aws-sdk-resources (2.6.35)
21
- aws-sdk-core (= 2.6.35)
20
+ aws-sdk-resources (2.7.2)
21
+ aws-sdk-core (= 2.7.2)
22
22
  aws-sigv4 (1.0.0)
23
- berkshelf (5.2.0)
23
+ berkshelf (5.5.0)
24
24
  addressable (~> 2.3, >= 2.3.4)
25
25
  berkshelf-api-client (>= 2.0.2, < 4.0)
26
26
  buff-config (~> 2.0)
@@ -35,7 +35,7 @@ GEM
35
35
  retryable (~> 2.0)
36
36
  ridley (~> 5.0)
37
37
  solve (> 2.0, < 4.0)
38
- thor (~> 0.19)
38
+ thor (~> 0.19, < 0.19.2)
39
39
  berkshelf-api-client (3.0.0)
40
40
  faraday (~> 0.9)
41
41
  httpclient (~> 2.7)
@@ -48,28 +48,30 @@ GEM
48
48
  buff-ruby_engine (1.0.0)
49
49
  buff-shell_out (1.1.0)
50
50
  buff-ruby_engine (~> 1.0)
51
- builder (3.2.2)
51
+ builder (3.2.3)
52
52
  celluloid (0.16.0)
53
53
  timers (~> 4.0.0)
54
54
  celluloid-io (0.16.2)
55
55
  celluloid (>= 0.16.0)
56
56
  nio4r (>= 1.1.0)
57
- chef-config (12.17.44)
57
+ chef-config (12.18.31)
58
58
  addressable
59
59
  fuzzyurl
60
60
  mixlib-config (~> 2.0)
61
61
  mixlib-shellout (~> 2.0)
62
62
  cleanroom (1.0.0)
63
63
  coderay (1.1.1)
64
- diff-lcs (1.2.5)
65
- docker-api (1.33.0)
64
+ diff-lcs (1.3)
65
+ docker-api (1.33.2)
66
66
  excon (>= 0.38.0)
67
67
  json
68
+ domain_name (0.5.20161129)
69
+ unf (>= 0.0.5, < 1.0.0)
68
70
  erubis (2.7.0)
69
71
  excon (0.54.0)
70
72
  faraday (0.9.2)
71
73
  multipart-post (>= 1.2, < 3)
72
- ffi (1.9.14)
74
+ ffi (1.9.17)
73
75
  fuzzyurl (0.9.0)
74
76
  gssapi (1.2.0)
75
77
  ffi (>= 1.0.1)
@@ -77,9 +79,19 @@ GEM
77
79
  builder (>= 2.1.2)
78
80
  hashie (3.4.6)
79
81
  hitimes (1.2.4)
82
+ http (2.1.0)
83
+ addressable (~> 2.3)
84
+ http-cookie (~> 1.0)
85
+ http-form_data (~> 1.0.1)
86
+ http_parser.rb (~> 0.6.0)
87
+ http-cookie (1.0.3)
88
+ domain_name (~> 0.5)
89
+ http-form_data (1.0.1)
90
+ http_parser.rb (0.6.0)
80
91
  httpclient (2.8.3)
81
- inspec (1.7.2)
92
+ inspec (1.10.0)
82
93
  hashie (~> 3.4)
94
+ http (~> 2.1.0)
83
95
  json (>= 1.8, < 3.0)
84
96
  method_source (~> 0.8)
85
97
  mixlib-log
@@ -94,7 +106,7 @@ GEM
94
106
  thor (~> 0.19)
95
107
  train (>= 0.22.0, < 1.0)
96
108
  jmespath (1.3.1)
97
- json (2.0.2)
109
+ json (2.0.3)
98
110
  kitchen-ec2 (1.2.0)
99
111
  aws-sdk (~> 2)
100
112
  excon
@@ -105,7 +117,7 @@ GEM
105
117
  hashie (~> 3.4)
106
118
  inspec (>= 0.34.0, < 2.0.0)
107
119
  test-kitchen (~> 1.6)
108
- kitchen-vagrant (0.21.1)
120
+ kitchen-vagrant (1.0.0)
109
121
  test-kitchen (~> 1.4)
110
122
  little-plugger (1.1.4)
111
123
  logging (2.1.0)
@@ -113,7 +125,7 @@ GEM
113
125
  multi_json (~> 1.10)
114
126
  method_source (0.8.2)
115
127
  minitar (0.5.4)
116
- mixlib-archive (0.2.0)
128
+ mixlib-archive (0.3.0)
117
129
  mixlib-log
118
130
  mixlib-authentication (1.4.1)
119
131
  mixlib-log
@@ -125,15 +137,15 @@ GEM
125
137
  mixlib-log (1.7.1)
126
138
  mixlib-shellout (2.2.7)
127
139
  mixlib-versioning (1.1.0)
128
- molinillo (0.5.4)
140
+ molinillo (0.5.5)
129
141
  multi_json (1.12.1)
130
142
  multipart-post (2.0.0)
131
143
  net-scp (1.2.1)
132
144
  net-ssh (>= 2.6.5)
133
- net-ssh (3.2.0)
145
+ net-ssh (4.0.1)
134
146
  net-ssh-gateway (1.2.0)
135
147
  net-ssh (>= 2.6.5)
136
- nio4r (1.2.1)
148
+ nio4r (2.0.0)
137
149
  nori (2.6.0)
138
150
  octokit (4.6.2)
139
151
  sawyer (~> 0.8.0, >= 0.5.3)
@@ -142,7 +154,7 @@ GEM
142
154
  coderay (~> 1.1.0)
143
155
  method_source (~> 0.8.1)
144
156
  slop (~> 3.4)
145
- public_suffix (2.0.4)
157
+ public_suffix (2.0.5)
146
158
  rainbow (2.1.0)
147
159
  retryable (2.0.4)
148
160
  ridley (5.1.0)
@@ -194,31 +206,34 @@ GEM
194
206
  molinillo (>= 0.5)
195
207
  semverse (>= 1.1, < 3.0)
196
208
  sslshake (1.0.13)
197
- test-kitchen (1.14.2)
209
+ test-kitchen (1.15.0)
198
210
  mixlib-install (>= 1.2, < 3.0)
199
211
  mixlib-shellout (>= 1.2, < 3.0)
200
212
  net-scp (~> 1.1)
201
- net-ssh (>= 2.9, < 4.0)
202
- net-ssh-gateway (~> 1.2.0)
213
+ net-ssh (>= 2.9, < 5.0)
214
+ net-ssh-gateway (~> 1.2)
203
215
  safe_yaml (~> 1.0)
204
216
  thor (~> 0.18)
205
- thor (0.19.4)
217
+ thor (0.19.1)
206
218
  timers (4.0.4)
207
219
  hitimes
208
- train (0.22.0)
220
+ train (0.22.1)
209
221
  docker-api (~> 1.26)
210
222
  json (>= 1.8, < 3.0)
211
223
  mixlib-shellout (~> 2.0)
212
224
  net-scp (~> 1.2)
213
- net-ssh (>= 2.9, < 4.0)
225
+ net-ssh (>= 2.9, < 5.0)
214
226
  winrm (~> 2.0)
215
227
  winrm-fs (~> 1.0)
228
+ unf (0.1.4)
229
+ unf_ext
230
+ unf_ext (0.0.7.2)
216
231
  varia_model (0.6.0)
217
232
  buff-extensions (~> 2.0)
218
233
  hashie (>= 2.0.2, < 4.0.0)
219
234
  windows_chef_zero (2.0.0)
220
235
  test-kitchen (>= 1.2.1)
221
- winrm (2.1.0)
236
+ winrm (2.1.2)
222
237
  builder (>= 2.1.2)
223
238
  erubis (~> 2.7)
224
239
  gssapi (~> 1.2)
@@ -246,6 +261,7 @@ DEPENDENCIES
246
261
  kitchen-inspec
247
262
  kitchen-vagrant
248
263
  mixlib-install (= 1.2.3)
264
+ rainbow (>= 2.1.0, < 2.2)
249
265
  rspec-core (= 3.4.4)
250
266
  test-kitchen
251
267
  windows_chef_zero
@@ -44,8 +44,9 @@ Gem::Specification.new do |gem|
44
44
  gem.add_dependency "ffi-yajl", ">= 1.0", "< 3.0"
45
45
  gem.add_dependency "minitar", "~> 0.5.4"
46
46
  gem.add_dependency "chef", "~> 12.5"
47
- gem.add_dependency "solve", ">= 2.0.1"
48
- gem.add_dependency "cookbook-omnifetch", "~> 0.2", ">= 0.2.2"
47
+ gem.add_dependency "solve", "< 4.0", "> 2.0"
48
+ gem.add_dependency "addressable", ">= 2.3.5", "< 2.6"
49
+ gem.add_dependency "cookbook-omnifetch", "~> 0.5"
49
50
  gem.add_dependency "diff-lcs", "~> 1.0"
50
51
  gem.add_dependency "paint", "~> 1.0"
51
52
  gem.add_dependency "chef-provisioning", "~> 2.0"
@@ -83,7 +83,7 @@ E
83
83
  end
84
84
 
85
85
  def installer
86
- @installer ||= PolicyfileServices::Install.new(policyfile: policyfile_relative_path, ui: ui, root_dir: Dir.pwd)
86
+ @installer ||= PolicyfileServices::Install.new(policyfile: policyfile_relative_path, ui: ui, root_dir: Dir.pwd, config: chef_config)
87
87
  end
88
88
 
89
89
  def debug?
@@ -62,6 +62,16 @@ module ChefDK
62
62
  class PolicyfileError < StandardError
63
63
  end
64
64
 
65
+ class InvalidPolicyfileSourceURI < StandardError
66
+ def initialize(url, reason = nil)
67
+ @url = url
68
+ @reason = reason
69
+ msg = "'#{@url}' is not a valid Policy File Source URI"
70
+ msg << " #{@reason}." unless @reason.nil?
71
+ super(msg)
72
+ end
73
+ end
74
+
65
75
  class MissingCookbookLockData < StandardError
66
76
  end
67
77
 
@@ -15,28 +15,60 @@
15
15
  # limitations under the License.
16
16
  #
17
17
 
18
+ require 'ffi_yajl'
18
19
  require 'chef-dk/exceptions'
20
+ require 'chef-dk/policyfile/source_uri'
21
+ require 'chef-dk/authenticated_http'
19
22
 
20
23
  module ChefDK
21
24
  module Policyfile
22
25
  class ChefServerCookbookSource
23
-
24
26
  attr_reader :uri
27
+ attr_reader :preferred_cookbooks
28
+ attr_reader :chef_config
29
+
30
+ def initialize(uri, chef_config: nil)
31
+ @uri = SourceURI.parse(uri)
32
+ @http_connections = {}
33
+ @chef_config = chef_config
34
+ @preferred_cookbooks = []
35
+ yield self if block_given?
36
+ end
25
37
 
26
- def initialize(uri)
27
- @uri = uri
38
+ def default_source_args
39
+ [:chef_server, uri]
28
40
  end
29
41
 
30
42
  def ==(other)
31
- other.kind_of?(self.class) && other.uri == uri
43
+ other.kind_of?(self.class) && other.uri == uri && other.preferred_cookbooks == preferred_cookbooks
44
+ end
45
+
46
+ def preferred_for(*cookbook_names)
47
+ preferred_cookbooks.concat(cookbook_names)
48
+ end
49
+
50
+ def preferred_source_for?(cookbook_name)
51
+ preferred_cookbooks.include?(cookbook_name)
32
52
  end
33
53
 
34
54
  def universe_graph
35
- raise UnsupportedFeature, 'ChefDK does not support chef-server cookbook default sources at this time'
55
+ @universe_graph ||= begin
56
+ full_chef_server_graph.inject({}) do |normalized_graph, (cookbook_name, metadata_by_version)|
57
+ normalized_graph[cookbook_name] = metadata_by_version.inject({}) do |deps_by_version, (version, metadata)|
58
+ deps_by_version[version] = metadata["dependencies"]
59
+ deps_by_version
60
+ end
61
+ normalized_graph
62
+ end
63
+ end
36
64
  end
37
65
 
38
66
  def source_options_for(cookbook_name, cookbook_version)
39
- raise UnsupportedFeature, 'ChefDK does not support chef-server cookbook default sources at this time'
67
+ {
68
+ chef_server: uri.to_s,
69
+ version: cookbook_version,
70
+ http_client: http_connection_for(uri.to_s)
71
+ }
40
72
  end
41
73
 
42
74
  def null?
@@ -47,8 +79,20 @@ module ChefDK
47
79
  "chef_server(#{uri})"
48
80
  end
49
81
 
82
+ private
83
+
84
+ def http_connection_for(base_url)
85
+ @http_connections[base_url] ||= ChefDK::AuthenticatedHTTP.new(base_url,
86
+ signing_key_filename: chef_config.client_key,
87
+ client_name: chef_config.node_name)
88
+ end
89
+
90
+ def full_chef_server_graph
91
+ @full_chef_server_graph ||=
92
+ begin
93
+ http_connection_for(uri.to_s).get('/universe')
94
+ end
95
+ end
50
96
  end
51
97
  end
52
98
  end
53
-
54
-
@@ -94,4 +94,3 @@ module ChefDK
94
94
  end
95
95
  end
96
96
  end
97
-
@@ -29,7 +29,7 @@ module ChefDK
29
29
  # API contract
30
30
  include StorageConfigDelegation
31
31
 
32
- SOURCE_TYPES = [:git, :github, :path, :artifactserver]
32
+ SOURCE_TYPES = [:git, :github, :path, :artifactserver, :chef_server]
33
33
 
34
34
  #--
35
35
  # Required by CookbookOmnifetch API contract
@@ -69,7 +69,7 @@ module ChefDK
69
69
  end
70
70
 
71
71
  def mirrors_canonical_upstream?
72
- [:git, :github, :artifactserver].include?(source_type)
72
+ [:git, :github, :artifactserver, :chef_server].include?(source_type)
73
73
  end
74
74
 
75
75
  def installed?
@@ -42,7 +42,8 @@ module ChefDK
42
42
 
43
43
  attr_reader :storage_config
44
44
 
45
- def initialize(storage_config)
45
+ attr_reader :chef_config
46
+ def initialize(storage_config, chef_config: nil)
46
47
  @name = nil
47
48
  @errors = []
48
49
  @run_list = []
@@ -50,6 +51,7 @@ module ChefDK
50
51
  @default_source = [ NullCookbookSource.new ]
51
52
  @cookbook_location_specs = {}
52
53
  @storage_config = storage_config
54
+ @chef_config = chef_config
53
55
 
54
56
  @node_attributes = Chef::Node::Attribute.new({}, {}, {}, {})
55
57
  end
@@ -168,7 +170,7 @@ module ChefDK
168
170
  if source_uri.nil?
169
171
  @errors << "You must specify the server's URI when using a default_source :chef_server"
170
172
  else
171
- set_default_source(ChefServerCookbookSource.new(source_uri))
173
+ set_default_source(ChefServerCookbookSource.new(source_uri, chef_config: chef_config, &block))
172
174
  end
173
175
  end
174
176
 
@@ -0,0 +1,57 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2016 Chef Software Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'addressable/uri'
19
+ require 'chef-dk/exceptions'
20
+
21
+ module ChefDK
22
+ module Policyfile
23
+ class SourceURI < Addressable::URI
24
+ class << self
25
+ # Returns a URI object based on the parsed string.
26
+ #
27
+ # @param [String, Addressable::URI, #to_str] uri The URI
28
+ # string to parse. No parsing is performed if the object
29
+ # is already an <code>Addressable::URI</code>.
30
+ #
31
+ # @raise [ChefDK::InvalidPolicyfileSourceURI]
32
+ #
33
+ # @return [ChefDK::Policyfile::SourceURI]
34
+ def parse(uri)
35
+ parsed_uri = super(uri)
36
+ parsed_uri.send(:validate)
37
+ parsed_uri
38
+ rescue TypeError, ArgumentError => ex
39
+ raise ChefDK::InvalidPolicyfileSourceURI.new(uri, ex)
40
+ end
41
+ end
42
+
43
+ VALID_SCHEMES = %w{ https http }.freeze
44
+
45
+ # @raise [ChefDK::InvalidPolicyfileSourceURI]
46
+ def validate
47
+ super
48
+
49
+ unless VALID_SCHEMES.include?(self.scheme)
50
+ raise InvalidPolicyfileSourceURI.new(self, "invalid URI scheme '#{self.scheme}'. Valid schemes: #{VALID_SCHEMES}")
51
+ end
52
+ rescue Addressable::URI::InvalidURIError => ex
53
+ raise InvalidPolicyfileSourceURI.new(self, ex)
54
+ end
55
+ end
56
+ end
57
+ end