chef 13.2.20 → 13.3.42

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +1 -1
  3. data/Gemfile +2 -8
  4. data/README.md +6 -2
  5. data/Rakefile +0 -11
  6. data/VERSION +1 -1
  7. data/acceptance/Gemfile.lock +1 -1
  8. data/acceptance/data-collector/.acceptance/data-collector-test/files/default/api.rb +34 -18
  9. data/acceptance/data-collector/.acceptance/data-collector-test/recipes/default.rb +6 -0
  10. data/lib/chef/cookbook/metadata.rb +2 -2
  11. data/lib/chef/deprecation/warnings.rb +3 -1
  12. data/lib/chef/exceptions.rb +1 -1
  13. data/lib/chef/http.rb +9 -10
  14. data/lib/chef/http/api_versions.rb +2 -0
  15. data/lib/chef/http/http_request.rb +3 -0
  16. data/lib/chef/knife/core/bootstrap_context.rb +1 -0
  17. data/lib/chef/knife/core/status_presenter.rb +1 -1
  18. data/lib/chef/knife/ssh.rb +4 -0
  19. data/lib/chef/provider/apt_preference.rb +99 -0
  20. data/lib/chef/provider/execute.rb +3 -2
  21. data/lib/chef/provider/http_request.rb +14 -0
  22. data/lib/chef/provider/mount/aix.rb +49 -8
  23. data/lib/chef/provider/package/windows/registry_uninstall_entry.rb +1 -1
  24. data/lib/chef/provider/package/zypper.rb +5 -5
  25. data/lib/chef/provider/service/systemd.rb +12 -11
  26. data/lib/chef/provider/support/zypper_repo.erb +17 -0
  27. data/lib/chef/provider/systemd_unit.rb +3 -2
  28. data/lib/chef/provider/windows_task.rb +92 -71
  29. data/lib/chef/provider/zypper_repository.rb +81 -0
  30. data/lib/chef/providers.rb +2 -0
  31. data/lib/chef/resource/apt_preference.rb +36 -0
  32. data/lib/chef/resource/execute.rb +12 -2
  33. data/lib/chef/resource/http_request.rb +1 -1
  34. data/lib/chef/resource/zypper_repository.rb +51 -0
  35. data/lib/chef/resources.rb +2 -0
  36. data/lib/chef/search/query.rb +6 -1
  37. data/lib/chef/server_api_versions.rb +21 -2
  38. data/lib/chef/version.rb +3 -4
  39. data/lib/chef/win32/api/file.rb +1 -0
  40. data/lib/chef/win32/file.rb +2 -0
  41. data/lib/chef/win32/version.rb +6 -0
  42. data/spec/functional/knife/ssh_spec.rb +1 -1
  43. data/spec/functional/resource/execute_spec.rb +2 -2
  44. data/spec/spec_helper.rb +8 -1
  45. data/spec/unit/cookbook/metadata_spec.rb +3 -3
  46. data/spec/unit/http/api_versions_spec.rb +6 -3
  47. data/spec/unit/knife/bootstrap_spec.rb +4 -0
  48. data/spec/unit/knife/cookbook_show_spec.rb +3 -3
  49. data/spec/unit/knife/ssh_spec.rb +7 -1
  50. data/spec/unit/knife/status_spec.rb +2 -0
  51. data/spec/unit/provider/apt_preference_spec.rb +87 -0
  52. data/spec/unit/provider/apt_update_spec.rb +7 -7
  53. data/spec/unit/provider/dsc_resource_spec.rb +2 -2
  54. data/spec/unit/provider/execute_spec.rb +32 -14
  55. data/spec/unit/provider/mount/aix_spec.rb +33 -1
  56. data/spec/unit/provider/package/rubygems_spec.rb +1 -1
  57. data/spec/unit/provider/package/windows/registry_uninstall_entry_spec.rb +56 -3
  58. data/spec/unit/provider/package/windows_spec.rb +1 -1
  59. data/spec/unit/provider/package/zypper_spec.rb +43 -0
  60. data/spec/unit/provider/script_spec.rb +1 -1
  61. data/spec/unit/provider/service/systemd_service_spec.rb +23 -21
  62. data/spec/unit/provider/systemd_unit_spec.rb +42 -41
  63. data/spec/unit/provider/windows_task_spec.rb +40 -0
  64. data/spec/unit/resource/apt_preference_spec.rb +41 -0
  65. data/spec/unit/resource/execute_spec.rb +21 -1
  66. data/spec/unit/resource/powershell_script_spec.rb +2 -2
  67. data/spec/unit/resource/zypper_repository_spec.rb +65 -0
  68. data/spec/unit/search/query_spec.rb +13 -18
  69. data/spec/unit/server_api_spec.rb +75 -1
  70. data/spec/unit/server_api_versions_spec.rb +22 -0
  71. data/spec/unit/win32/link_spec.rb +73 -0
  72. data/tasks/dependencies.rb +0 -1
  73. metadata +13 -6
  74. data/tasks/changelog.rb +0 -37
  75. data/tasks/version.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 46f3d5cd0336f4203b7e6d5dc6b2ad968f02d0db
