chef 17.1.35-universal-mingw32 → 17.4.38-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (198) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -4
  3. data/chef.gemspec +1 -0
  4. data/lib/chef/action_collection.rb +6 -26
  5. data/lib/chef/application/base.rb +15 -0
  6. data/lib/chef/application.rb +4 -2
  7. data/lib/chef/client.rb +7 -1
  8. data/lib/chef/compliance/default_attributes.rb +5 -3
  9. data/lib/chef/compliance/reporter/automate.rb +1 -1
  10. data/lib/chef/compliance/runner.rb +16 -2
  11. data/lib/chef/cookbook_version.rb +26 -4
  12. data/lib/chef/data_collector/run_end_message.rb +1 -1
  13. data/lib/chef/data_collector.rb +0 -1
  14. data/lib/chef/deprecated.rb +14 -4
  15. data/lib/chef/dsl/render_helpers.rb +44 -0
  16. data/lib/chef/dsl/secret.rb +64 -0
  17. data/lib/chef/dsl/toml.rb +116 -0
  18. data/lib/chef/dsl/universal.rb +5 -0
  19. data/lib/chef/dsl.rb +1 -0
  20. data/lib/chef/event_dispatch/base.rb +2 -1
  21. data/lib/chef/exceptions.rb +23 -0
  22. data/lib/chef/formatters/doc.rb +14 -13
  23. data/lib/chef/formatters/error_mapper.rb +2 -2
  24. data/lib/chef/formatters/minimal.rb +6 -5
  25. data/lib/chef/handler/slow_report.rb +66 -0
  26. data/lib/chef/handler.rb +46 -8
  27. data/lib/chef/http.rb +5 -5
  28. data/lib/chef/json_compat.rb +1 -1
  29. data/lib/chef/node.rb +20 -19
  30. data/lib/chef/policy_builder/policyfile.rb +88 -45
  31. data/lib/chef/provider/execute.rb +1 -1
  32. data/lib/chef/provider/file.rb +2 -2
  33. data/lib/chef/provider/group/dscl.rb +1 -1
  34. data/lib/chef/provider/launchd.rb +6 -6
  35. data/lib/chef/provider/lwrp_base.rb +1 -1
  36. data/lib/chef/provider/package/habitat.rb +168 -0
  37. data/lib/chef/provider/package/powershell.rb +5 -0
  38. data/lib/chef/provider/subversion.rb +4 -4
  39. data/lib/chef/provider/support/yum_repo.erb +1 -1
  40. data/lib/chef/provider/support/zypper_repo.erb +4 -2
  41. data/lib/chef/provider/systemd_unit.rb +17 -16
  42. data/lib/chef/provider/user/mac.rb +3 -3
  43. data/lib/chef/provider/yum_repository.rb +27 -43
  44. data/lib/chef/provider/zypper_repository.rb +30 -34
  45. data/lib/chef/provider.rb +26 -1
  46. data/lib/chef/provider_resolver.rb +8 -2
  47. data/lib/chef/providers.rb +1 -0
  48. data/lib/chef/resource/alternatives.rb +5 -5
  49. data/lib/chef/resource/apt_preference.rb +2 -2
  50. data/lib/chef/resource/apt_repository.rb +2 -2
  51. data/lib/chef/resource/apt_update.rb +4 -4
  52. data/lib/chef/resource/build_essential.rb +1 -1
  53. data/lib/chef/resource/chef_client_config.rb +10 -5
  54. data/lib/chef/resource/chef_client_cron.rb +3 -3
  55. data/lib/chef/resource/chef_client_launchd.rb +3 -3
  56. data/lib/chef/resource/chef_client_scheduled_task.rb +15 -15
  57. data/lib/chef/resource/chef_client_systemd_timer.rb +3 -3
  58. data/lib/chef/resource/chef_client_trusted_certificate.rb +2 -2
  59. data/lib/chef/resource/chef_handler.rb +2 -2
  60. data/lib/chef/resource/chef_sleep.rb +1 -1
  61. data/lib/chef/resource/chef_vault_secret.rb +2 -2
  62. data/lib/chef/resource/chocolatey_feature.rb +2 -2
  63. data/lib/chef/resource/chocolatey_source.rb +1 -1
  64. data/lib/chef/resource/cron/cron_d.rb +4 -6
  65. data/lib/chef/resource/cron_access.rb +1 -1
  66. data/lib/chef/resource/dmg_package.rb +1 -1
  67. data/lib/chef/resource/dsc_resource.rb +1 -1
  68. data/lib/chef/resource/execute.rb +5 -5
  69. data/lib/chef/resource/gem_package.rb +2 -1
  70. data/lib/chef/resource/group.rb +4 -4
  71. data/lib/chef/resource/habitat/_habitat_shared.rb +28 -0
  72. data/lib/chef/resource/habitat/habitat_package.rb +129 -0
  73. data/lib/chef/resource/habitat/habitat_sup.rb +329 -0
  74. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +67 -0
  75. data/lib/chef/resource/habitat/habitat_sup_windows.rb +90 -0
  76. data/lib/chef/resource/habitat_config.rb +107 -0
  77. data/lib/chef/resource/habitat_install.rb +247 -0
  78. data/lib/chef/resource/habitat_service.rb +451 -0
  79. data/lib/chef/resource/habitat_user_toml.rb +92 -0
  80. data/lib/chef/resource/homebrew_cask.rb +18 -7
  81. data/lib/chef/resource/homebrew_package.rb +1 -1
  82. data/lib/chef/resource/homebrew_tap.rb +4 -3
  83. data/lib/chef/resource/homebrew_update.rb +2 -2
  84. data/lib/chef/resource/hostname.rb +49 -7
  85. data/lib/chef/resource/inspec_waiver_file_entry.rb +8 -7
  86. data/lib/chef/resource/kernel_module.rb +6 -6
  87. data/lib/chef/resource/launchd.rb +3 -3
  88. data/lib/chef/resource/locale.rb +1 -1
  89. data/lib/chef/resource/lwrp_base.rb +1 -1
  90. data/lib/chef/resource/macos_userdefaults.rb +2 -2
  91. data/lib/chef/resource/ohai_hint.rb +2 -6
  92. data/lib/chef/resource/openbsd_package.rb +17 -0
  93. data/lib/chef/resource/openssl_dhparam.rb +1 -2
  94. data/lib/chef/resource/openssl_ec_private_key.rb +1 -3
  95. data/lib/chef/resource/openssl_ec_public_key.rb +1 -3
  96. data/lib/chef/resource/openssl_rsa_private_key.rb +1 -3
  97. data/lib/chef/resource/openssl_rsa_public_key.rb +1 -3
  98. data/lib/chef/resource/openssl_x509_certificate.rb +1 -4
  99. data/lib/chef/resource/openssl_x509_crl.rb +1 -3
  100. data/lib/chef/resource/openssl_x509_request.rb +1 -3
  101. data/lib/chef/resource/osx_profile.rb +3 -3
  102. data/lib/chef/resource/plist.rb +1 -1
  103. data/lib/chef/resource/powershell_package_source.rb +2 -4
  104. data/lib/chef/resource/reboot.rb +38 -9
  105. data/lib/chef/resource/remote_directory.rb +2 -2
  106. data/lib/chef/resource/remote_file.rb +1 -1
  107. data/lib/chef/resource/rhsm_errata.rb +0 -2
  108. data/lib/chef/resource/rhsm_errata_level.rb +1 -5
  109. data/lib/chef/resource/rhsm_repo.rb +15 -0
  110. data/lib/chef/resource/rhsm_subscription.rb +5 -5
  111. data/lib/chef/resource/ruby_block.rb +100 -0
  112. data/lib/chef/resource/scm/subversion.rb +1 -1
  113. data/lib/chef/resource/ssh_known_hosts_entry.rb +4 -7
  114. data/lib/chef/resource/sudo.rb +2 -6
  115. data/lib/chef/resource/support/HabService.dll.config.erb +19 -0
  116. data/lib/chef/resource/support/client.erb +8 -1
  117. data/lib/chef/resource/support/sup.toml.erb +179 -0
  118. data/lib/chef/resource/swap_file.rb +2 -6
  119. data/lib/chef/resource/sysctl.rb +2 -2
  120. data/lib/chef/resource/systemd_unit.rb +3 -3
  121. data/lib/chef/resource/timezone.rb +1 -1
  122. data/lib/chef/resource/user_ulimit.rb +2 -2
  123. data/lib/chef/resource/windows_ad_join.rb +2 -2
  124. data/lib/chef/resource/windows_audit_policy.rb +2 -2
  125. data/lib/chef/resource/windows_auto_run.rb +2 -2
  126. data/lib/chef/resource/windows_certificate.rb +1 -1
  127. data/lib/chef/resource/windows_defender.rb +163 -0
  128. data/lib/chef/resource/windows_defender_exclusion.rb +125 -0
  129. data/lib/chef/resource/windows_dfs_folder.rb +2 -2
  130. data/lib/chef/resource/windows_dfs_namespace.rb +2 -2
  131. data/lib/chef/resource/windows_dns_record.rb +2 -2
  132. data/lib/chef/resource/windows_dns_zone.rb +2 -2
  133. data/lib/chef/resource/windows_feature.rb +3 -3
  134. data/lib/chef/resource/windows_feature_dism.rb +3 -5
  135. data/lib/chef/resource/windows_feature_powershell.rb +3 -3
  136. data/lib/chef/resource/windows_firewall_profile.rb +2 -2
  137. data/lib/chef/resource/windows_firewall_rule.rb +20 -6
  138. data/lib/chef/resource/windows_font.rb +1 -1
  139. data/lib/chef/resource/windows_pagefile.rb +103 -64
  140. data/lib/chef/resource/windows_path.rb +2 -2
  141. data/lib/chef/resource/windows_printer.rb +80 -61
  142. data/lib/chef/resource/windows_printer_port.rb +48 -65
  143. data/lib/chef/resource/windows_security_policy.rb +2 -2
  144. data/lib/chef/resource/windows_share.rb +2 -2
  145. data/lib/chef/resource/windows_shortcut.rb +1 -1
  146. data/lib/chef/resource/windows_task.rb +1 -1
  147. data/lib/chef/resource/windows_uac.rb +3 -5
  148. data/lib/chef/resource/windows_update_settings.rb +259 -0
  149. data/lib/chef/resource/windows_user_privilege.rb +2 -2
  150. data/lib/chef/resource/windows_workgroup.rb +2 -2
  151. data/lib/chef/resource/yum_package.rb +11 -15
  152. data/lib/chef/resource/zypper_package.rb +4 -4
  153. data/lib/chef/resource/zypper_repository.rb +28 -8
  154. data/lib/chef/resource.rb +13 -17
  155. data/lib/chef/resource_inspector.rb +6 -2
  156. data/lib/chef/resource_reporter.rb +0 -1
  157. data/lib/chef/resources.rb +12 -1
  158. data/lib/chef/secret_fetcher/aws_secrets_manager.rb +65 -0
  159. data/lib/chef/secret_fetcher/azure_key_vault.rb +78 -0
  160. data/lib/chef/secret_fetcher/base.rb +76 -0
  161. data/lib/chef/secret_fetcher/example.rb +46 -0
  162. data/lib/chef/secret_fetcher.rb +55 -0
  163. data/lib/chef/version.rb +1 -1
  164. data/spec/functional/mixin/from_file_spec.rb +1 -1
  165. data/spec/functional/resource/windows_hostname_spec.rb +91 -0
  166. data/spec/functional/resource/windows_pagefile_spec.rb +98 -0
  167. data/spec/integration/compliance/compliance_spec.rb +1 -0
  168. data/spec/integration/recipes/recipe_dsl_spec.rb +1 -1
  169. data/spec/integration/recipes/resource_action_spec.rb +6 -6
  170. data/spec/support/shared/unit/provider/file.rb +2 -8
  171. data/spec/unit/compliance/runner_spec.rb +46 -2
  172. data/spec/unit/cookbook_version_spec.rb +52 -0
  173. data/spec/unit/data_collector_spec.rb +47 -1
  174. data/spec/unit/dsl/render_helpers_spec.rb +102 -0
  175. data/spec/unit/dsl/secret_spec.rb +71 -0
  176. data/spec/unit/formatters/doc_spec.rb +1 -1
  177. data/spec/unit/handler_spec.rb +8 -2
  178. data/spec/unit/policy_builder/dynamic_spec.rb +0 -5
  179. data/spec/unit/policy_builder/policyfile_spec.rb +144 -56
  180. data/spec/unit/provider/apt_update_spec.rb +3 -1
  181. data/spec/unit/provider/mount/aix_spec.rb +1 -1
  182. data/spec/unit/provider/package/powershell_spec.rb +74 -12
  183. data/spec/unit/provider/zypper_repository_spec.rb +3 -10
  184. data/spec/unit/provider_spec.rb +23 -0
  185. data/spec/unit/resource/homebrew_cask_spec.rb +29 -11
  186. data/spec/unit/resource/rhsm_subscription_spec.rb +50 -3
  187. data/spec/unit/resource/systemd_unit_spec.rb +1 -1
  188. data/spec/unit/resource/windows_defender_exclusion_spec.rb +62 -0
  189. data/spec/unit/resource/windows_defender_spec.rb +71 -0
  190. data/spec/unit/resource/windows_firewall_rule_spec.rb +12 -7
  191. data/spec/unit/resource/windows_pagefile_spec.rb +4 -9
  192. data/spec/unit/resource/windows_update_settings_spec.rb +64 -0
  193. data/spec/unit/resource/zypper_repository_spec.rb +1 -1
  194. data/spec/unit/resource_spec.rb +19 -8
  195. data/spec/unit/secret_fetcher/aws_secrets_manager_spec.rb +70 -0
  196. data/spec/unit/secret_fetcher/azure_key_vault_spec.rb +70 -0
  197. data/spec/unit/secret_fetcher_spec.rb +82 -0
  198. metadata +55 -7
