chef 18.5.0 → 18.7.3

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 (241) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +11 -6
  3. data/chef-universal-mingw-ucrt.gemspec +1 -1
  4. data/chef.gemspec +19 -15
  5. data/lib/chef/application/client.rb +0 -12
  6. data/lib/chef/client.rb +1 -10
  7. data/lib/chef/compliance/default_attributes.rb +2 -2
  8. data/lib/chef/compliance/runner.rb +6 -11
  9. data/lib/chef/cookbook/metadata.rb +1 -1
  10. data/lib/chef/cookbook/remote_file_vendor.rb +1 -3
  11. data/lib/chef/cookbook/synchronizer.rb +0 -5
  12. data/lib/chef/event_dispatch/dispatcher.rb +0 -1
  13. data/lib/chef/exceptions.rb +1 -1
  14. data/lib/chef/file_access_control/unix.rb +9 -9
  15. data/lib/chef/file_content_management/deploy.rb +1 -4
  16. data/lib/chef/mixin/file_class.rb +1 -3
  17. data/lib/chef/mixin/get_source_from_package.rb +1 -1
  18. data/lib/chef/mixin/{homebrew_user.rb → homebrew.rb} +13 -16
  19. data/lib/chef/mixin/openssl_helper.rb +1 -12
  20. data/lib/chef/provider/cookbook_file.rb +1 -1
  21. data/lib/chef/provider/cron.rb +1 -1
  22. data/lib/chef/provider/directory.rb +15 -15
  23. data/lib/chef/provider/file.rb +29 -42
  24. data/lib/chef/provider/git.rb +8 -8
  25. data/lib/chef/provider/group/aix.rb +1 -1
  26. data/lib/chef/provider/group/dscl.rb +1 -1
  27. data/lib/chef/provider/group/gpasswd.rb +2 -2
  28. data/lib/chef/provider/group/groupadd.rb +1 -1
  29. data/lib/chef/provider/group/groupmod.rb +2 -2
  30. data/lib/chef/provider/group/pw.rb +2 -2
  31. data/lib/chef/provider/group/solaris.rb +2 -2
  32. data/lib/chef/provider/group/usermod.rb +2 -2
  33. data/lib/chef/provider/group.rb +1 -1
  34. data/lib/chef/provider/http_request.rb +3 -2
  35. data/lib/chef/provider/ifconfig/aix.rb +1 -1
  36. data/lib/chef/provider/ifconfig/debian.rb +3 -3
  37. data/lib/chef/provider/ifconfig/redhat.rb +1 -1
  38. data/lib/chef/provider/ifconfig.rb +1 -1
  39. data/lib/chef/provider/link.rb +10 -10
  40. data/lib/chef/provider/mount/aix.rb +4 -4
  41. data/lib/chef/provider/mount/linux.rb +4 -4
  42. data/lib/chef/provider/mount/mount.rb +11 -11
  43. data/lib/chef/provider/package/apt.rb +11 -2
  44. data/lib/chef/provider/package/bff.rb +3 -3
  45. data/lib/chef/provider/package/chocolatey.rb +2 -2
  46. data/lib/chef/provider/package/dnf/dnf_helper.py +7 -0
  47. data/lib/chef/provider/package/dpkg.rb +3 -3
  48. data/lib/chef/provider/package/freebsd/base.rb +1 -1
  49. data/lib/chef/provider/package/habitat.rb +3 -5
  50. data/lib/chef/provider/package/homebrew.rb +6 -9
  51. data/lib/chef/provider/package/ips.rb +2 -2
  52. data/lib/chef/provider/package/openbsd.rb +2 -3
  53. data/lib/chef/provider/package/pacman.rb +4 -4
  54. data/lib/chef/provider/package/paludis.rb +2 -2
  55. data/lib/chef/provider/package/portage.rb +1 -1
  56. data/lib/chef/provider/package/rpm.rb +2 -2
  57. data/lib/chef/provider/package/rubygems.rb +4 -0
  58. data/lib/chef/provider/package/smartos.rb +2 -2
  59. data/lib/chef/provider/package/snap.rb +2 -2
  60. data/lib/chef/provider/package/solaris.rb +4 -4
  61. data/lib/chef/provider/package/zypper.rb +4 -4
  62. data/lib/chef/provider/package.rb +1 -1
  63. data/lib/chef/provider/registry_key.rb +6 -0
  64. data/lib/chef/provider/remote_directory.rb +5 -5
  65. data/lib/chef/provider/remote_file/http.rb +3 -2
  66. data/lib/chef/provider/remote_file.rb +1 -1
  67. data/lib/chef/provider/route.rb +9 -9
  68. data/lib/chef/provider/service/aix.rb +1 -1
  69. data/lib/chef/provider/service/aixinit.rb +4 -4
  70. data/lib/chef/provider/service/arch.rb +6 -6
  71. data/lib/chef/provider/service/debian.rb +5 -5
  72. data/lib/chef/provider/service/freebsd.rb +7 -7
  73. data/lib/chef/provider/service/gentoo.rb +5 -5
  74. data/lib/chef/provider/service/init.rb +2 -2
  75. data/lib/chef/provider/service/insserv.rb +2 -2
  76. data/lib/chef/provider/service/invokercd.rb +1 -1
  77. data/lib/chef/provider/service/openbsd.rb +7 -7
  78. data/lib/chef/provider/service/redhat.rb +3 -3
  79. data/lib/chef/provider/service/solaris.rb +2 -2
  80. data/lib/chef/provider/service/systemd.rb +2 -2
  81. data/lib/chef/provider/service/upstart.rb +2 -2
  82. data/lib/chef/provider/subversion.rb +8 -8
  83. data/lib/chef/provider/systemd_unit.rb +3 -3
  84. data/lib/chef/provider/template.rb +1 -1
  85. data/lib/chef/provider/user/aix.rb +3 -3
  86. data/lib/chef/provider/user/linux.rb +2 -7
  87. data/lib/chef/provider/user/pw.rb +3 -3
  88. data/lib/chef/provider/user/solaris.rb +7 -7
  89. data/lib/chef/provider/user/windows.rb +5 -0
  90. data/lib/chef/provider/user.rb +8 -7
  91. data/lib/chef/provider/yum_repository.rb +3 -1
  92. data/lib/chef/provider/zypper_repository.rb +1 -1
  93. data/lib/chef/providers.rb +0 -1
  94. data/lib/chef/resource/alternatives.rb +2 -2
  95. data/lib/chef/resource/apt_preference.rb +1 -1
  96. data/lib/chef/resource/apt_repository.rb +90 -15
  97. data/lib/chef/resource/apt_update.rb +3 -3
  98. data/lib/chef/resource/bff_package.rb +1 -1
  99. data/lib/chef/resource/chef_client_config.rb +3 -2
  100. data/lib/chef/resource/chef_sleep.rb +1 -1
  101. data/lib/chef/resource/cookbook_file.rb +1 -1
  102. data/lib/chef/resource/cron/cron.rb +1 -1
  103. data/lib/chef/resource/cron/cron_d.rb +1 -1
  104. data/lib/chef/resource/cron_access.rb +1 -1
  105. data/lib/chef/resource/directory.rb +1 -1
  106. data/lib/chef/resource/dpkg_package.rb +1 -1
  107. data/lib/chef/resource/file/verification/json.rb +1 -1
  108. data/lib/chef/resource/file/verification/systemd_unit.rb +1 -1
  109. data/lib/chef/resource/file/verification/yaml.rb +1 -1
  110. data/lib/chef/resource/file.rb +1 -1
  111. data/lib/chef/resource/freebsd_package.rb +2 -2
  112. data/lib/chef/resource/group.rb +1 -1
  113. data/lib/chef/resource/habitat/habitat_package.rb +1 -1
  114. data/lib/chef/resource/habitat/habitat_sup.rb +9 -9
  115. data/lib/chef/resource/habitat/habitat_sup_systemd.rb +2 -2
  116. data/lib/chef/resource/habitat_install.rb +3 -3
  117. data/lib/chef/resource/homebrew_cask.rb +19 -30
  118. data/lib/chef/resource/homebrew_tap.rb +32 -17
  119. data/lib/chef/resource/homebrew_update.rb +4 -4
  120. data/lib/chef/resource/hostname.rb +10 -11
  121. data/lib/chef/resource/http_request.rb +1 -1
  122. data/lib/chef/resource/ifconfig.rb +1 -1
  123. data/lib/chef/resource/inspec_input.rb +1 -3
  124. data/lib/chef/resource/inspec_waiver.rb +1 -1
  125. data/lib/chef/resource/inspec_waiver_file_entry.rb +1 -1
  126. data/lib/chef/resource/ips_package.rb +2 -2
  127. data/lib/chef/resource/kernel_module.rb +2 -2
  128. data/lib/chef/resource/link.rb +1 -1
  129. data/lib/chef/resource/locale.rb +2 -2
  130. data/lib/chef/resource/mount.rb +1 -1
  131. data/lib/chef/resource/notify_group.rb +1 -1
  132. data/lib/chef/resource/ohai.rb +1 -1
  133. data/lib/chef/resource/ohai_hint.rb +1 -1
  134. data/lib/chef/resource/openbsd_package.rb +2 -2
  135. data/lib/chef/resource/package.rb +1 -1
  136. data/lib/chef/resource/pacman_package.rb +1 -1
  137. data/lib/chef/resource/paludis_package.rb +1 -1
  138. data/lib/chef/resource/portage_package.rb +1 -1
  139. data/lib/chef/resource/reboot.rb +1 -1
  140. data/lib/chef/resource/registry_key.rb +18 -0
  141. data/lib/chef/resource/remote_directory.rb +1 -1
  142. data/lib/chef/resource/remote_file.rb +1 -1
  143. data/lib/chef/resource/rhsm_errata.rb +1 -1
  144. data/lib/chef/resource/rhsm_errata_level.rb +1 -1
  145. data/lib/chef/resource/rhsm_register.rb +1 -1
  146. data/lib/chef/resource/rhsm_repo.rb +4 -3
  147. data/lib/chef/resource/rhsm_subscription.rb +9 -8
  148. data/lib/chef/resource/route.rb +1 -1
  149. data/lib/chef/resource/rpm_package.rb +1 -1
  150. data/lib/chef/resource/scm/git.rb +1 -1
  151. data/lib/chef/resource/scm/subversion.rb +1 -1
  152. data/lib/chef/resource/selinux/common_helpers.rb +1 -1
  153. data/lib/chef/resource/selinux_boolean.rb +1 -1
  154. data/lib/chef/resource/selinux_fcontext.rb +3 -3
  155. data/lib/chef/resource/selinux_install.rb +1 -1
  156. data/lib/chef/resource/selinux_login.rb +1 -1
  157. data/lib/chef/resource/selinux_module.rb +5 -5
  158. data/lib/chef/resource/selinux_permissive.rb +2 -2
  159. data/lib/chef/resource/selinux_port.rb +2 -2
  160. data/lib/chef/resource/selinux_state.rb +2 -2
  161. data/lib/chef/resource/selinux_user.rb +1 -1
  162. data/lib/chef/resource/smartos_package.rb +2 -2
  163. data/lib/chef/resource/snap_package.rb +1 -1
  164. data/lib/chef/resource/solaris_package.rb +1 -1
  165. data/lib/chef/resource/ssh_known_hosts_entry.rb +1 -1
  166. data/lib/chef/resource/sudo.rb +5 -5
  167. data/lib/chef/resource/support/client.erb +3 -2
  168. data/lib/chef/resource/swap_file.rb +6 -6
  169. data/lib/chef/resource/sysctl.rb +5 -5
  170. data/lib/chef/resource/systemd_unit.rb +1 -1
  171. data/lib/chef/resource/template.rb +1 -1
  172. data/lib/chef/resource/timezone.rb +5 -5
  173. data/lib/chef/resource/user/aix_user.rb +2 -2
  174. data/lib/chef/resource/user/linux_user.rb +2 -2
  175. data/lib/chef/resource/user/pw_user.rb +2 -2
  176. data/lib/chef/resource/user/solaris_user.rb +2 -2
  177. data/lib/chef/resource/user_ulimit.rb +1 -1
  178. data/lib/chef/resource/yum_repository.rb +1 -1
  179. data/lib/chef/resource/zypper_package.rb +2 -2
  180. data/lib/chef/resource/zypper_repository.rb +2 -2
  181. data/lib/chef/resource.rb +1 -0
  182. data/lib/chef/resource_inspector.rb +25 -7
  183. data/lib/chef/resource_reporter.rb +1 -0
  184. data/lib/chef/run_lock.rb +0 -3
  185. data/lib/chef/scan_access_control.rb +6 -6
  186. data/lib/chef/util/backup.rb +1 -1
  187. data/lib/chef/util/diff.rb +1 -14
  188. data/lib/chef/util/file_edit.rb +4 -4
  189. data/lib/chef/util/powershell/ps_credential.rb +10 -0
  190. data/lib/chef/version.rb +1 -1
  191. data/lib/chef/win32/registry.rb +5 -1
  192. data/lib/chef/win32/security.rb +9 -0
  193. data/lib/chef.rb +0 -2
  194. data/spec/functional/assets/yumrepo-empty/repodata/repomd.xml +6 -6
  195. data/spec/functional/resource/cookbook_file_spec.rb +1 -1
  196. data/spec/functional/resource/registry_spec.rb +276 -609
  197. data/spec/integration/client/open_ssl_spec.rb +1 -1
  198. data/spec/spec_helper.rb +1 -0
  199. data/spec/support/chef_helpers.rb +2 -2
  200. data/spec/support/platform_helpers.rb +8 -0
  201. data/spec/support/shared/functional/file_resource.rb +3 -3
  202. data/spec/tiny_server.rb +5 -2
  203. data/spec/unit/mixin/homebrew_spec.rb +118 -0
  204. data/spec/unit/provider/apt_repository_spec.rb +14 -9
  205. data/spec/unit/provider/package/chocolatey_spec.rb +1 -1
  206. data/spec/unit/provider/package/homebrew_spec.rb +4 -1
  207. data/spec/unit/provider/registry_key_spec.rb +18 -17
  208. data/spec/unit/provider/route_spec.rb +4 -6
  209. data/spec/unit/provider/user/windows_spec.rb +1 -0
  210. data/spec/unit/resource/rhsm_repo_spec.rb +0 -1
  211. data/spec/unit/resource/rhsm_subscription_spec.rb +0 -2
  212. data/spec/unit/resource_inspector_spec.rb +36 -0
  213. data/spec/unit/util/powershell/ps_credential_spec.rb +6 -0
  214. metadata +36 -44
  215. data/lib/chef/file_content_management/deploy/target_io.rb +0 -29
  216. data/lib/chef/provider/.gitkeep +0 -0
  217. data/lib/chef/provider/package/snap_tm.rb +0 -79
  218. data/lib/chef/resource/.gitkeep +0 -0
  219. data/lib/chef/target_io/dir.rb +0 -12
  220. data/lib/chef/target_io/etc.rb +0 -16
  221. data/lib/chef/target_io/file.rb +0 -12
  222. data/lib/chef/target_io/fileutils.rb +0 -12
  223. data/lib/chef/target_io/http.rb +0 -22
  224. data/lib/chef/target_io/io.rb +0 -12
  225. data/lib/chef/target_io/shadow.rb +0 -44
  226. data/lib/chef/target_io/train/dir.rb +0 -69
  227. data/lib/chef/target_io/train/etc.rb +0 -112
  228. data/lib/chef/target_io/train/file.rb +0 -219
  229. data/lib/chef/target_io/train/fileutils.rb +0 -220
  230. data/lib/chef/target_io/train/http.rb +0 -117
  231. data/lib/chef/target_io/train/io.rb +0 -13
  232. data/lib/chef/target_io/train/shadow.rb +0 -52
  233. data/lib/chef/target_io/train_compat.rb +0 -7
  234. data/lib/chef/target_io.rb +0 -9
  235. data/spec/unit/mixin/homebrew_user_spec.rb +0 -119
  236. /data/spec/functional/assets/yumrepo-empty/repodata/{01a3b489a465bcac22a43492163df43451dc6ce47d27f66de289756b91635523-filelists.sqlite.bz2 → 01a3b-filelists.sqlite.bz2} +0 -0
  237. /data/spec/functional/assets/yumrepo-empty/repodata/{401dc19bda88c82c403423fb835844d64345f7e95f5b9835888189c03834cc93-filelists.xml.gz → 401dc-filelists.xml.gz} +0 -0
  238. /data/spec/functional/assets/yumrepo-empty/repodata/{5dc1e6e73c84803f059bb3065e684e56adfc289a7e398946574d79dac6643945-primary.sqlite.bz2 → 5dc1e-primary.sqlite.bz2} +0 -0
  239. /data/spec/functional/assets/yumrepo-empty/repodata/{6bf9672d0862e8ef8b8ff05a2fd0208a922b1f5978e6589d87944c88259cb670-other.xml.gz → 6bf96-other.xml.gz} +0 -0
  240. /data/spec/functional/assets/yumrepo-empty/repodata/{7c36572015e075add2b38b900837bcdbb8a504130ddff49b2351a7fc0affa3d4-other.sqlite.bz2 → 7c365-other.sqlite.bz2} +0 -0
  241. /data/spec/functional/assets/yumrepo-empty/repodata/{dabe2ce5481d23de1f4f52bdcfee0f9af98316c9e0de2ce8123adeefa0dd08b9-primary.xml.gz → dabe2-primary.xml.gz} +0 -0