4
- data.tar.gz: 133bae912a030f9d8443f34d37d05e27a5a9952b
3
+ metadata.gz: 244f9d815246c3d954e9794813133b95395fac26
4
+ data.tar.gz: beb5752e4b20493f5b754e20cbe118da4dadf2d6
5
5
  SHA512:
6
- metadata.gz: dfaf798e23a92d0ce78b6cab250f8ad7035a002f8ba8b7c0be9e44d355d608ca948be756d5f432af5f758e9929de123c235e89a09e19fcb0c4c9c11d1d94fc9b
7
- data.tar.gz: '089f2e2c8ac56f720faeac7933bebc13e50522538e3f5feb706a58e110245259517ce41f43910f812b33193817abaebd3a7896ae2be1976fb9e849a4fb9b7ca1'
6
+ metadata.gz: '091dcc6ee3ea1710e4998795452dec480e07b36db38c0b7e33054ee50c96462358a108a44cb9a86a8632d5f3a41c3b2301f07bc37d3fd192e17dcedaade45049'
7
+ data.tar.gz: 488d579aed0dd49078cc89965ece8d61c815aa3cc0f085028ad6ef854272d494cf69b7fec18f0ce9a52f793d636c6612b6bb2d82f654fdd7614b2f2f699e4576
@@ -90,7 +90,7 @@ The DCO requires a sign-off message in the following format appear on each commi
90
90
  Signed-off-by: Julia Child <juliachild@chef.io>