@@ -64,7 +64,7 @@ class Chef
64
64
  end
65
65
  end
66
66
 
67
- action :add, description: "Add an item to the system path" do
67
+ action :add, description: "Add an item to the system path." do
68
68
  # The windows Env provider does not correctly expand variables in
69
69
  # the PATH environment variable. Ruby expects these to be expanded.
70
70
  #
@@ -76,7 +76,7 @@ class Chef
76
76
  end
77
77
  end
78
78
 
79
- action :remove, description: "Remove an item from the system path" do
79
+ action :remove, description: "Remove an item from the system path." do
80
80
  # The windows Env provider does not correctly expand variables in
81
81
  # the PATH environment variable. Ruby expects these to be expanded.
82
82
  #
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Doug Ireton (<doug@1strategy.com>)
3
3
  # Copyright:: 2012-2018, Nordstrom, Inc.
4
+ # Copyright:: Chef Software, Inc.
4
5
  #
5
6
  # Licensed under the Apache License, Version 2.0 (the "License");
6
7
  # you may not use this file except in compliance with the License.
@@ -21,6 +22,10 @@ require_relative "../resource"
21
22
 
22
23
  class Chef
23
24
  class Resource
25
+ # @todo
26
+ # 1. Allow updating the printer properties
27
+ # 2. Fail with a warning if the port can't be found and create_port is false
28
+ # 3. Fail with helpful messaging if the printer driver can't be installed
24
29
  class WindowsPrinter < Chef::Resource