@@ -1,219 +0,0 @@
1
- module TargetIO
2
- module TrainCompat
3
- class File
4
- class << self
5
- def foreach(name)
6
- raise "TargetIO does not implement block-less File.foreach yet" unless block_given?
7
-
8
- contents = readlines(name)
9
- contents.each { |line| yield(line) }
10
- end
11
-
12
- def binread(name, length = nil, offset = 0)
13
- content = read(file_name)
14
- length = content.size - offset if length.nil?
15
-
16
- content[offset, length]
17
- end
18
-
19
- def expand_path(file_name, dir_string = "")
20
- require "pathname" unless defined?(Pathname)
21
-
22
- # Will just collapse relative paths inside
23
- pn = Pathname.new File.join(dir_string, file_name)
24
- pn.cleanpath
25
- end
26
-
27
- def new(filename, mode = "r")
28
- # Would need to hook into io.close (Closure?)
29
- raise NotImplementedError, "TargetIO does not implement File.new yet"
30
- end
31
-
32
- def read(file_name)
33
- readlines(file_name)&.join("\n") || ""
34
- end
35
-
36
- def open(file_name, mode = "r")
37
- # Would need to hook into io.close (Closure?)
38
- raise "TargetIO does not implement block-less File.open with modes other than read yet" if mode != "r" && !block_given?
39
-
40
- content = read(file_name)
41
- new_content = content.dup
42
-
43
- io = StringIO.new(new_content)
44
-
45
- if mode.start_with? "w"
46
- io.truncate(0)
47
- elsif mode.start_with? "a"
48
- io.seek(0, IO::SEEK_END)
49
- end
50
-
51
- if block_given?
52
- yield(io)
53
-
54
- if (content != new_content) && !mode.start_with?("r")
55
- __transport_connection.file(file_name).content = new_content # Need Train 2.5+
56
- end
57
- end
58
-
59
- io
60
- end
61
-
62
- def readlines(file_name)
63
- content = __transport_connection.file(file_name).content
64
- raise Errno::ENOENT if content.nil? # Not found
65
-
66
- content.split("\n")
67
- end
68
-
69
- ### START Could be in Train::File::...
70
-
71
- def executable?(file_name)
72
- mode(file_name) & 0111 != 0
73
- end
74
-
75
- def readable?(file_name)
76
- cmd = format("test -r %s", file_name)
77
- __transport_connection.run_command(cmd).exit_status == 0
78
- end
79
-
80
- def writable?(file_name)
81
- cmd = format("test -w %s", file_name)
82
- __transport_connection.run_command(cmd).exit_status == 0
83
- end
84
-
85
- # def ftype(file_name)
86
- # case type(file_name)
87
- # when :block_device
88
- # "blockSpecial"
89
- # when :character_device
90
- # "characterSpecial"
91
- # when :symlink
92
- # "link"
93
- # else
94
- # type(file_name).to_s
95
- # end
96
- # end
97
-
98
- def realpath(file_name)
99
- cmd = "realpath #{file_name}" # coreutils, not MacOSX
100
- Chef::Log.debug cmd
101
-
102
- __transport_connection.run_command(cmd).stdout.chop
103
- end
104
-
105
- def readlink(file_name)
106
- raise Errno::EINVAL unless symlink?(file_name)
107
-
108
- cmd = "readlink #{file_name}"
109
- Chef::Log.debug cmd
110
-
111
- __transport_connection.run_command(cmd).stdout.chop
112
- end
113
-
114
- # def setgid?(file_name)
115
- # mode(file_name) & 04000 != 0
116
- # end
117
-
118
- # def setuid?(file_name)
119
- # mode(file_name) & 02000 != 0
120
- # end
121
-
122
- # def sticky?(file_name)
123
- # mode(file_name) & 01000 != 0
124
- # end
125
-
126
- # def size?(file_name)
127
- # exist?(file_name) && size(file_name) > 0
128
- # end
129
-
130
- # def world_readable?(file_name)
131
- # mode(file_name) & 0001 != 0
132
- # end
133
-
134
- # def world_writable?(file_name)
135
- # mode(file_name) & 0002 != 0
136
- # end
137
-
138
- # def zero?(file_name)
139
- # exists?(file_name) && size(file_name) == 0
140
- # end
141
-
142
- ### END: Could be in Train
143
-
144
- # passthrough or map calls to third parties
145
- def method_missing(m, *args, **kwargs, &block)
146
- nonio = %i{extname join dirname path split}
147
-
148
- # TODO: writable?
149
- passthru = %i{basename directory? exist? exists? file? path pipe? socket? symlink?}
150
- redirect_train = {
151
- blockdev?: :block_device?,
152
- chardev?: :character_device?,
153
- }
154
- redirect_utils = {
155
- chown: :chown,
156
- chmod: :chmod,
157
- symlink: :ln_s,
158
- delete: :rm,
159
- }
160
- filestat = %i{gid group mode owner selinux_label size uid}
161
-
162
- if %i{stat lstat}.include? m
163
- Chef::Log.debug "File::#{m} passed to Train.file.stat"
164
-
165
- follow_symlink = m == :stat
166
- tfile = __transport_connection.file(args[0], follow_symlink).stat
167
-
168
- require "ostruct" unless defined?(OpenStruct)
169
- OpenStruct.new(tfile)
170
-
171
- # Non-IO methods can be issued locally
172
- elsif nonio.include? m
173
- ::File.send(m, *args, **kwargs) # TODO: pass block
174
-
175
- elsif passthru.include? m
176
- Chef::Log.debug "File::#{m} passed to Train.file.#{m}"
177
-
178
- file_name, other_args = args[0], args[1..]
179
-
180
- file = __transport_connection.file(file_name)
181
- file.send(m, *other_args, **kwargs) # block?
182
-
183
- elsif m == :mtime
184
- # Solve a data type disparity between Train.file and File
185
- timestamp = __transport_connection.file(args[0]).mtime
186
- Time.at(timestamp)
187
-
188
- elsif filestat.include? m
189
- Chef::Log.debug "File::#{m} passed to Train.file.stat.#{m}"
190
-
191
- __transport_connection.file(args[0]).stat[m]
192
-
193
- elsif redirect_utils.key?(m)
194
- new_method = redirect_utils[m]
195
- Chef::Log.debug "File::#{m} redirected to TargetIO::FileUtils.#{new_method}"
196
-
197
- ::TargetIO::FileUtils.send(new_method, *args, **kwargs) # TODO: pass block
198
-
199
- elsif redirect_train.key?(m)
200
- new_method = redirect_train[m]
201
- Chef::Log.debug "File::#{m} redirected to Train.file.#{new_method}"
202
-
203
- file_name, other_args = args[0], args[1..]
204
-
205
- file = __transport_connection.file(file_name)
206
- file.send(redirect[m], *other_args, **kwargs) # TODO: pass block
207
-
208
- else
209
- raise "Unsupported File method #{m}"
210
- end
211
- end
212
-
213
- def __transport_connection
214
- Chef.run_context&.transport_connection
215
- end
216
- end
217
- end
218
- end
219
- end
@@ -1,220 +0,0 @@
1
- module TargetIO
2
- module TrainCompat
3
- class FileUtils
4
- class << self
5
- def chmod(mode, list, noop: nil, verbose: nil)
6
- cmd = sprintf("chmod %s %s", __mode_to_s(mode), Array(list).join(" "))
7
-
8
- Chef::Log.debug cmd if verbose
9
- return if noop
10
-
11
- __run_command(cmd)
12
- end
13
-
14
- def chmod_R(mode, list, noop: nil, verbose: nil, force: nil)
15
- cmd = sprintf("chmod -R%s %s %s", (force ? "f" : ""), mode_to_s(mode), Array(list).join(" "))
16
-
17
- Chef::Log.debug cmd if verbose
18
- return if noop
19
-
20
- __run_command(cmd)
21
- end
22
-
23
- def chown(user, group, list, noop: nil, verbose: nil)
24
- cmd = sprintf("chown %s %s", (group ? "#{user}:#{group}" : user || ":"), Array(list).join(" "))
25
-
26
- Chef::Log.debug cmd if verbose
27
- return if noop
28
-
29
- __run_command(cmd)
30
- end
31
-
32
- def chown_R(user, group, list, noop: nil, verbose: nil, force: nil)
33
- cmd = sprintf("chown -R%s %s %s", (force ? "f" : ""), (group ? "#{user}:#{group}" : user || ":"), Array(list).join(" "))
34
-
35
- Chef::Log.debug cmd if verbose
36
- return if noop
37
-
38
- __run_command(cmd)
39
- end
40
-
41
- # cmp
42
- # collect_method
43
- # commands
44
- # compare_file
45
- # compare_stream
46
-
47
- def cp(src, dest, preserve: nil, noop: nil, verbose: nil)
48
- cmd = "cp#{preserve ? " -p" : ""} #{[src, dest].flatten.join(" ")}"
49
-
50
- Chef::Log.debug cmd if verbose
51
- return if noop
52
-
53
- __run_command(cmd)
54
- end
55
- alias_method :copy, :cp
56
-
57
- def cp_lr(src, dest, noop: nil, verbose: nil, dereference_root: true, remove_destination: false)
58
- cmd = "cp -lr#{remove_destination ? " --remove-destination" : ""} #{[src, dest].flatten.join(" ")}"
59
-
60
- Chef::Log.debug cmd if verbose
61
- return if noop
62
-
63
- __run_command(cmd)
64
- end
65
-
66
- def cp_r(src, dest, preserve: nil, noop: nil, verbose: nil, dereference_root: true, remove_destination: nil)
67
- cmd = "cp -r#{preserve ? "p" : ""}#{remove_destination ? " --remove-destination" : ""} #{[src, dest].flatten.join(" ")}"
68
-
69
- Chef::Log.debug cmd if verbose
70
- return if noop
71
-
72
- __run_command(cmd)
73
- end
74
-
75
- # getwd (alias pwd)
76
- # have_option?
77
- # identical? (alias compare_file)
78
-
79
- def install(src, dest, mode: nil, owner: nil, group: nil, preserve: nil, noop: nil, verbose: nil)
80
- cmd = "install -c"
81
- cmd << " -p" if preserve
82
- cmd << " -m " << mode_to_s(mode) if mode
83
- cmd << " -o #{owner}" if owner
84
- cmd << " -g #{group}" if group
85
- cmd << " " << [src, dest].flatten.join(" ")
86
-
87
- Chef::Log.debug cmd if verbose
88
- return if noop
89
-
90
- __run_command(cmd)
91
- end
92
-
93
- def ln(src, dest, force: nil, noop: nil, verbose: nil)
94
- cmd = "ln#{force ? " -f" : ""} #{[src, dest].flatten.join(" ")}"
95
-
96
- Chef::Log.debug cmd if verbose
97
- return if noop
98
-
99
- __run_command(cmd)
100
- end
101
- alias_method :link, :ln
102
-
103
- def ln_s(src, dest, force: nil, noop: nil, verbose: nil)
104
- cmd = "ln -s#{force ? "f" : ""} #{[src, dest].flatten.join(" ")}"
105
-
106
- Chef::Log.debug cmd if verbose
107
- return if noop
108
-
109
- __run_command(cmd)
110
- end
111
- alias_method :symlink, :ln_s
112
-
113
- def ln_sf(src, dest, noop: nil, verbose: nil)
114
- ln_s(src, dest, force: true, noop: noop, verbose: verbose)
115
- end
116
-
117
- def mkdir(list, mode: nil, noop: nil, verbose: nil)
118
- cmd = "mkdir #{mode ? ("-m %03o " % mode) : ""}#{Array(list).join(" ")}"
119
-
120
- Chef::Log.debug cmd if verbose
121
- return if noop
122
-
123
- __run_command(cmd)
124
- end
125
-
126
- def mkdir_p(list, mode: nil, noop: nil, verbose: nil)
127
- cmd = "mkdir -p #{mode ? ("-m %03o " % mode) : ""}#{Array(list).join(" ")}"
128
-
129
- Chef::Log.debug cmd if verbose
130
- return if noop
131
-
132
- __run_command(cmd)
133
- end
134
- alias_method :makedirs, :mkdir_p
135
- alias_method :mkpath, :mkdir_p
136
-
137
- def mv(src, dest, force: nil, noop: nil, verbose: nil, secure: nil)
138
- cmd = "mv#{force ? " -f" : ""} #{[src, dest].flatten.join(" ")}"
139
-
140
- Chef::Log.debug cmd if verbose
141
- return if noop
142
-
143
- __run_command(cmd)
144
- end
145
-
146
- # options
147
- # options_of
148
- # pwd
149
- # remove
150
- # remove_entry_secure
151
- # remove_file
152
-
153
- def rm(list, force: nil, noop: nil, verbose: nil)
154
- cmd = "rm#{force ? " -f" : ""} #{Array(list).join(" ")}"
155
-
156
- Chef::Log.debug cmd if verbose
157
- return if noop
158
-
159
- __run_command(cmd)
160
- end
161
-
162
- def rm_f(list, force: nil, noop: nil, verbose: nil, secure: nil)
163
- rm(list, force: true, noop: noop, verbose: verbose)
164
- end
165
-
166
- def rm_r(list, force: nil, noop: nil, verbose: nil, secure: nil)
167
- cmd = "rm -r#{force ? "f" : ""} #{Array(list).join(" ")}"
168
-
169
- Chef::Log.debug cmd if verbose
170
- return if noop
171
-
172
- __run_command(cmd)
173
- end
174
-
175
- def rm_rf(list, noop: nil, verbose: nil, secure: nil)
176
- rm_r(list, force: true, noop: noop, verbose: verbose, secure: secure)
177
- end
178
- alias_method :remove_entry, :rm_rf
179
- alias_method :rmtree, :rm_rf
180
- alias_method :safe_unlink, :rm_rf
181
-
182
- def rmdir(list, parents: nil, noop: nil, verbose: nil)
183
- cmd = "rmdir #{parents ? "-p " : ""}#{Array(list).join(" ")}"
184
-
185
- Chef::Log.debug cmd if verbose
186
- return if noop
187
-
188
- __run_command(cmd)
189
- end
190
-
191
- def touch(list, noop: nil, verbose: nil, mtime: nil, nocreate: nil)
192
- return if noop
193
-
194
- __run_command "touch #{nocreate ? "-c " : ""}#{mtime ? mtime.strftime("-t %Y%m%d%H%M.%S ") : ""}#{Array(list).join(" ")}"
195
- end
196
-
197
- # uptodate?
198
-
199
- def method_missing(m, *_args, **_kwargs, &_block)
200
- raise "Unsupported #{self.class} method #{m}"
201
- end
202
-
203
- private
204
-
205
- # TODO: Symbolic modes
206
- def __mode_to_s(mode)
207
- mode.to_s(8)
208
- end
209
-
210
- def __run_command(cmd)
211
- __transport_connection.run_command(cmd)
212
- end
213
-
214
- def __transport_connection
215
- Chef.run_context&.transport_connection
216
- end
217
- end
218
- end
219
- end
220
- end
@@ -1,117 +0,0 @@
1
- # require_relative "../mixin/which"
2
-
3
- module TargetIO
4
- module TrainCompat
5
- class HTTP
6
- attr_reader :last_response
7
-
8
- def initialize(url, options = {})
9
- @url = url.is_a?(URI) ? url.to_s : url
10
- @options = options
11
- @last_response = ""
12
- end
13
-
14
- # Send an HTTP HEAD request to the path
15
- #
16
- # === Parameters
17
- # path:: path part of the request URL
18
- def head(path, headers = {})
19
- request(:HEAD, path, headers)
20
- end
21
-
22
- # Send an HTTP GET request to the path
23
- #
24
- # === Parameters
25
- # path:: The path to GET
26
- def get(path, headers = {})
27
- request(:GET, path, headers)
28
- end
29
-
30
- # Send an HTTP PUT request to the path
31
- #
32
- # === Parameters
33
- # path:: path part of the request URL
34
- def put(path, json, headers = {})
35
- request(:PUT, path, headers, json)
36
- end
37
-
38
- # Send an HTTP POST request to the path
39
- #
40
- # === Parameters
41
- # path:: path part of the request URL
42
- def post(path, json, headers = {})
43
- request(:POST, path, headers, json)
44
- end
45
-
46
- # Send an HTTP DELETE request to the path
47
- #
48
- # === Parameters
49
- # path:: path part of the request URL
50
- def delete(path, headers = {})
51
- request(:DELETE, path, headers)
52
- end
53
-
54
- # Used inside Chef::Provider::RemoteFile::HTTPS
55
- def streaming_request(path, headers = {}, tempfile = nil)
56
- content = get(path, headers)
57
- @last_response = content
58
-
59
- tempfile.write(content)
60
- tempfile.close
61
-
62
- tempfile
63
- end
64
-
65
- def request(method, path, headers = {}, data = false)
66
- cmd = nil
67
- path = path.is_a?(URI) ? path.to_s : path
68
- headers.merge!(@options[:headers] || {})
69
-
70
- SUPPORTED_COMMANDS.each do |command_name|
71
- executable = which(command_name).chop
72
- next if !executable || executable.empty?
73
-
74
- # There are different ways to call (constructor, argument, combination of both)
75
- full_url = if path.start_with?("http")
76
- path
77
- elsif path.empty? || @url.end_with?(path)
78
- @url
79
- else
80
- File.join(@url, path)
81
- end
82
-
83
- cmd = send(command_name.to_sym, executable, method.to_s.upcase, full_url, headers, data)
84
- break
85
- end
86
-
87
- raise "Target needs one of #{SUPPORTED_COMMANDS.join("/")} for HTTP requests to work" unless cmd
88
-
89
- connection = Chef.run_context&.transport_connection
90
- connection.run_command(cmd).stdout
91
- end
92
-
93
- SUPPORTED_COMMANDS = %w{curl wget}.freeze
94
-
95
- # Sending data is not yet supported
96
- def curl(cmd, method, url, headers, _data)
97
- cmd += headers.map { |name, value| " --header '#{name}: #{value}'" }.join
98
- cmd += " --request #{method} "
99
- cmd += url
100
- end
101
-
102
- # Sending data is not yet supported
103
- def wget(cmd, method, url, headers, _data)
104
- cmd += headers.map { |name, value| " --header '#{name}: #{value}'" }.join
105
- cmd += " --method #{method}"
106
- cmd += " --output-document=- "
107
- cmd += url
108
- end
109
-
110
- # extend Chef::Mixin::Which
111
- def which(cmd)
112
- connection = Chef.run_context&.transport_connection
113
- connection.run_command("which #{cmd}").stdout
114
- end
115
- end
116
- end
117
- end
@@ -1,13 +0,0 @@
1
- require_relative "file"
2
-
3
- module TargetIO
4
- module TrainCompat
5
- class IO
6
- class << self
7
- def read(path)
8
- TargetIO::File.read(path)
9
- end
10
- end
11
- end
12
- end
13
- end
@@ -1,52 +0,0 @@
1
- module TargetIO
2
- module TrainCompat
3
- module Shadow
4
- # @see https://www.rubydoc.info/gems/ruby-shadow/2.5.0
5
- class Passwd
6
- class << self
7
- def getspnam(name)
8
- content = ::TargetIO::File.read("/etc/shadow")
9
- entries = __parse_shadow(content)
10
- data = entries.detect { |entry| entry["name"] == name }
11
- return ::TargetIO::Shadow::Entry.new unless data
12
-
13
- ::TargetIO::Shadow::Entry.new(
14
- data["sp_namp"],
15
- data["sp_pwdp"],
16
- data["sp_lstchg"],
17
- data["sp_min"],
18
- data["sp_max"],
19
- data["sp_warn"],
20
- data["sp_inact"],
21
- data["sp_expire"],
22
- data["sp_loginclass"]
23
- )
24
- end
25
-
26
- def __parse_shadow(content)
27
- content.to_s.split("\n").map do |line|
28
- next if line[0] == "#"
29
-
30
- __parse_shadow_line(line)
31
- end.compact
32
- end
33
-
34
- def __parse_shadow_line(line)
35
- x = line.split(":")
36
- {
37
- # rubocop:disable Layout/AlignHash
38
- "sp_namp" => x.at(0),
39
- "sp_pwdp" => x.at(1),
40
- "sp_lstchg" => x.at(2),
41
- "sp_min" => x.at(3),
42
- "sp_max" => x.at(4),
43
- "sp_warn" => x.at(5),
44
- "sp_inact" => x.at(6),
45
- "sp_expire" => x.at(7),
46
- }
47
- end
48
- end
49
- end
50
- end
51
- end
52
- end
@@ -1,7 +0,0 @@
1
- require_relative "train/dir"
2
- require_relative "train/etc"
3
- require_relative "train/file"
4
- require_relative "train/fileutils"
5
- require_relative "train/http"
6
- require_relative "train/io"
7
- require_relative "train/shadow"
@@ -1,9 +0,0 @@
1
- require_relative "target_io/dir"
2
- require_relative "target_io/etc"
3
- require_relative "target_io/file"
4
- require_relative "target_io/fileutils"
5
- require_relative "target_io/http"
6
- require_relative "target_io/io"
7
- require_relative "target_io/shadow"
8
-
9
- require_relative "target_io/train_compat"