91
91
  ```
92
92
 
93
- The DCO text can either be manually added to your commit body, or you can add either **-s** or **--signoff** to your usual git commit commands. If you forget to add the sign-off you can also amend a previous commit with the sign-off by running **git commit –-amend -s**. If you've pushed your changes to Github already you'll need to force push your branch after this with **git push -f**.
93
+ The DCO text can either be manually added to your commit body, or you can add either **-s** or **--signoff** to your usual git commit commands. If you forget to add the sign-off you can also amend a previous commit with the sign-off by running **git commit --amend -s**. If you've pushed your changes to Github already you'll need to force push your branch after this with **git push -f**.
94
94
 
95
95
  ### Chef Obvious Fix Policy
96
96
 
data/Gemfile CHANGED
@@ -16,8 +16,6 @@ group(:omnibus_package) do
16
16
  gem "appbundler"
17
17
  gem "rb-readline"
18
18
  gem "inspec"
19
- # nokogiri has no ruby-2.4 version for windows so it cannot go into our Gemfile.lock
20
- # gem "nokogiri", ">= 1.7.1"
21
19
  end
22
20
 
23
21
  group(:omnibus_package, :pry) do
@@ -31,7 +29,7 @@ group(:docgen) do
31
29
  gem "yard"
32
30
  end
33
31
 
34
- group(:maintenance, :ci) do
32
+ group(:maintenance) do
35
33
  gem "tomlrb"
36
34
 
37
35
  # To sync maintainers with github
@@ -52,17 +50,13 @@ end
52
50
  group(:development, :test) do
53
51
  gem "rake"
54
52
  gem "simplecov"
53
+ gem "webmock"
55
54
 
56
55
  # for testing new chefstyle rules
57
56
  # gem 'chefstyle', github: 'chef/chefstyle'
58
57
  gem "chefstyle", git: "https://github.com/chef/chefstyle.git", branch: "master"
59
58
  end
60
59
 
61
- group(:ci) do
62
- gem "github_changelog_generator", git: "https://github.com/chef/github-changelog-generator"
63
- gem "mixlib-install"
64
- end
65
-
66
60
  group(:travis) do
67
61
  # See `bundler-audit` in .travis.yml
68
62
  gem "bundler-audit", git: "https://github.com/rubysec/bundler-audit.git"
data/README.md CHANGED
@@ -5,7 +5,11 @@
5
5
  [![Gem Version](https://badge.fury.io/rb/chef.svg)](https://badge.fury.io/rb/chef)
6
6
  [![](https://img.shields.io/badge/Release%20Policy-Cadence%20Release-brightgreen.svg)](https://github.com/chef/chef-rfc/blob/master/rfc086-chef-oss-project-policies.md#cadence-release)
7
7
 
8
- Want to try Chef? Get started with [learnchef](https://learn.chef.io)
8
+ ## Getting Started
9
+
10
+ Want to try Chef?
11
+ For Chef user, please refer to [Quick Start](https://docs.chef.io/quick_start.html)
12
+ For more details, please refer to [learnchef](https://learn.chef.io)
9
13
 
10
14
  - Documentation: <https://docs.chef.io>
11
15
  - Source: <https://github.com/chef/chef/tree/master>
@@ -37,7 +41,7 @@ to report issues against in the Chef docs in the
37
41
  If you can't determine the appropriate place to report an issue, then please open it
38
42
  against the repository you think best fits and it will be directed to the appropriate project.
39
43
 
40
- ## Installing From Git
44
+ ## Installing From Git for Developers
41
45
 
42
46
  **NOTE:** As a Chef user, please download the omnibus package of [Chef](https://downloads.chef.io/chef) or [Chef-DK](https://downloads.chef.io/chef)
43
47
 
data/Rakefile CHANGED
@@ -27,9 +27,7 @@ require_relative "tasks/rspec"
27
27
  require_relative "tasks/maintainers"
28
28
  require_relative "tasks/cbgb"
29
29
  require_relative "tasks/dependencies"
30
- require_relative "tasks/changelog"
31
30
  require_relative "tasks/announce"
32
- require_relative "tasks/version"
33
31
 
34
32
  ChefConfig::PackageTask.new(File.expand_path("..", __FILE__), "Chef", "chef") do |package|
35
33
  package.component_paths = ["chef-config"]
@@ -51,15 +49,6 @@ task :register_eventlog do
51
49
  end
52
50
  end
53
51
 
54
- desc "Keep the Dockerfile up-to-date"
55
- task :update_dockerfile do
56
- require "mixlib/install"
57
- latest_stable_version = Mixlib::Install.available_versions("chef", "stable").last
58
- text = File.read("Dockerfile")
59
- new_text = text.gsub(/^ARG VERSION=[\d\.]+$/, "ARG VERSION=#{latest_stable_version}")
60
- File.open("Dockerfile", "w+") { |f| f.write(new_text) }
61
- end
62
-
63
52
  begin
64
53
  require "chefstyle"
65
54
  require "rubocop/rake_task"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 13.2.20
1
+ 13.3.42
@@ -128,7 +128,7 @@ GEM
128
128
  mixlib-shellout
129
129
  mixlib-versioning
130
130
  mixlib-log (1.7.1)
131
- mixlib-shellout (2.2.7)
131
+ mixlib-shellout (2.3.2)
132
132
  mixlib-versioning (1.1.0)
133
133
  molinillo (0.5.7)
134
134
  multi_json (1.12.1)
@@ -17,35 +17,51 @@ module ApiHelpers
17
17
  end
18
18
 
19
19
  class Counter
20
- def self.reset
21
- @@counters = Hash.new { |h, k| h[k] = 0 }
22
- end
20
+ class << self
21
+ attr_accessor :counters
23
22
 
24
- def self.increment(payload)
25
- counter_name = ApiHelpers.payload_type(payload)
26
- @@counters[counter_name] += 1
27
- end
23
+ def counters
24
+ @counters ||= Hash.new { |h, k| h[k] = 0 }
25
+ end
26
+
27
+ def reset
28
+ @counters = nil
29
+ end
30
+
31
+ def increment(payload)
32
+ counter_name = ApiHelpers.payload_type(payload)
33
+ counters[counter_name] += 1
34
+ end
28
35
 
29
- def self.to_json
30
- @@counters.to_json
36
+ def to_json
37
+ counters.to_json
38
+ end
31
39
  end
32
40
  end
33
41
 
34
42
  class MessageCache
35
43
  include ApiHelpers
36
44
 
37
- def self.reset
38
- @@message_cache = {}
39
- end
45
+ class << self
46
+ attr_accessor :message_cache
40
47
 
41
- def self.store(payload)
42
- cache_key = ApiHelpers.payload_type(payload)
48
+ def message_cache
49
+ @message_cache ||= {}
50
+ end
43
51
 
44
- @@message_cache[cache_key] = payload
45
- end
52
+ def reset
53
+ @message_cache = nil
54
+ end
55
+
56
+ def store(payload)
57
+ cache_key = ApiHelpers.payload_type(payload)
58
+
59
+ message_cache[cache_key] = payload
60
+ end
46
61
 
47
- def self.fetch(cache_key)
48
- @@message_cache[cache_key].to_json
62
+ def fetch(cache_key)
63
+ message_cache[cache_key].to_json
64
+ end
49
65
  end
50
66
  end
51
67
 
@@ -1,3 +1,6 @@
1
+
2
+ embedded_path = "/opt/chef/embedded/bin:#{ENV["PATH"]}"
3
+
1
4
  api_root_dir = "/var/opt/data_collector_api"
2
5
 
3
6
  directory api_root_dir do
@@ -14,6 +17,7 @@ cookbook_file ::File.join(api_root_dir, "api.rb")
14
17
 
15
18
  execute "bundle install --binstubs" do
16
19
  cwd api_root_dir
20
+ environment({ "PATH" => embedded_path })
17
21
  end
18
22
 
19
23
  pid_file = "/var/run/api.pid"
@@ -21,11 +25,13 @@ running_pid = ::File.exist?(pid_file) ? ::File.read(pid_file).strip : nil
21
25
 
22
26
  execute "kill existing API process" do
23
27
  command "kill #{running_pid}"
28
+ environment({ "PATH" => embedded_path })
24
29
  not_if { running_pid.nil? }
25
30
  end
26
31
 
27
32
  execute "start API" do
28
33
  command "bin/rackup -D -P #{pid_file}"
34
+ environment({ "PATH" => embedded_path })
29
35
  cwd api_root_dir
30
36
  end
31
37
 
@@ -100,8 +100,8 @@ class Chef
100
100
  @long_description = ""
101
101
  @license = "All rights reserved"
102
102
 
103
- @maintainer = nil
104
- @maintainer_email = nil
103
+ @maintainer = ""
104
+ @maintainer_email = ""
105
105
 
106
106
  @platforms = Mash.new
107
107
  @dependencies = Mash.new
@@ -20,10 +20,12 @@ class Chef
20
20
  module Deprecation
21
21
  module Warnings
22
22
 
23
+ require "chef/version"
24
+
23
25
  def add_deprecation_warnings_for(method_names)
24
26
  method_names.each do |name|
25
27
  define_method(name) do |*args|
26
- message = "Method '#{name}' of '#{self.class}' is deprecated. It will be removed in Chef 13."
28
+ message = "Method '#{name}' of '#{self.class}' is deprecated. It will be removed in Chef #{Chef::VERSION.to_i.next}."
27
29
  message << " Please update your cookbooks accordingly."
28
30
  Chef.deprecated(:internal_api, message)
29
31
  super(*args)
@@ -515,7 +515,7 @@ This error is most often caused by network issues (proxies, etc) outside of chef
515
515
  "Resource #{r['Name']} is a binary resource"
516
516
  end
517
517
  end
518
- super "Found multiple matching resources. #{matches_info.join("\n")}"
518
+ super "Found multiple resources matching #{matches_info[0]["Module"]["Name"]}:\n#{(matches_info.map { |f| f["Module"]["Version"] }).uniq.join("\n")}"
519
519
  end
520
520
  end
521
521
 
@@ -5,7 +5,7 @@
5
5
  # Author:: Christopher Brown (<cb@chef.io>)
6
6
  # Author:: Christopher Walters (<cw@chef.io>)
7
7
  # Author:: Daniel DeLeo (<dan@chef.io>)
8
- # Copyright:: Copyright 2009-2016 Chef Software, Inc.
8
+ # Copyright:: Copyright 2009-2017, Chef Software Inc.
9
9
  # License:: Apache License, Version 2.0
10
10
  #
11
11
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -144,9 +144,9 @@ class Chef
144
144
  def request(method, path, headers = {}, data = false)
145
145
  http_attempts ||= 0
146
146
  url = create_url(path)
147
- method, url, headers, data = apply_request_middleware(method, url, headers, data)
147
+ processed_method, url, processed_headers, processed_data = apply_request_middleware(method, url, headers, data)
148
148
 
149
- response, rest_request, return_value = send_http_request(method, url, headers, data)
149
+ response, rest_request, return_value = send_http_request(processed_method, url, processed_headers, processed_data)
150
150
  response, rest_request, return_value = apply_response_middleware(response, rest_request, return_value)
151
151
 
152
152
  response.error! unless success_response?(response)
@@ -157,7 +157,6 @@ class Chef
157
157
  response = e.response
158
158
  if response.kind_of?(Net::HTTPNotAcceptable) && version_retries - http_attempts > 0
159
159
  Chef::Log.debug("Negotiating protocol version with #{url}, retry #{http_attempts}/#{version_retries}")
160
- sleep(http_retry_delay)
161
160
  retry
162
161
  else
163
162
  raise
@@ -176,11 +175,12 @@ class Chef
176
175
  url = create_url(path)
177
176
  response, rest_request, return_value = nil, nil, nil
178
177
  tempfile = nil
178
+ data = nil
179
179
 
180
180
  method = :GET
181
- method, url, headers, data = apply_request_middleware(method, url, headers, data)
181
+ method, url, processed_headers, data = apply_request_middleware(method, url, headers, data)
182
182
 
183
- response, rest_request, return_value = send_http_request(method, url, headers, data) do |http_response|
183
+ response, rest_request, return_value = send_http_request(method, url, processed_headers, data) do |http_response|
184
184
  if http_response.kind_of?(Net::HTTPSuccess)
185
185
  tempfile = stream_to_tempfile(url, http_response, &progress_block)
186
186
  end
@@ -196,7 +196,6 @@ class Chef
196
196
  response = e.response
197
197
  if response.kind_of?(Net::HTTPNotAcceptable) && version_retries - http_attempts > 0
198
198
  Chef::Log.debug("Negotiating protocol version with #{url}, retry #{http_attempts}/#{version_retries}")
199
- sleep(http_retry_delay)
200
199
  retry
201
200
  else
202
201
  raise
@@ -223,11 +222,12 @@ class Chef
223
222
  url = create_url(path)
224
223
  response, rest_request, return_value = nil, nil, nil
225
224
  tempfile = nil
225
+ data = nil
226
226
 
227
227
  method = :GET
228
- method, url, headers, data = apply_request_middleware(method, url, headers, data)
228
+ method, url, processed_headers, data = apply_request_middleware(method, url, headers, data)
229
229
 
230
- response, rest_request, return_value = send_http_request(method, url, headers, data) do |http_response|
230
+ response, rest_request, return_value = send_http_request(method, url, processed_headers, data) do |http_response|
231
231
  if http_response.kind_of?(Net::HTTPSuccess)
232
232
  tempfile = stream_to_tempfile(url, http_response)
233
233
  end
@@ -252,7 +252,6 @@ class Chef
252
252
  response = e.response
253
253
  if response.kind_of?(Net::HTTPNotAcceptable) && version_retries - http_attempts > 0
254
254
  Chef::Log.debug("Negotiating protocol version with #{url}, retry #{http_attempts}/#{version_retries}")
255
- sleep(http_retry_delay)
256
255
  retry
257
256
  else
258
257
  raise
@@ -37,6 +37,8 @@ class Chef
37
37
  end
38
38
  if http_response.key?("x-ops-server-api-version")
39
39
  ServerAPIVersions.instance.set_versions(JSONCompat.parse(http_response["x-ops-server-api-version"]))
40
+ else
41
+ ServerAPIVersions.instance.unversioned!
40
42
  end
41
43
  [http_response, rest_request, return_value]
42
44
  end
@@ -49,6 +49,7 @@ class Chef
49
49
  ENCODING_GZIP_DEFLATE = "gzip;q=1.0,deflate;q=0.6,identity;q=0.3".freeze
50
50
 
51
51
  GET = "get".freeze
52
+ PATCH = "patch".freeze
52
53
  PUT = "put".freeze
53
54
  POST = "post".freeze
54
55
  DELETE = "delete".freeze
@@ -161,6 +162,8 @@ class Chef
161
162
  Net::HTTP::Post.new(req_path, headers)
162
163
  when PUT
163
164
  Net::HTTP::Put.new(req_path, headers)
165
+ when PATCH
166
+ Net::HTTP::Patch.new(req_path, headers)
164
167
  when DELETE
165
168
  Net::HTTP::Delete.new(req_path, headers)
166
169
  when HEAD
@@ -223,6 +223,7 @@ validation_client_name "#{@chef_config[:validation_client_name]}"
223
223
  attributes[:run_list] = @run_list
224
224
  end
225
225
 
226
+ attributes.delete(:run_list) if attributes[:policy_name] && !attributes[:policy_name].empty?
226
227
  attributes.merge!(:tags => @config[:tags]) if @config[:tags] && !@config[:tags].empty?
227
228
  end
228
229
  end
@@ -123,7 +123,7 @@ class Chef
123
123
  line_parts << run_list if run_list
124
124
 
125
125
  if node["platform"]
126
- platform = node["platform"]
126
+ platform = node["platform"].dup
127
127
  if node["platform_version"]
128
128
  platform << " #{node['platform_version']}"
129
129
  end
@@ -273,6 +273,10 @@ class Chef
273
273
  opts[:paranoid] = false
274
274
  opts[:user_known_hosts_file] = "/dev/null"
275
275
  end
276
+ if ssh_config[:keepalive]
277
+ opts[:keepalive] = true
278
+ opts[:keepalive_interval] = ssh_config[:keepalive_interval]
279
+ end
276
280
  end
277
281
  end
278
282
 
@@ -0,0 +1,99 @@
1
+ #
2
+ # Author:: Tim Smith (<tsmith@chef.io>)
3
+ # Copyright:: 2016-2017, Chef Software, Inc.
4
+ # License:: Apache License, Version 2.0
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+
19
+ require "chef/provider"
20
+ require "chef/dsl/declare_resource"
21
+ require "chef/provider/noop"
22
+ require "chef/mixin/which"
23
+ require "chef/log"
24
+
25
+ class Chef
26
+ class Provider
27
+ class AptPreference < Chef::Provider
28
+ extend Chef::Mixin::Which
29
+
30
+ provides :apt_preference do
31
+ which("apt-get")
32
+ end
33
+
34
+ APT_PREFERENCE_DIR = "/etc/apt/preferences.d".freeze
35
+
36
+ def load_current_resource
37
+ end
38
+
39
+ action :add do
40
+ preference = build_pref(
41
+ new_resource.glob || new_resource.package_name,
42
+ new_resource.pin,
43
+ new_resource.pin_priority
44
+ )
45
+
46
+ declare_resource(:directory, APT_PREFERENCE_DIR) do
47
+ mode "0755"
48
+ action :create
49
+ end
50
+
51
+ sanitized_prefname = safe_name(new_resource.package_name)
52
+
53
+ # cleanup any existing pref files w/o the sanitized name (created by old apt cookbook)
54
+ if (sanitized_prefname != new_resource.package_name) && ::File.exist?("#{APT_PREFERENCE_DIR}/#{new_resource.package_name}.pref")
55
+ Chef::Log.warn "Replacing legacy #{new_resource.package_name}.pref with #{sanitized_prefname}.pref in #{APT_PREFERENCE_DIR}"
56
+ declare_resource(:file, "#{APT_PREFERENCE_DIR}/#{new_resource.package_name}.pref") do
57
+ action :delete
58
+ end
59
+ end
60
+
61
+ # cleanup any existing pref files without the .pref extension (created by old apt cookbook)
62
+ if ::File.exist?("#{APT_PREFERENCE_DIR}/#{new_resource.package_name}")
63
+ Chef::Log.warn "Replacing legacy #{new_resource.package_name} with #{sanitized_prefname}.pref in #{APT_PREFERENCE_DIR}"
64
+ declare_resource(:file, "#{APT_PREFERENCE_DIR}/#{new_resource.package_name}") do
65
+ action :delete
66
+ end
67
+ end
68
+
69
+ declare_resource(:file, "#{APT_PREFERENCE_DIR}/#{sanitized_prefname}.pref") do
70
+ mode "0644"
71
+ content preference
72
+ action :create
73
+ end
74
+ end
75
+
76
+ action :remove do
77
+ sanitized_prefname = safe_name(new_resource.package_name)
78
+
79
+ if ::File.exist?("#{APT_PREFERENCE_DIR}/#{sanitized_prefname}.pref")
80
+ Chef::Log.info "Un-pinning #{sanitized_prefname} from #{APT_PREFERENCE_DIR}"
81
+ declare_resource(:file, "#{APT_PREFERENCE_DIR}/#{sanitized_prefname}.pref") do
82
+ action :delete
83
+ end
84
+ end
85
+ end
86
+
87
+ # Build preferences.d file contents
88
+ def build_pref(package_name, pin, pin_priority)
89
+ "Package: #{package_name}\nPin: #{pin}\nPin-Priority: #{pin_priority}\n"
90
+ end
91
+
92
+ def safe_name(name)
93
+ name.tr(".", "_").gsub("*", "wildcard")
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ Chef::Provider::Noop.provides :apt_preference