25
30
  unified_mode true
26
31
 
@@ -28,7 +33,7 @@ class Chef
28
33
 
29
34
  provides(:windows_printer) { true }
30
35
 
31
- description "Use the **windows_printer** resource to setup Windows printers. Note that this doesn't currently install a printer driver. You must already have the driver installed on the system."
36
+ description "Use the **windows_printer** resource to setup Windows printers. This resource will automatically install the driver specified in the `driver_name` property and will automatically create a printer port using either the `ipv4_address` property or the `port_name property."
32
37
  introduced "14.0"
33
38
  examples <<~DOC
34
39
  **Create a printer**:
@@ -49,6 +54,23 @@ class Chef
49
54
  action :delete
50
55
  end
51
56
  ```
57
+
58
+ **Create a printer port and a printer that uses that port (new in 17.3)**
59
+
60
+ ```ruby
61
+ windows_printer_port '10.4.64.39' do
62
+ port_name 'My awesome printer port'
63
+ snmp_enabled true
64
+ port_protocol 2
65
+ end
66
+
67
+ windows_printer 'HP LaserJet 5th Floor' do
68
+ driver_name 'HP LaserJet 4100 Series PCL6'
69
+ port_name 'My awesome printer port'
70
+ ipv4_address '10.4.64.38'
71
+ create_port false
72
+ end
73
+ ```
52
74
  DOC
53
75
 
54
76
  property :device_id, String,
@@ -83,82 +105,79 @@ class Chef
83
105
  proc { |v| v.match(Resolv::IPv4::Regex) },
84
106
  }
85
107
 
86
- PRINTERS_REG_KEY = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\\'.freeze unless defined?(PRINTERS_REG_KEY)
108
+ property :create_port, [TrueClass, FalseClass],
109
+ description: "Create a printer port for the printer. Set this to false and specify the `port_name` property if using the `windows_printer_port` resource to create the port instead.",
110
+ introduced: "17.3",
111
+ default: true, desired_state: false
87
112
 
88
- # @todo Set @current_resource printer properties from registry
89
- load_current_value do |new_resource|
90
- name new_resource.name
91
- end
113
+ property :port_name, String,
114
+ description: "The port name.",
115
+ default: lazy { |x| "IP_#{x.ipv4_address}" },
116
+ introduced: "17.3",
117
+ default_description: "The resource block name or the ipv4_address prepended with IP_."
92
118
 
93
- action :create, description: "Create a new printer and printer port, if one doesn't already" do
94
- description "Create a new printer and a printer port if one doesn't already exist."
119
+ load_current_value do |new_resource|
120
+ printer_data = powershell_exec(%Q{Get-WmiObject -Class Win32_Printer -Filter "Name='#{new_resource.device_id}'"}).result
95
121
 
96
- if printer_exists?
97
- Chef::Log.info "#{@new_resource} already exists - nothing to do."
122
+ if printer_data.empty?
123
+ current_value_does_not_exist!
98
124
  else
99
- converge_by("Create #{@new_resource}") do
100
- create_printer
125
+ device_id new_resource.device_id
126
+ comment printer_data["Comment"]
127
+ default printer_data["Default"]
128
+ location printer_data["Location"]
129
+ shared printer_data["Shared"]
130
+ share_name printer_data["ShareName"]
131
+ port_name printer_data["PortName"]
132
+
133
+ driver_data = powershell_exec(%Q{Get-PrinterDriver -Name="#{new_resource.driver_name}"}).result
134
+ unless driver_data.empty?
135
+ driver_name new_resource.driver_name
101
136
  end
102
137
  end
103
138
  end
104
139
 
105
- action :delete, description: "Delete an existing printer. Note that this resource does not delete the associated printer port." do
106
- description "Delete an existing printer. Note this does not delete the associated printer port."
107
-
108
- if printer_exists?
109
- converge_by("Delete #{@new_resource}") do
110
- delete_printer
111
- end
140
+ action :create, description: "Create a new printer and printer port, if one doesn't already." do
141
+ if current_resource
142
+ Chef::Log.info "#{@new_resource} already exists - nothing to do."
112
143
  else
113
- Chef::Log.info "#{@current_resource} doesn't exist - can't delete."
114
- end
115
- end
144
+ # Create the printer port first unless the property is set to false
145
+ if new_resource.create_port
146
+ windows_printer_port new_resource.port_name do
147
+ ipv4_address new_resource.ipv4_address
148
+ port_name new_resource.port_name
149
+ end
150
+ end
116
151
 
117
- action_class do
118
- private
119
-
120
- # does the printer exist
121
- #
122
- # @param [String] name the name of the printer
123
- # @return [Boolean]
124
- def printer_exists?
125
- printer_reg_key = PRINTERS_REG_KEY + new_resource.name
126
- logger.trace "Checking to see if this reg key exists: '#{printer_reg_key}'"
127
- registry_key_exists?(printer_reg_key)
128
- end
152
+ converge_by("install driver #{new_resource.driver_name}") do
153
+ powershell_exec!("Add-PrinterDriver -Name '#{new_resource.driver_name}'")
154
+ end
129
155
 
130
- # creates the printer port and then the printer
131
- def create_printer
132
- # Create the printer port first
133
- windows_printer_port new_resource.ipv4_address
134
-
135
- port_name = "IP_#{new_resource.ipv4_address}"
136
-
137
- declare_resource(:powershell_script, "Creating printer: #{new_resource.device_id}") do
138
- code <<-EOH
139
-
140
- Set-WmiInstance -class Win32_Printer `
141
- -EnableAllPrivileges `
142
- -Argument @{ DeviceID = "#{new_resource.device_id}";
143
- Comment = "#{new_resource.comment}";
144
- Default = "$#{new_resource.default}";
145
- DriverName = "#{new_resource.driver_name}";
146
- Location = "#{new_resource.location}";
147
- PortName = "#{port_name}";
148
- Shared = "$#{new_resource.shared}";
149
- ShareName = "#{new_resource.share_name}";
150
- }
156
+ converge_by("create #{@new_resource.device_id}") do
157
+ powershell_exec! <<-EOH
158
+ Set-WmiInstance -class Win32_Printer `
159
+ -EnableAllPrivileges `
160
+ -Argument @{ DeviceID = "#{new_resource.device_id}";
161
+ Comment = "#{new_resource.comment}";
162
+ Default = "$#{new_resource.default}";
163
+ DriverName = "#{new_resource.driver_name}";
164
+ Location = "#{new_resource.location}";
165
+ PortName = "#{new_resource.port_name}";
166
+ Shared = "$#{new_resource.shared}";
167
+ ShareName = "#{new_resource.share_name}";
168
+ }
151
169
  EOH
152
170
  end
153
171
  end
172
+ end
154
173
 
155
- def delete_printer
156
- declare_resource(:powershell_script, "Deleting printer: #{new_resource.device_id}") do
157
- code <<-EOH
158
- $printer = Get-WMIObject -class Win32_Printer -EnableAllPrivileges -Filter "name = '#{new_resource.device_id}'"
159
- $printer.Delete()
160
- EOH
174
+ action :delete, description: "Delete an existing printer. Note that this resource does not delete the associated printer port." do
175
+ if current_resource
176
+ converge_by("Delete #{new_resource.device_id}") do
177
+ powershell_exec!("Remove-Printer -Name '#{new_resource.device_id}'")
161
178
  end
179
+ else
180
+ Chef::Log.info "#{new_resource.device_id} doesn't exist - can't delete."
162
181
  end
163
182
  end
164
183
  end
@@ -1,6 +1,7 @@
1
1
  #
2
2
  # Author:: Doug Ireton <doug@1strategy.com>
3
3
  # Copyright:: 2012-2018, Nordstrom, Inc.
4
+ # Copyright:: Chef Software, Inc.
4
5
  #
5
6
  # Licensed under the Apache License, Version 2.0 (the "License");
6
7
  # you may not use this file except in compliance with the License.
@@ -68,14 +69,17 @@ class Chef
68
69
  }
69
70
 
70
71
  property :port_name, String,
71
- description: "The port name."
72
+ description: "The port name.",
73
+ default: lazy { |x| "IP_#{x.ipv4_address}" },
74
+ default_description: "The resource block name or the ipv4_address prepended with IP_."
72
75
 
73
76
  property :port_number, Integer,
74
- description: "The port number.",
77
+ description: "The TCP port number.",
75
78
  default: 9100
76
79
 
77
80
  property :port_description, String,
78
- description: "The description of the port."
81
+ desired_state: false,
82
+ deprecated: true
79
83
 
80
84
  property :snmp_enabled, [TrueClass, FalseClass],
81
85
  description: "Determines if SNMP is enabled on the port.",
@@ -86,79 +90,58 @@ class Chef
86
90
  validation_message: "port_protocol must be either 1 for RAW or 2 for LPR!",
87
91
  default: 1, equal_to: [1, 2]
88
92
 
89
- PORTS_REG_KEY = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\\'.freeze unless defined?(PORTS_REG_KEY)
90
-
91
- # @todo Set @current_resource port properties from registry
92
93
  load_current_value do |new_resource|
93
- name new_resource.name
94
- ipv4_address new_resource.ipv4_address
95
- port_name new_resource.port_name || "IP_#{new_resource.ipv4_address}"
96
- end
97
-
98
- action :create, description: "Create the printer port, if one doesn't already exist" do
99
- description "Create the new printer port if it does not already exist."
100
-
101
- if port_exists?
102
- Chef::Log.info "#{@new_resource} already exists - nothing to do."
103
- else
104
- converge_by("Create #{@new_resource}") do
105
- create_printer_port
106
- end
107
- end
108
- end
94
+ port_data = powershell_exec(%Q{Get-WmiObject -Class Win32_TCPIPPrinterPort -Filter "Name='#{new_resource.port_name}'"}).result
109
95
 
110
- action :delete, description: "Delete an existing printer port" do
111
- description "Delete an existing printer port."
112
-
113
- if port_exists?
114
- converge_by("Delete #{@new_resource}") do
115
- delete_printer_port
116
- end
96
+ if port_data.empty?
97
+ current_value_does_not_exist!
117
98
  else
118
- Chef::Log.info "#{@current_resource} doesn't exist - can't delete."
99
+ ipv4_address port_data["HostAddress"]
100
+ port_name port_data["Name"]
101
+ snmp_enabled port_data["SNMPEnabled"]
102
+ port_protocol port_data["Protocol"]
103
+ port_number port_data["PortNumber"]
119
104
  end
120
105
  end
121
106
 
122
- action_class do
123
- private
124
-
125
- def port_exists?
126
- name = new_resource.port_name || "IP_#{new_resource.ipv4_address}"
127
- port_reg_key = PORTS_REG_KEY + name
128
-
129
- logger.trace "Checking to see if this reg key exists: '#{port_reg_key}'"
130
- registry_key_exists?(port_reg_key)
131
- end
132
-
133
- def create_printer_port
134
- port_name = new_resource.port_name || "IP_#{new_resource.ipv4_address}"
135
-
136
- # create the printer port using PowerShell
137
- declare_resource(:powershell_script, "Creating printer port #{new_resource.port_name}") do
138
- code <<-EOH
139
-
140
- Set-WmiInstance -class Win32_TCPIPPrinterPort `
141
- -EnableAllPrivileges `
142
- -Argument @{ HostAddress = "#{new_resource.ipv4_address}";
143
- Name = "#{port_name}";
144
- Description = "#{new_resource.port_description}";
145
- PortNumber = "#{new_resource.port_number}";
146
- Protocol = "#{new_resource.port_protocol}";
147
- SNMPEnabled = "$#{new_resource.snmp_enabled}";
148
- }
107
+ action :create, description: "Create or update the printer port." do
108
+ converge_if_changed do
109
+ if current_resource
110
+ # update the printer port using PowerShell
111
+ powershell_exec! <<-EOH
112
+ Get-WmiObject Win32_TCPIPPrinterPort -EnableAllPrivileges -filter "Name='#{new_resource.port_name}'" |
113
+ ForEach-Object{
114
+ $_.HostAddress='#{new_resource.ipv4_address}'
115
+ $_.PortNumber='#{new_resource.port_number}'
116
+ $_.Protocol='#{new_resource.port_protocol}'
117
+ $_.SNMPEnabled='$#{new_resource.snmp_enabled}'
118
+ $_.Put()
119
+ }
120
+ EOH
121
+ else
122
+ # create the printer port using PowerShell
123
+ powershell_exec! <<-EOH
124
+ Set-WmiInstance -class Win32_TCPIPPrinterPort `
125
+ -EnableAllPrivileges `
126
+ -Argument @{ HostAddress = "#{new_resource.ipv4_address}";
127
+ Name = "#{new_resource.port_name}";
128
+ PortNumber = "#{new_resource.port_number}";
129
+ Protocol = "#{new_resource.port_protocol}";
130
+ SNMPEnabled = "$#{new_resource.snmp_enabled}";
131
+ }
149
132
  EOH
150
133
  end
151
- end
152
134
 
153
- def delete_printer_port
154
- port_name = new_resource.port_name || "IP_#{new_resource.ipv4_address}"
135
+ end
136
+ end
155
137
 
156
- declare_resource(:powershell_script, "Deleting printer port: #{new_resource.port_name}") do
157
- code <<-EOH
158
- $port = Get-WMIObject -class Win32_TCPIPPrinterPort -EnableAllPrivileges -Filter "name = '#{port_name}'"
159
- $port.Delete()
160
- EOH
138
+ action :delete, description: "Delete an existing printer port." do
139
+ if current_resource
140
+ converge_by("delete port #{new_resource.port_name}") do
141
+ powershell_exec!("Remove-PrinterPort -Name #{new_resource.port_name}")
161
142
  end
143
+ else
144
+ Chef::Log.info "#{new_resource.port_name} doesn't exist - can't delete."
162
145
  end
163
146
  end
164
147
  end
@@ -90,8 +90,8 @@ class Chef
90
90
  current_state = load_security_options
91
91
 
92
92
  if new_resource.secoption == "ResetLockoutCount"
93
- if new_resource.secvalue.to_i > 30
94
- raise Chef::Exceptions::ValidationFailed, "The \"ResetLockoutCount\" value cannot be greater than 30 minutes"
93
+ if new_resource.secvalue.to_i > current_state["LockoutDuration"].to_i
94
+ raise Chef::Exceptions::ValidationFailed, "The \"ResetLockoutCount\" value cannot be greater than the value currently set for \"LockoutDuration\""
95
95
  end
96
96
  end
97
97
  if (new_resource.secoption == "ResetLockoutCount" || new_resource.secoption == "LockoutDuration") && current_state["LockoutBadCount"] == "0"
@@ -192,7 +192,7 @@ class Chef
192
192
  name
193
193
  end
194
194
 
195
- action :create, description: "Create or modify a Windows share" do
195
+ action :create, description: "Create or modify a Windows share." do
196
196
  # we do this here instead of requiring the property because :delete doesn't need path set
197
197
  raise "No path property set" unless new_resource.path
198
198
 
@@ -216,7 +216,7 @@ class Chef
216
216
  end
217
217
  end
218
218
 
219
- action :delete, description: "Delete an existing Windows share" do
219
+ action :delete, description: "Delete an existing Windows share." do
220
220
  if current_resource.nil?
221
221
  Chef::Log.debug("#{new_resource.share_name} does not exist - nothing to do")
222
222
  else
@@ -69,7 +69,7 @@ class Chef
69
69
  iconlocation(link.IconLocation)
70
70
  end
71
71
 
72
- action :create, description: "Create or modify a Windows shortcut" do
72
+ action :create, description: "Create or modify a Windows shortcut." do
73
73
  converge_if_changed do
74
74
  converge_by "creating shortcut #{new_resource.shortcut_name}" do
75
75
  link = WIN32OLE.new("WScript.Shell").CreateShortcut(new_resource.shortcut_name)
@@ -49,7 +49,7 @@ class Chef
49
49
 
50
50
  **Create a scheduled task to run every 2 days**:
51
51
 
52
- ``` ruby
52
+ ```ruby
53
53
  windows_task 'chef-client' do
54
54
  command 'chef-client'
55
55
  run_level :highest
@@ -29,7 +29,7 @@ class Chef
29
29
  examples <<~DOC
30
30
  **Disable UAC prompts for the admin**:
31
31
 
32
- ``` ruby
32
+ ```ruby
33
33
  windows_uac 'Disable UAC prompts for the admin' do
34
34
  enable_uac true
35
35
  prompt_on_secure_desktop false
@@ -39,7 +39,7 @@ class Chef
39
39
 
40
40
  **Disable UAC entirely**:
41
41
 
42
- ``` ruby
42
+ ```ruby
43
43
  windows_uac 'Disable UAC entirely' do
44
44
  enable_uac false
45
45
  end
@@ -72,9 +72,7 @@ class Chef
72
72
  equal_to: %i{auto_deny secure_prompt_for_creds prompt_for_creds},
73
73
  default: :prompt_for_creds
74
74
 
75
- action :configure, description: "Configures UAC by setting registry keys at `HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System`" do
76
- description 'Configures UAC by setting registry keys at \'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\''
77
-
75
+ action :configure, description: "Configures UAC by setting registry keys at `HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System`." do
78
76
  registry_key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System' do
79
77
  values [{ name: "EnableLUA", type: :dword, data: bool_to_reg(new_resource.enable_uac) },
80
78
  { name: "ValidateAdminCodeSignatures", type: :dword, data: bool_to_reg(new_resource.require_signed_binaries) },
@@ -0,0 +1,259 @@
1
+ #
2
+ # Author:: Sölvi Páll Ásgeirsson (<solvip@gmail.com>)
3
+ # Author:: Richard Lavey (richard.lavey@calastone.com)
4
+ # Author:: Tim Smith (tsmith@chef.io)
5
+ #
6
+ # Copyright:: 2014-2017, Sölvi Páll Ásgeirsson.
7
+ # Copyright:: Copyright (c) Chef Software Inc.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ require_relative "../resource"
23
+ class Chef
24
+ class Resource
25
+ class WindowsUpdateSettings < Chef::Resource
26
+ unified_mode true
27
+
28
+ provides :windows_update_settings
29
+
30
+ description "Use the **windows_update_settings** resource to manage the various Windows Update patching options."
31
+ introduced "17.3"
32
+ examples <<~DOC
33
+ **Set Windows Update settings**:
34
+
35
+ ```ruby
36
+ windows_update_settings 'Settings to Configure Windows Nodes to automatically receive updates' do
37
+ disable_os_upgrades true
38
+ elevate_non_admins true
39
+ block_windows_update_website true
40
+ automatically_install_minor_updates true
41
+ scheduled_install_day 'Friday'
42
+ scheduled_install_hour 18
43
+ update_other_ms_products true
44
+ action :enable
45
+ end
46
+ ```
47
+ DOC
48
+
49
+ # required for the alias to pass validation
50
+ allowed_actions :set, :enable
51
+
52
+ DAYS = %W{Everyday Monday Tuesday Wednesday Thursday Friday Saturday Sunday}.freeze
53
+ UPDATE_OPTIONS = {
54
+ notify: 2,
55
+ download_and_notify: 3,
56
+ download_and_schedule: 4,
57
+ local_admin_decides: 5,
58
+ }.freeze
59
+
60
+ # HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate
61
+
62
+ property :disable_os_upgrades, [true, false], default: false, description: "Disable OS upgrades."
63
+ # options: 0 - let windows update update the os - false
64
+ # 1 - don't let windows update update the os - true
65
+
66
+ property :elevate_non_admins, [true, false], default: true, description: "Allow normal user accounts to temporarily be elevated to install patches."
67
+ # options: 0 - do not elevate a user to force an install - false
68
+ # 1 - do elevate the logged on user to install an update - true
69
+
70
+ property :add_to_target_wsus_group, [true, false], deprecated: "As of Chef Infra Client 17.3 the `add_to_target_wsus_group` property is no longer necessary."
71
+ # we set this registry value now automatically if the group name is set
72
+
73
+ property :target_wsus_group_name, String, description: "Add the node to a WSUS Target Group."
74
+ # options: --- a string representing the name of a target group you defined on your wsus server
75
+
76
+ property :wsus_server_url, String, description: "The URL of your WSUS server if you use one."
77
+ # options: --- a url for your internal update server in the form of https://my.updateserver.tld:4545 or whatever
78
+
79
+ property :wsus_status_server_url, String, deprecated: "As of Chef Infra Client 17.3 the `wsus_status_server_url` no longer needs to be set."
80
+ # this needs to be the same as wsus_server_url so we just set that value in both places now
81
+
82
+ # HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
83
+
84
+ property :block_windows_update_website, [true, false], default: false, description: "Block accessing the Windows Update website."
85
+ # options: 0 - allow access to the windows update website - false
86
+ # 1 - do not allow access to the windows update website - true
87
+
88
+ # HKLM\Software\Policies\Microsoft\Windows\WindowsUpdate\AU
89
+
90
+ property :automatic_update_option, [Integer, Symbol], equal_to: UPDATE_OPTIONS.keys, coerce: proc { |x| UPDATE_OPTIONS.key(x) || x },
91
+ default: :download_and_schedule,
92
+ description: "Control what to do when updates are found. This allows you to notify, automatically download and notify to install, automatically download and schedule the install, or let the local admin decide what action to take."
93
+ # options: 2 - notify before download
94
+ # 3 - auto download and notify
95
+ # 4 - auto download and schedule - must also set day and time (below)
96
+ # 5 - allow the local admin to decide
97
+
98
+ property :automatically_install_minor_updates, [true, false], default: false, description: "Automatically install minor updates."
99
+ # options: 0 - do not automatically install minor updates - false
100
+ # 1 - of course, silently install them! - true
101
+
102
+ property :enable_detection_frequency, [true, false], default: false, description: "Used to override the OS default of how often to check for updates"
103
+ # do i want my nodes checking for updates at a time interval i chose?
104
+ # options: 0 - do not enable the option for a custom interval - false
105
+ # 1 - yeah, buddy, i want to set my own interval for checking for updates - true
106
+
107
+ property :custom_detection_frequency, Integer, default: 22, description: "If you decided to override the OS default detection frequency, specify your choice here. Valid choices are 0 - 22",
108
+ callbacks: {
109
+ "should be a valid detection frequency (0-22)" => lambda { |p|
110
+ p >= 0 && p <= 22
111
+ },
112
+ }
113
+ # a time period of between 0 and 22 hours to check for new updates
114
+ # this is a hex value - convert it from dec to hex
115
+
116
+ property :no_reboot_with_users_logged_on, [true, false], default: true, description: "Prevents the OS from rebooting while someone is on the console."
117
+ # options: 0 - user is notified of pending reboot in xx minutes - false/off
118
+ # 1 - user is notified of pending reboot but can defer - true/on
119
+
120
+ property :disable_automatic_updates, [true, false], default: false, description: "Disable Windows Update."
121
+ # options: 0 - enable automatic updates to the local system - false
122
+ # 1 - disable automatic updates - true
123
+
124
+ property :scheduled_install_day, String, equal_to: DAYS, default: DAYS.first, description: "A day of the week to tell Windows when to install updates."
125
+ # options: Everyday - install every day
126
+ # Sunday - Saturday day of the week to install, 1 == sunday
127
+
128
+ property :scheduled_install_hour, Integer, description: "If you chose a scheduled day to install, then choose an hour on that day for you installation",
129
+ callbacks: {
130
+ "should be a valid hour in a 24 hour clock" => lambda { |p|
131
+ p > 0 && p < 25
132
+ },
133
+ }
134
+ # options: --- 2-digit number representing an hour of the day, uses a 24-hour clock, 12 == noon, 24 == midnight
135
+
136
+ property :update_other_ms_products, [true, false], default: true, description: "Allows for other Microsoft products to get updates too"
137
+ # options: 0 - do not allow wu to update other apps - remove key from hive - false/off
138
+ # 1 - please update all my stuff! - true/on
139
+
140
+ # \AU\AllowMUUpdateService dword: 1
141
+
142
+ property :custom_wsus_server, [true, false], deprecated: "As of Chef Infra Client 17.3 the `custom_wsus_server` no longer needs to be setup when specifying a WSUS endpoint."
143
+ # not necessary as we set this registry value automatically if a URL is set
144
+
145
+ action :set, description: "Set Windows Update settings." do
146
+ actual_day = convert_day(new_resource.scheduled_install_day)
147
+
148
+ registry_key 'HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate' do
149
+ recursive true
150
+ values [{
151
+ name: "DisableOSUpgrade",
152
+ type: :dword,
153
+ data: new_resource.disable_os_upgrades ? 1 : 0,
154
+ },
155
+ {
156
+ name: "ElevateNonAdmins",
157
+ type: :dword,
158
+ data: new_resource.elevate_non_admins ? 1 : 0,
159
+ },
160
+ {
161
+ name: "TargetGroupEnabled",
162
+ type: :dword,
163
+ data: new_resource.target_wsus_group_name ? 1 : 0,
164
+ },
165
+ {
166
+ name: "TargetGroup",
167
+ type: :string,
168
+ data: new_resource.target_wsus_group_name,
169
+ },
170
+ {
171
+ name: "WUServer",
172
+ type: :string,
173
+ data: new_resource.wsus_server_url,
174
+ },
175
+ {
176
+ name: "WUStatusServer",
177
+ type: :string,
178
+ data: new_resource.wsus_server_url, # status server and server need to be the same. Why? Ask Microsoft
179
+ }]
180
+ action :create
181
+ end
182
+
183
+ registry_key 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer' do
184
+ recursive true
185
+ values [{
186
+ name: "NoWindowsUpdate",
187
+ type: :dword,
188
+ data: new_resource.block_windows_update_website ? 1 : 0,
189
+ }]
190
+ action :create
191
+ end
192
+
193
+ registry_key 'HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU' do
194
+ recursive true
195
+ values [{
196
+ name: "AUOptions",
197
+ type: :dword,
198
+ data: UPDATE_OPTIONS[new_resource.automatic_update_option],
199
+ },
200
+ {
201
+ name: "AutoInstallMinorUpdates",
202
+ type: :dword,
203
+ data: new_resource.automatically_install_minor_updates ? 1 : 0,
204
+ },
205
+ {
206
+ name: "DetectionFrequencyEnabled",
207
+ type: :dword,
208
+ data: new_resource.enable_detection_frequency ? 1 : 0,
209
+ },
210
+ {
211
+ name: "DetectionFrequency",
212
+ type: :dword,
213
+ data: new_resource.custom_detection_frequency,
214
+ },
215
+ {
216
+ name: "NoAutoRebootWithLoggedOnUsers",
217
+ type: :dword,
218
+ data: new_resource.no_reboot_with_users_logged_on ? 1 : 0,
219
+ },
220
+ {
221
+ name: "NoAutoUpdate",
222
+ type: :dword,
223
+ data: new_resource.disable_automatic_updates ? 1 : 0,
224
+ },
225
+ {
226
+ name: "ScheduledInstallDay",
227
+ type: :dword,
228
+ data: actual_day,
229
+ },
230
+ {
231
+ name: "ScheduledInstallTime",
232
+ type: :dword,
233
+ data: new_resource.scheduled_install_hour,
234
+ },
235
+ {
236
+ name: "AllowMUUpdateService",
237
+ type: :dword,
238
+ data: new_resource.update_other_ms_products ? 1 : 0,
239
+ },
240
+ {
241
+ name: "UseWUServer",
242
+ type: :dword,
243
+ data: new_resource.wsus_server_url ? 1 : 0, # if we have a URL set then want to turn on WSUS functionality
244
+ }]
245
+ action :create
246
+ end
247
+ end
248
+
249
+ action_class do
250
+ def convert_day(day)
251
+ DAYS.index(day)
252
+ end
253
+
254
+ # support the old name as well
255
+ alias_method :action_enable, :action_set
256
+ end
257
+ end
258
+ end
259
+ end