naked-chef 0.9.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (363) hide show
  1. data/LICENSE +201 -0
  2. data/README.rdoc +172 -0
  3. data/bin/chef-client +26 -0
  4. data/bin/chef-solo +25 -0
  5. data/bin/knife +26 -0
  6. data/bin/shef +34 -0
  7. data/distro/README +2 -0
  8. data/distro/arch/etc/conf.d/chef-client.conf +5 -0
  9. data/distro/arch/etc/conf.d/chef-server-webui.conf +10 -0
  10. data/distro/arch/etc/conf.d/chef-server.conf +10 -0
  11. data/distro/arch/etc/conf.d/chef-solr-indexer.conf +8 -0
  12. data/distro/arch/etc/conf.d/chef-solr.conf +8 -0
  13. data/distro/arch/etc/rc.d/chef-client +76 -0
  14. data/distro/arch/etc/rc.d/chef-server +82 -0
  15. data/distro/arch/etc/rc.d/chef-server-webui +82 -0
  16. data/distro/arch/etc/rc.d/chef-solr +82 -0
  17. data/distro/arch/etc/rc.d/chef-solr-indexer +82 -0
  18. data/distro/common/man/man1/chef-indexer.1 +42 -0
  19. data/distro/common/man/man1/chef-server-webui.1 +106 -0
  20. data/distro/common/man/man1/chef-server.1 +107 -0
  21. data/distro/common/man/man1/chef-solr-indexer.1 +55 -0
  22. data/distro/common/man/man1/chef-solr.1 +55 -0
  23. data/distro/common/man/man8/chef-client.8 +63 -0
  24. data/distro/common/man/man8/chef-solo.8 +57 -0
  25. data/distro/common/man/man8/chef-solr-rebuild.8 +37 -0
  26. data/distro/common/man/man8/knife.8 +1349 -0
  27. data/distro/common/man/man8/shef.8 +45 -0
  28. data/distro/common/markdown/README +3 -0
  29. data/distro/common/markdown/knife.mkd +865 -0
  30. data/distro/debian/etc/default/chef-client +4 -0
  31. data/distro/debian/etc/default/chef-server +9 -0
  32. data/distro/debian/etc/default/chef-server-webui +9 -0
  33. data/distro/debian/etc/default/chef-solr +8 -0
  34. data/distro/debian/etc/default/chef-solr-indexer +7 -0
  35. data/distro/debian/etc/init.d/chef-client +175 -0
  36. data/distro/debian/etc/init.d/chef-server +122 -0
  37. data/distro/debian/etc/init.d/chef-server-webui +123 -0
  38. data/distro/debian/etc/init.d/chef-solr +176 -0
  39. data/distro/debian/etc/init.d/chef-solr-indexer +176 -0
  40. data/distro/debian/etc/init/chef-client.conf +17 -0
  41. data/distro/debian/etc/init/chef-server-webui.conf +17 -0
  42. data/distro/debian/etc/init/chef-server.conf +17 -0
  43. data/distro/debian/etc/init/chef-solr-indexer.conf +17 -0
  44. data/distro/debian/etc/init/chef-solr.conf +17 -0
  45. data/distro/redhat/etc/init.d/chef-client +106 -0
  46. data/distro/redhat/etc/init.d/chef-server +112 -0
  47. data/distro/redhat/etc/init.d/chef-server-webui +112 -0
  48. data/distro/redhat/etc/init.d/chef-solr +104 -0
  49. data/distro/redhat/etc/init.d/chef-solr-indexer +104 -0
  50. data/distro/redhat/etc/logrotate.d/chef-client +8 -0
  51. data/distro/redhat/etc/logrotate.d/chef-server +8 -0
  52. data/distro/redhat/etc/logrotate.d/chef-server-webui +8 -0
  53. data/distro/redhat/etc/logrotate.d/chef-solr +8 -0
  54. data/distro/redhat/etc/logrotate.d/chef-solr-indexer +8 -0
  55. data/distro/redhat/etc/sysconfig/chef-client +15 -0
  56. data/distro/redhat/etc/sysconfig/chef-server +14 -0
  57. data/distro/redhat/etc/sysconfig/chef-server-webui +14 -0
  58. data/distro/redhat/etc/sysconfig/chef-solr +8 -0
  59. data/distro/redhat/etc/sysconfig/chef-solr-indexer +7 -0
  60. data/lib/chef.rb +40 -0
  61. data/lib/chef/api_client.rb +264 -0
  62. data/lib/chef/application.rb +127 -0
  63. data/lib/chef/application/agent.rb +18 -0
  64. data/lib/chef/application/client.rb +246 -0
  65. data/lib/chef/application/knife.rb +171 -0
  66. data/lib/chef/application/solo.rb +215 -0
  67. data/lib/chef/applications.rb +4 -0
  68. data/lib/chef/certificate.rb +194 -0
  69. data/lib/chef/checksum.rb +182 -0
  70. data/lib/chef/checksum_cache.rb +173 -0
  71. data/lib/chef/client.rb +304 -0
  72. data/lib/chef/config.rb +240 -0
  73. data/lib/chef/cookbook/cookbook_collection.rb +44 -0
  74. data/lib/chef/cookbook/file_system_file_vendor.rb +54 -0
  75. data/lib/chef/cookbook/file_vendor.rb +48 -0
  76. data/lib/chef/cookbook/metadata.rb +500 -0
  77. data/lib/chef/cookbook/metadata/version.rb +87 -0
  78. data/lib/chef/cookbook/remote_file_vendor.rb +87 -0
  79. data/lib/chef/cookbook/syntax_check.rb +136 -0
  80. data/lib/chef/cookbook_loader.rb +227 -0
  81. data/lib/chef/cookbook_site_streaming_uploader.rb +244 -0
  82. data/lib/chef/cookbook_uploader.rb +103 -0
  83. data/lib/chef/cookbook_version.rb +934 -0
  84. data/lib/chef/couchdb.rb +239 -0
  85. data/lib/chef/daemon.rb +172 -0
  86. data/lib/chef/data_bag.rb +223 -0
  87. data/lib/chef/data_bag_item.rb +267 -0
  88. data/lib/chef/exceptions.rb +72 -0
  89. data/lib/chef/file_access_control.rb +140 -0
  90. data/lib/chef/file_cache.rb +218 -0
  91. data/lib/chef/handler.rb +206 -0
  92. data/lib/chef/handler/json_file.rb +58 -0
  93. data/lib/chef/index_queue.rb +29 -0
  94. data/lib/chef/index_queue/amqp_client.rb +113 -0
  95. data/lib/chef/index_queue/consumer.rb +76 -0
  96. data/lib/chef/index_queue/indexable.rb +75 -0
  97. data/lib/chef/json_compat.rb +52 -0
  98. data/lib/chef/knife.rb +522 -0
  99. data/lib/chef/knife/bluebox_images_list.rb +54 -0
  100. data/lib/chef/knife/bluebox_server_create.rb +157 -0
  101. data/lib/chef/knife/bluebox_server_delete.rb +63 -0
  102. data/lib/chef/knife/bluebox_server_list.rb +59 -0
  103. data/lib/chef/knife/bootstrap.rb +177 -0
  104. data/lib/chef/knife/bootstrap/archlinux-gems.erb +44 -0
  105. data/lib/chef/knife/bootstrap/centos5-gems.erb +41 -0
  106. data/lib/chef/knife/bootstrap/client-install.vbs +80 -0
  107. data/lib/chef/knife/bootstrap/fedora13-gems.erb +38 -0
  108. data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +32 -0
  109. data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +43 -0
  110. data/lib/chef/knife/bootstrap/windows-gems.erb +34 -0
  111. data/lib/chef/knife/client_bulk_delete.rb +40 -0
  112. data/lib/chef/knife/client_create.rb +70 -0
  113. data/lib/chef/knife/client_delete.rb +45 -0
  114. data/lib/chef/knife/client_edit.rb +45 -0
  115. data/lib/chef/knife/client_list.rb +40 -0
  116. data/lib/chef/knife/client_reregister.rb +56 -0
  117. data/lib/chef/knife/client_show.rb +50 -0
  118. data/lib/chef/knife/configure.rb +140 -0
  119. data/lib/chef/knife/configure_client.rb +52 -0
  120. data/lib/chef/knife/cookbook_bulk_delete.rb +58 -0
  121. data/lib/chef/knife/cookbook_create.rb +209 -0
  122. data/lib/chef/knife/cookbook_delete.rb +143 -0
  123. data/lib/chef/knife/cookbook_download.rb +130 -0
  124. data/lib/chef/knife/cookbook_list.rb +41 -0
  125. data/lib/chef/knife/cookbook_metadata.rb +82 -0
  126. data/lib/chef/knife/cookbook_metadata_from_file.rb +40 -0
  127. data/lib/chef/knife/cookbook_show.rb +90 -0
  128. data/lib/chef/knife/cookbook_site_download.rb +58 -0
  129. data/lib/chef/knife/cookbook_site_list.rb +56 -0
  130. data/lib/chef/knife/cookbook_site_search.rb +51 -0
  131. data/lib/chef/knife/cookbook_site_share.rb +109 -0
  132. data/lib/chef/knife/cookbook_site_show.rb +57 -0
  133. data/lib/chef/knife/cookbook_site_unshare.rb +53 -0
  134. data/lib/chef/knife/cookbook_site_vendor.rb +139 -0
  135. data/lib/chef/knife/cookbook_test.rb +82 -0
  136. data/lib/chef/knife/cookbook_upload.rb +95 -0
  137. data/lib/chef/knife/data_bag_create.rb +59 -0
  138. data/lib/chef/knife/data_bag_delete.rb +49 -0
  139. data/lib/chef/knife/data_bag_edit.rb +50 -0
  140. data/lib/chef/knife/data_bag_from_file.rb +45 -0
  141. data/lib/chef/knife/data_bag_list.rb +43 -0
  142. data/lib/chef/knife/data_bag_show.rb +41 -0
  143. data/lib/chef/knife/ec2_instance_data.rb +46 -0
  144. data/lib/chef/knife/ec2_server_create.rb +218 -0
  145. data/lib/chef/knife/ec2_server_delete.rb +87 -0
  146. data/lib/chef/knife/ec2_server_list.rb +89 -0
  147. data/lib/chef/knife/exec.rb +52 -0
  148. data/lib/chef/knife/index_rebuild.rb +51 -0
  149. data/lib/chef/knife/node_bulk_delete.rb +43 -0
  150. data/lib/chef/knife/node_create.rb +47 -0
  151. data/lib/chef/knife/node_delete.rb +44 -0
  152. data/lib/chef/knife/node_edit.rb +44 -0
  153. data/lib/chef/knife/node_from_file.rb +42 -0
  154. data/lib/chef/knife/node_list.rb +41 -0
  155. data/lib/chef/knife/node_run_list_add.rb +64 -0
  156. data/lib/chef/knife/node_run_list_remove.rb +45 -0
  157. data/lib/chef/knife/node_show.rb +54 -0
  158. data/lib/chef/knife/rackspace_server_create.rb +184 -0
  159. data/lib/chef/knife/rackspace_server_delete.rb +57 -0
  160. data/lib/chef/knife/rackspace_server_list.rb +59 -0
  161. data/lib/chef/knife/recipe_list.rb +32 -0
  162. data/lib/chef/knife/role_bulk_delete.rb +44 -0
  163. data/lib/chef/knife/role_create.rb +52 -0
  164. data/lib/chef/knife/role_delete.rb +44 -0
  165. data/lib/chef/knife/role_edit.rb +45 -0
  166. data/lib/chef/knife/role_from_file.rb +46 -0
  167. data/lib/chef/knife/role_list.rb +40 -0
  168. data/lib/chef/knife/role_show.rb +51 -0
  169. data/lib/chef/knife/search.rb +94 -0
  170. data/lib/chef/knife/slicehost_images_list.rb +53 -0
  171. data/lib/chef/knife/slicehost_server_create.rb +103 -0
  172. data/lib/chef/knife/slicehost_server_delete.rb +61 -0
  173. data/lib/chef/knife/slicehost_server_list.rb +64 -0
  174. data/lib/chef/knife/ssh.rb +338 -0
  175. data/lib/chef/knife/status.rb +87 -0
  176. data/lib/chef/knife/terremark_server_create.rb +152 -0
  177. data/lib/chef/knife/terremark_server_delete.rb +87 -0
  178. data/lib/chef/knife/terremark_server_list.rb +77 -0
  179. data/lib/chef/knife/windows_bootstrap.rb +154 -0
  180. data/lib/chef/log.rb +93 -0
  181. data/lib/chef/mixin/check_helper.rb +31 -0
  182. data/lib/chef/mixin/checksum.rb +32 -0
  183. data/lib/chef/mixin/command.rb +220 -0
  184. data/lib/chef/mixin/command/unix.rb +215 -0
  185. data/lib/chef/mixin/command/windows.rb +72 -0
  186. data/lib/chef/mixin/convert_to_class_name.rb +63 -0
  187. data/lib/chef/mixin/create_path.rb +56 -0
  188. data/lib/chef/mixin/deep_merge.rb +225 -0
  189. data/lib/chef/mixin/deprecation.rb +65 -0
  190. data/lib/chef/mixin/find_preferred_file.rb +92 -0
  191. data/lib/chef/mixin/from_file.rb +50 -0
  192. data/lib/chef/mixin/language.rb +165 -0
  193. data/lib/chef/mixin/language_include_attribute.rb +61 -0
  194. data/lib/chef/mixin/language_include_recipe.rb +52 -0
  195. data/lib/chef/mixin/params_validate.rb +225 -0
  196. data/lib/chef/mixin/recipe_definition_dsl_core.rb +81 -0
  197. data/lib/chef/mixin/shell_out.rb +38 -0
  198. data/lib/chef/mixin/template.rb +95 -0
  199. data/lib/chef/mixin/xml_escape.rb +140 -0
  200. data/lib/chef/mixins.rb +16 -0
  201. data/lib/chef/monkey_patches/dir.rb +36 -0
  202. data/lib/chef/monkey_patches/numeric.rb +7 -0
  203. data/lib/chef/monkey_patches/regexp.rb +34 -0
  204. data/lib/chef/monkey_patches/string.rb +28 -0
  205. data/lib/chef/monkey_patches/tempfile.rb +64 -0
  206. data/lib/chef/node.rb +599 -0
  207. data/lib/chef/node/attribute.rb +487 -0
  208. data/lib/chef/openid_registration.rb +187 -0
  209. data/lib/chef/platform.rb +382 -0
  210. data/lib/chef/provider.rb +124 -0
  211. data/lib/chef/provider/breakpoint.rb +36 -0
  212. data/lib/chef/provider/cookbook_file.rb +100 -0
  213. data/lib/chef/provider/cron.rb +186 -0
  214. data/lib/chef/provider/cron/solaris.rb +195 -0
  215. data/lib/chef/provider/deploy.rb +320 -0
  216. data/lib/chef/provider/deploy/revision.rb +77 -0
  217. data/lib/chef/provider/deploy/timestamped.rb +33 -0
  218. data/lib/chef/provider/directory.rb +72 -0
  219. data/lib/chef/provider/env.rb +152 -0
  220. data/lib/chef/provider/env/windows.rb +75 -0
  221. data/lib/chef/provider/erl_call.rb +100 -0
  222. data/lib/chef/provider/execute.rb +58 -0
  223. data/lib/chef/provider/file.rb +213 -0
  224. data/lib/chef/provider/git.rb +235 -0
  225. data/lib/chef/provider/group.rb +133 -0
  226. data/lib/chef/provider/group/dscl.rb +121 -0
  227. data/lib/chef/provider/group/gpasswd.rb +53 -0
  228. data/lib/chef/provider/group/groupadd.rb +78 -0
  229. data/lib/chef/provider/group/pw.rb +84 -0
  230. data/lib/chef/provider/group/usermod.rb +57 -0
  231. data/lib/chef/provider/group/windows.rb +79 -0
  232. data/lib/chef/provider/http_request.rb +122 -0
  233. data/lib/chef/provider/ifconfig.rb +132 -0
  234. data/lib/chef/provider/link.rb +161 -0
  235. data/lib/chef/provider/log.rb +54 -0
  236. data/lib/chef/provider/mdadm.rb +91 -0
  237. data/lib/chef/provider/mount.rb +117 -0
  238. data/lib/chef/provider/mount/mount.rb +232 -0
  239. data/lib/chef/provider/mount/windows.rb +80 -0
  240. data/lib/chef/provider/ohai.rb +41 -0
  241. data/lib/chef/provider/package.rb +160 -0
  242. data/lib/chef/provider/package/apt.rb +110 -0
  243. data/lib/chef/provider/package/dpkg.rb +112 -0
  244. data/lib/chef/provider/package/easy_install.rb +136 -0
  245. data/lib/chef/provider/package/freebsd.rb +123 -0
  246. data/lib/chef/provider/package/macports.rb +105 -0
  247. data/lib/chef/provider/package/pacman.rb +101 -0
  248. data/lib/chef/provider/package/portage.rb +124 -0
  249. data/lib/chef/provider/package/rpm.rb +101 -0
  250. data/lib/chef/provider/package/rubygems.rb +462 -0
  251. data/lib/chef/provider/package/solaris.rb +127 -0
  252. data/lib/chef/provider/package/yum-dump.py +128 -0
  253. data/lib/chef/provider/package/yum.rb +261 -0
  254. data/lib/chef/provider/package/zypper.rb +133 -0
  255. data/lib/chef/provider/remote_directory.rb +140 -0
  256. data/lib/chef/provider/remote_file.rb +120 -0
  257. data/lib/chef/provider/route.rb +195 -0
  258. data/lib/chef/provider/ruby_block.rb +33 -0
  259. data/lib/chef/provider/script.rb +55 -0
  260. data/lib/chef/provider/service.rb +128 -0
  261. data/lib/chef/provider/service/arch.rb +109 -0
  262. data/lib/chef/provider/service/debian.rb +130 -0
  263. data/lib/chef/provider/service/freebsd.rb +156 -0
  264. data/lib/chef/provider/service/gentoo.rb +54 -0
  265. data/lib/chef/provider/service/init.rb +71 -0
  266. data/lib/chef/provider/service/insserv.rb +52 -0
  267. data/lib/chef/provider/service/redhat.rb +60 -0
  268. data/lib/chef/provider/service/simple.rb +118 -0
  269. data/lib/chef/provider/service/solaris.rb +85 -0
  270. data/lib/chef/provider/service/upstart.rb +192 -0
  271. data/lib/chef/provider/service/windows.rb +146 -0
  272. data/lib/chef/provider/subversion.rb +194 -0
  273. data/lib/chef/provider/template.rb +105 -0
  274. data/lib/chef/provider/user.rb +187 -0
  275. data/lib/chef/provider/user/dscl.rb +280 -0
  276. data/lib/chef/provider/user/pw.rb +113 -0
  277. data/lib/chef/provider/user/useradd.rb +137 -0
  278. data/lib/chef/provider/user/windows.rb +124 -0
  279. data/lib/chef/providers.rb +92 -0
  280. data/lib/chef/recipe.rb +130 -0
  281. data/lib/chef/resource.rb +543 -0
  282. data/lib/chef/resource/apt_package.rb +34 -0
  283. data/lib/chef/resource/bash.rb +33 -0
  284. data/lib/chef/resource/breakpoint.rb +35 -0
  285. data/lib/chef/resource/cookbook_file.rb +45 -0
  286. data/lib/chef/resource/cron.rb +188 -0
  287. data/lib/chef/resource/csh.rb +33 -0
  288. data/lib/chef/resource/deploy.rb +371 -0
  289. data/lib/chef/resource/deploy_revision.rb +35 -0
  290. data/lib/chef/resource/directory.rb +76 -0
  291. data/lib/chef/resource/dpkg_package.rb +34 -0
  292. data/lib/chef/resource/easy_install_package.rb +57 -0
  293. data/lib/chef/resource/env.rb +58 -0
  294. data/lib/chef/resource/erl_call.rb +83 -0
  295. data/lib/chef/resource/execute.rb +127 -0
  296. data/lib/chef/resource/file.rb +99 -0
  297. data/lib/chef/resource/freebsd_package.rb +35 -0
  298. data/lib/chef/resource/gem_package.rb +49 -0
  299. data/lib/chef/resource/git.rb +36 -0
  300. data/lib/chef/resource/group.rb +70 -0
  301. data/lib/chef/resource/http_request.rb +61 -0
  302. data/lib/chef/resource/ifconfig.rb +134 -0
  303. data/lib/chef/resource/link.rb +78 -0
  304. data/lib/chef/resource/log.rb +62 -0
  305. data/lib/chef/resource/macports_package.rb +29 -0
  306. data/lib/chef/resource/mdadm.rb +82 -0
  307. data/lib/chef/resource/mount.rb +135 -0
  308. data/lib/chef/resource/ohai.rb +40 -0
  309. data/lib/chef/resource/package.rb +80 -0
  310. data/lib/chef/resource/pacman_package.rb +33 -0
  311. data/lib/chef/resource/perl.rb +33 -0
  312. data/lib/chef/resource/portage_package.rb +33 -0
  313. data/lib/chef/resource/python.rb +33 -0
  314. data/lib/chef/resource/remote_directory.rb +109 -0
  315. data/lib/chef/resource/remote_file.rb +83 -0
  316. data/lib/chef/resource/route.rb +135 -0
  317. data/lib/chef/resource/rpm_package.rb +34 -0
  318. data/lib/chef/resource/ruby.rb +33 -0
  319. data/lib/chef/resource/ruby_block.rb +40 -0
  320. data/lib/chef/resource/scm.rb +146 -0
  321. data/lib/chef/resource/script.rb +60 -0
  322. data/lib/chef/resource/service.rb +160 -0
  323. data/lib/chef/resource/solaris_package.rb +37 -0
  324. data/lib/chef/resource/subversion.rb +36 -0
  325. data/lib/chef/resource/template.rb +69 -0
  326. data/lib/chef/resource/timestamped_deploy.rb +31 -0
  327. data/lib/chef/resource/user.rb +130 -0
  328. data/lib/chef/resource/yum_package.rb +44 -0
  329. data/lib/chef/resource_collection.rb +217 -0
  330. data/lib/chef/resource_collection/stepable_iterator.rb +124 -0
  331. data/lib/chef/resource_definition.rb +67 -0
  332. data/lib/chef/resource_definition_list.rb +38 -0
  333. data/lib/chef/resources.rb +64 -0
  334. data/lib/chef/rest.rb +395 -0
  335. data/lib/chef/rest/auth_credentials.rb +78 -0
  336. data/lib/chef/rest/cookie_jar.rb +31 -0
  337. data/lib/chef/rest/rest_request.rb +188 -0
  338. data/lib/chef/role.rb +287 -0
  339. data/lib/chef/run_context.rb +110 -0
  340. data/lib/chef/run_list.rb +150 -0
  341. data/lib/chef/run_list/run_list_expansion.rb +172 -0
  342. data/lib/chef/run_list/run_list_item.rb +78 -0
  343. data/lib/chef/run_status.rb +121 -0
  344. data/lib/chef/runner.rb +107 -0
  345. data/lib/chef/sandbox.rb +153 -0
  346. data/lib/chef/search/query.rb +60 -0
  347. data/lib/chef/shef.rb +326 -0
  348. data/lib/chef/shef/ext.rb +569 -0
  349. data/lib/chef/shef/model_wrapper.rb +120 -0
  350. data/lib/chef/shef/shef_rest.rb +28 -0
  351. data/lib/chef/shef/shef_session.rb +279 -0
  352. data/lib/chef/shell_out.rb +418 -0
  353. data/lib/chef/streaming_cookbook_uploader.rb +201 -0
  354. data/lib/chef/tasks/chef_repo.rake +256 -0
  355. data/lib/chef/util/file_edit.rb +122 -0
  356. data/lib/chef/util/windows.rb +56 -0
  357. data/lib/chef/util/windows/net_group.rb +101 -0
  358. data/lib/chef/util/windows/net_use.rb +121 -0
  359. data/lib/chef/util/windows/net_user.rb +198 -0
  360. data/lib/chef/util/windows/volume.rb +59 -0
  361. data/lib/chef/version.rb +21 -0
  362. data/lib/chef/webui_user.rb +231 -0
  363. metadata +606 -0
@@ -0,0 +1,244 @@
1
+ #
2
+ # Author:: Stanislav Vitvitskiy
3
+ # Author:: Nuo Yan (nuo@opscode.com)
4
+ # Author:: Christopher Walters (<cw@opscode.com>)
5
+ # Copyright:: Copyright (c) 2009, 2010 Opscode, Inc.
6
+ # License:: Apache License, Version 2.0
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+
21
+ require 'net/http'
22
+ require 'mixlib/authentication/signedheaderauth'
23
+ require 'openssl'
24
+
25
+ class Chef
26
+ # == Chef::CookbookSiteStreamingUploader
27
+ # A streaming multipart HTTP upload implementation. Used to upload cookbooks
28
+ # (in tarball form) to http://cookbooks.opscode.com
29
+ #
30
+ # inspired by http://stanislavvitvitskiy.blogspot.com/2008/12/multipart-post-in-ruby.html
31
+ class CookbookSiteStreamingUploader
32
+
33
+ DefaultHeaders = { 'accept' => 'application/json', 'x-chef-version' => ::Chef::VERSION }
34
+
35
+ class << self
36
+
37
+ def create_build_dir(cookbook)
38
+ tmp_cookbook_path = Tempfile.new("chef-#{cookbook.name}-build")
39
+ tmp_cookbook_path.close
40
+ tmp_cookbook_dir = tmp_cookbook_path.path
41
+ File.unlink(tmp_cookbook_dir)
42
+ FileUtils.mkdir_p(tmp_cookbook_dir)
43
+ Chef::Log.debug("Staging at #{tmp_cookbook_dir}")
44
+ checksums_to_on_disk_paths = cookbook.checksums
45
+ Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |segment|
46
+ cookbook.manifest[segment].each do |manifest_record|
47
+ path_in_cookbook = manifest_record[:path]
48
+ on_disk_path = checksums_to_on_disk_paths[manifest_record[:checksum]]
49
+ dest = File.join(tmp_cookbook_dir, cookbook.name.to_s, path_in_cookbook)
50
+ FileUtils.mkdir_p(File.dirname(dest))
51
+ Chef::Log.debug("Staging #{on_disk_path} to #{dest}")
52
+ FileUtils.cp(on_disk_path, dest)
53
+ end
54
+ end
55
+
56
+ # First, generate metadata
57
+ Chef::Log.debug("Generating metadata")
58
+ kcm = Chef::Knife::CookbookMetadata.new
59
+ kcm.config[:cookbook_path] = [ tmp_cookbook_dir ]
60
+ kcm.name_args = [ cookbook.name.to_s ]
61
+ kcm.run
62
+
63
+ tmp_cookbook_dir
64
+ end
65
+
66
+ def post(to_url, user_id, secret_key_filename, params = {}, headers = {})
67
+ make_request(:post, to_url, user_id, secret_key_filename, params, headers)
68
+ end
69
+
70
+ def put(to_url, user_id, secret_key_filename, params = {}, headers = {})
71
+ make_request(:put, to_url, user_id, secret_key_filename, params, headers)
72
+ end
73
+
74
+ def make_request(http_verb, to_url, user_id, secret_key_filename, params = {}, headers = {})
75
+ boundary = '----RubyMultipartClient' + rand(1000000).to_s + 'ZZZZZ'
76
+ parts = []
77
+ content_file = nil
78
+
79
+ timestamp = Time.now.utc.iso8601
80
+ secret_key = OpenSSL::PKey::RSA.new(File.read(secret_key_filename))
81
+
82
+ unless params.nil? || params.empty?
83
+ params.each do |key, value|
84
+ if value.kind_of?(File)
85
+ content_file = value
86
+ filepath = value.path
87
+ filename = File.basename(filepath)
88
+ parts << StringPart.new( "--" + boundary + "\r\n" +
89
+ "Content-Disposition: form-data; name=\"" + key.to_s + "\"; filename=\"" + filename + "\"\r\n" +
90
+ "Content-Type: application/octet-stream\r\n\r\n")
91
+ parts << StreamPart.new(value, File.size(filepath))
92
+ parts << StringPart.new("\r\n")
93
+ else
94
+ parts << StringPart.new( "--" + boundary + "\r\n" +
95
+ "Content-Disposition: form-data; name=\"" + key.to_s + "\"\r\n\r\n")
96
+ parts << StringPart.new(value.to_s + "\r\n")
97
+ end
98
+ end
99
+ parts << StringPart.new("--" + boundary + "--\r\n")
100
+ end
101
+
102
+ body_stream = MultipartStream.new(parts)
103
+
104
+ timestamp = Time.now.utc.iso8601
105
+
106
+ url = URI.parse(to_url)
107
+
108
+ Chef::Log.logger.debug("Signing: method: #{http_verb}, path: #{url.path}, file: #{content_file}, User-id: #{user_id}, Timestamp: #{timestamp}")
109
+
110
+ # We use the body for signing the request if the file parameter
111
+ # wasn't a valid file or wasn't included. Extract the body (with
112
+ # multi-part delimiters intact) to sign the request.
113
+ # TODO: tim: 2009-12-28: It'd be nice to remove this special case, and
114
+ # always hash the entire request body. In the file case it would just be
115
+ # expanded multipart text - the entire body of the POST.
116
+ content_body = parts.inject("") { |result,part| result + part.read(0, part.size) }
117
+ content_file.rewind if content_file # we consumed the file for the above operation, so rewind it.
118
+
119
+ signing_options = {
120
+ :http_method=>http_verb,
121
+ :path=>url.path,
122
+ :user_id=>user_id,
123
+ :timestamp=>timestamp}
124
+ (content_file && signing_options[:file] = content_file) || (signing_options[:body] = (content_body || ""))
125
+
126
+ headers.merge!(Mixlib::Authentication::SignedHeaderAuth.signing_object(signing_options).sign(secret_key))
127
+
128
+ content_file.rewind if content_file
129
+
130
+ # net/http doesn't like symbols for header keys, so we'll to_s each one just in case
131
+ headers = DefaultHeaders.merge(Hash[*headers.map{ |k,v| [k.to_s, v] }.flatten])
132
+
133
+ req = case http_verb
134
+ when :put
135
+ Net::HTTP::Put.new(url.path, headers)
136
+ when :post
137
+ Net::HTTP::Post.new(url.path, headers)
138
+ end
139
+ req.content_length = body_stream.size
140
+ req.content_type = 'multipart/form-data; boundary=' + boundary unless parts.empty?
141
+ req.body_stream = body_stream
142
+
143
+ http = Net::HTTP.new(url.host, url.port)
144
+ if url.scheme == "https"
145
+ http.use_ssl = true
146
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
147
+ end
148
+ res = http.request(req)
149
+ #res = http.start {|http_proc| http_proc.request(req) }
150
+
151
+ # alias status to code and to_s to body for test purposes
152
+ # TODO: stop the following madness!
153
+ class << res
154
+ alias :to_s :body
155
+
156
+ # BUGBUG this makes the response compatible with what respsonse_steps expects to test headers (response.headers[] -> response[])
157
+ def headers
158
+ self
159
+ end
160
+
161
+ def status
162
+ code.to_i
163
+ end
164
+ end
165
+ res
166
+ end
167
+
168
+ end
169
+
170
+ class StreamPart
171
+ def initialize(stream, size)
172
+ @stream, @size = stream, size
173
+ end
174
+
175
+ def size
176
+ @size
177
+ end
178
+
179
+ # read the specified amount from the stream
180
+ def read(offset, how_much)
181
+ @stream.read(how_much)
182
+ end
183
+ end
184
+
185
+ class StringPart
186
+ def initialize(str)
187
+ @str = str
188
+ end
189
+
190
+ def size
191
+ @str.length
192
+ end
193
+
194
+ # read the specified amount from the string startiung at the offset
195
+ def read(offset, how_much)
196
+ @str[offset, how_much]
197
+ end
198
+ end
199
+
200
+ class MultipartStream
201
+ def initialize(parts)
202
+ @parts = parts
203
+ @part_no = 0
204
+ @part_offset = 0
205
+ end
206
+
207
+ def size
208
+ @parts.inject(0) {|size, part| size + part.size}
209
+ end
210
+
211
+ def read(how_much)
212
+ return nil if @part_no >= @parts.size
213
+
214
+ how_much_current_part = @parts[@part_no].size - @part_offset
215
+
216
+ how_much_current_part = if how_much_current_part > how_much
217
+ how_much
218
+ else
219
+ how_much_current_part
220
+ end
221
+
222
+ how_much_next_part = how_much - how_much_current_part
223
+
224
+ current_part = @parts[@part_no].read(@part_offset, how_much_current_part)
225
+
226
+ # recurse into the next part if the current one was not large enough
227
+ if how_much_next_part > 0
228
+ @part_no += 1
229
+ @part_offset = 0
230
+ next_part = read(how_much_next_part)
231
+ current_part + if next_part
232
+ next_part
233
+ else
234
+ ''
235
+ end
236
+ else
237
+ @part_offset += how_much_current_part
238
+ current_part
239
+ end
240
+ end
241
+ end
242
+
243
+ end
244
+ end
@@ -0,0 +1,103 @@
1
+ require 'rest_client'
2
+ require 'chef/cookbook_loader'
3
+ require 'chef/checksum_cache'
4
+ require 'chef/sandbox'
5
+ require 'chef/cookbook_version'
6
+ require 'chef/cookbook/syntax_check'
7
+ require 'chef/cookbook/file_system_file_vendor'
8
+
9
+ class Chef
10
+ class CookbookUploader
11
+ class << self
12
+
13
+ def upload_cookbook(cookbook)
14
+ Chef::Log.info("Saving #{cookbook.name}")
15
+
16
+ rest = Chef::REST.new(Chef::Config[:chef_server_url])
17
+
18
+ # Syntax Check
19
+ validate_cookbook(cookbook)
20
+ # Generate metadata.json from metadata.rb
21
+ build_metadata(cookbook)
22
+
23
+ # generate checksums of cookbook files and create a sandbox
24
+ checksum_files = cookbook.checksums
25
+ checksums = checksum_files.inject({}){|memo,elt| memo[elt.first]=nil ; memo}
26
+ new_sandbox = rest.post_rest("sandboxes", { :checksums => checksums })
27
+
28
+ Chef::Log.info("Uploading files")
29
+ # upload the new checksums and commit the sandbox
30
+ new_sandbox['checksums'].each do |checksum, info|
31
+ if info['needs_upload'] == true
32
+ Chef::Log.info("Uploading #{checksum_files[checksum]} (checksum hex = #{checksum}) to #{info['url']}")
33
+
34
+ # Checksum is the hexadecimal representation of the md5,
35
+ # but we need the base64 encoding for the content-md5
36
+ # header
37
+ checksum64 = Base64.encode64([checksum].pack("H*")).strip
38
+ timestamp = Time.now.utc.iso8601
39
+ file_contents = File.read(checksum_files[checksum])
40
+ # TODO - 5/28/2010, cw: make signing and sending the request streaming
41
+ sign_obj = Mixlib::Authentication::SignedHeaderAuth.signing_object(
42
+ :http_method => :put,
43
+ :path => URI.parse(info['url']).path,
44
+ :body => file_contents,
45
+ :timestamp => timestamp,
46
+ :user_id => rest.client_name
47
+ )
48
+ headers = { 'content-type' => 'application/x-binary', 'content-md5' => checksum64, :accept => 'application/json' }
49
+ headers.merge!(sign_obj.sign(OpenSSL::PKey::RSA.new(rest.signing_key)))
50
+ begin
51
+ RestClient::Resource.new(info['url'], :headers=>headers, :timeout=>1800, :open_timeout=>1800).put(file_contents)
52
+ rescue RestClient::Exception => e
53
+ Chef::Log.error("Upload failed: #{e.message}\n#{e.response.body}")
54
+ raise
55
+ end
56
+ else
57
+ Chef::Log.debug("#{checksum_files[checksum]} has not changed")
58
+ end
59
+ end
60
+ sandbox_url = new_sandbox['uri']
61
+ Chef::Log.debug("Committing sandbox")
62
+ # Retry if S3 is claims a checksum doesn't exist (the eventual
63
+ # in eventual consistency)
64
+ retries = 0
65
+ begin
66
+ rest.put_rest(sandbox_url, {:is_completed => true})
67
+ rescue Net::HTTPServerException => e
68
+ if e.message =~ /^400/ && (retries += 1) <= 5
69
+ sleep 2
70
+ retry
71
+ else
72
+ raise
73
+ end
74
+ end
75
+ # files are uploaded, so save the manifest
76
+ cookbook.save
77
+ Chef::Log.info("Upload complete!")
78
+ end
79
+
80
+ def build_metadata(cookbook)
81
+ Chef::Log.debug("Generating metadata")
82
+ # FIXME: This knife command should be factored out into a
83
+ # library for use here
84
+ kcm = Chef::Knife::CookbookMetadata.new
85
+ kcm.config[:cookbook_path] = Chef::Config[:cookbook_path]
86
+ kcm.name_args = [ cookbook.name.to_s ]
87
+ kcm.run
88
+ cookbook.reload_metadata!
89
+ end
90
+
91
+ def validate_cookbook(cookbook)
92
+ syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cookbook.name, @user_cookbook_path)
93
+ Chef::Log.info("Validating ruby files")
94
+ exit(1) unless syntax_checker.validate_ruby_files
95
+ Chef::Log.info("Validating templates")
96
+ exit(1) unless syntax_checker.validate_templates
97
+ Chef::Log.info("Syntax OK")
98
+ true
99
+ end
100
+
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,934 @@
1
+ #
2
+ # Author:: Adam Jacob (<adam@opscode.com>)
3
+ # Author:: Nuo Yan (<nuo@opscode.com>)
4
+ # Author:: Christopher Walters (<cw@opscode.com>)
5
+ # Author:: Tim Hinderliter (<tim@opscode.com>)
6
+ # Copyright:: Copyright (c) 2008-2010 Opscode, Inc.
7
+ # License:: Apache License, Version 2.0
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
+ require 'chef/log'
22
+ require 'chef/client'
23
+ require 'chef/node'
24
+ require 'chef/resource_definition_list'
25
+ require 'chef/recipe'
26
+ require 'chef/cookbook/file_vendor'
27
+ require 'chef/checksum'
28
+
29
+ class Chef
30
+ # == Chef::CookbookVersion
31
+ # CookbookVersion is a model object encapsulating the data about a Chef
32
+ # cookbook. Chef supports maintaining multiple versions of a cookbook on a
33
+ # single server; each version is represented by a distinct instance of this
34
+ # class.
35
+ #--
36
+ # TODO: timh/cw: 5-24-2010: mutators for files (e.g., recipe_filenames=,
37
+ # recipe_filenames.insert) should dirty the manifest so it gets regenerated.
38
+ class CookbookVersion
39
+ include Chef::IndexQueue::Indexable
40
+
41
+ COOKBOOK_SEGMENTS = [ :resources, :providers, :recipes, :definitions, :libraries, :attributes, :files, :templates, :root_files ]
42
+
43
+ DESIGN_DOCUMENT = {
44
+ "version" => 7,
45
+ "language" => "javascript",
46
+ "views" => {
47
+ "all" => {
48
+ "map" => <<-EOJS
49
+ function(doc) {
50
+ if (doc.chef_type == "cookbook_version") {
51
+ emit(doc.name, doc);
52
+ }
53
+ }
54
+ EOJS
55
+ },
56
+ "all_id" => {
57
+ "map" => <<-EOJS
58
+ function(doc) {
59
+ if (doc.chef_type == "cookbook_version") {
60
+ emit(doc.name, doc.name);
61
+ }
62
+ }
63
+ EOJS
64
+ },
65
+ "all_with_version" => {
66
+ "map" => <<-EOJS
67
+ function(doc) {
68
+ if (doc.chef_type == "cookbook_version") {
69
+ emit(doc.cookbook_name, doc.version);
70
+ }
71
+ }
72
+ EOJS
73
+ },
74
+ "all_latest_version" => {
75
+ "map" => %q@
76
+ function(doc) {
77
+ if (doc.chef_type == "cookbook_version") {
78
+ emit(doc.cookbook_name, doc.version);
79
+ }
80
+ }
81
+ @,
82
+ "reduce" => %q@
83
+ function(keys, values, rereduce) {
84
+ var result = null;
85
+
86
+ for (var idx in values) {
87
+ var value = values[idx];
88
+
89
+ if (idx == 0) {
90
+ result = value;
91
+ continue;
92
+ }
93
+
94
+ var valueParts = value.split('.').map(function(v) { return parseInt(v); });
95
+ var resultParts = result.split('.').map(function(v) { return parseInt(v); });
96
+
97
+ if (valueParts[0] != resultParts[0]) {
98
+ if (valueParts[0] > resultParts[0]) {
99
+ result = value;
100
+ }
101
+ }
102
+ else if (valueParts[1] != resultParts[1]) {
103
+ if (valueParts[1] > resultParts[1]) {
104
+ result = value;
105
+ }
106
+ }
107
+ else if (valueParts[2] != resultParts[2]) {
108
+ if (valueParts[2] > resultParts[2]) {
109
+ result = value;
110
+ }
111
+ }
112
+ }
113
+ return result;
114
+ }
115
+ @
116
+ },
117
+ "all_latest_version_by_id" => {
118
+ "map" => %q@
119
+ function(doc) {
120
+ if (doc.chef_type == "cookbook_version") {
121
+ emit(doc.cookbook_name, {version: doc.version, id:doc._id});
122
+ }
123
+ }
124
+ @,
125
+ "reduce" => %q@
126
+ function(keys, values, rereduce) {
127
+ var result = null;
128
+
129
+ for (var idx in values) {
130
+ var value = values[idx];
131
+
132
+ if (idx == 0) {
133
+ result = value;
134
+ continue;
135
+ }
136
+
137
+ var valueParts = value.version.split('.').map(function(v) { return parseInt(v); });
138
+ var resultParts = result.version.split('.').map(function(v) { return parseInt(v); });
139
+
140
+ if (valueParts[0] != resultParts[0]) {
141
+ if (valueParts[0] > resultParts[0]) {
142
+ result = value;
143
+ }
144
+ }
145
+ else if (valueParts[1] != resultParts[1]) {
146
+ if (valueParts[1] > resultParts[1]) {
147
+ result = value;
148
+ }
149
+ }
150
+ else if (valueParts[2] != resultParts[2]) {
151
+ if (valueParts[2] > resultParts[2]) {
152
+ result = value;
153
+ }
154
+ }
155
+ }
156
+ return result;
157
+ }
158
+ @
159
+ },
160
+ }
161
+ }
162
+
163
+ attr_accessor :root_dir
164
+ attr_accessor :definition_filenames
165
+ attr_accessor :template_filenames
166
+ attr_accessor :file_filenames
167
+ attr_accessor :library_filenames
168
+ attr_accessor :resource_filenames
169
+ attr_accessor :provider_filenames
170
+ attr_accessor :root_filenames
171
+ attr_accessor :name
172
+ attr_accessor :metadata
173
+ attr_accessor :metadata_filenames
174
+ attr_accessor :status
175
+ attr_accessor :couchdb_rev
176
+ attr_accessor :couchdb
177
+
178
+ attr_reader :couchdb_id
179
+
180
+ # attribute_filenames also has a setter that has non-default
181
+ # functionality.
182
+ attr_reader :attribute_filenames
183
+
184
+ # recipe_filenames also has a setter that has non-default
185
+ # functionality.
186
+ attr_reader :recipe_filenames
187
+
188
+ attr_reader :recipe_filenames_by_name
189
+ attr_reader :attribute_filenames_by_short_filename
190
+
191
+ # This is the one and only method that knows how cookbook files'
192
+ # checksums are generated.
193
+ def self.checksum_cookbook_file(filepath)
194
+ Chef::ChecksumCache.generate_md5_checksum_for_file(filepath)
195
+ rescue Errno::ENOENT
196
+ Chef::Log.debug("File #{filepath} does not exist, so there is no checksum to generate")
197
+ nil
198
+ end
199
+
200
+ # Keep track of the filenames that we use in both eager cookbook
201
+ # downloading (during sync_cookbooks) and lazy (during the run
202
+ # itself, through FileVendor). After the run is over, clean up the
203
+ # cache.
204
+ def self.valid_cache_entries
205
+ @valid_cache_entries ||= {}
206
+ end
207
+
208
+ def self.reset_cache_validity
209
+ @valid_cache_entries = nil
210
+ end
211
+
212
+ def self.cache
213
+ Chef::FileCache
214
+ end
215
+
216
+ # Setup a notification to clear the valid_cache_entries when a Chef client
217
+ # run starts
218
+ Chef::Client.when_run_starts do |run_status|
219
+ reset_cache_validity
220
+ end
221
+
222
+ # Synchronizes all the cookbooks from the chef-server.
223
+ #
224
+ # === Returns
225
+ # true:: Always returns true
226
+ def self.sync_cookbooks(cookbook_hash)
227
+ Chef::Log.debug("Cookbooks to load: #{cookbook_hash.inspect}")
228
+
229
+ clear_obsoleted_cookbooks(cookbook_hash)
230
+
231
+ # Synchronize each of the node's cookbooks, and add to the
232
+ # valid_cache_entries hash.
233
+ cookbook_hash.values.each do |cookbook|
234
+ sync_cookbook_file_cache(cookbook)
235
+ end
236
+
237
+ true
238
+ end
239
+
240
+ # Iterates over cached cookbooks' files, removing files belonging to
241
+ # cookbooks that don't appear in +cookbook_hash+
242
+ def self.clear_obsoleted_cookbooks(cookbook_hash)
243
+ # Remove all cookbooks no longer relevant to this node
244
+ cache.find(File.join(%w{cookbooks ** *})).each do |cache_file|
245
+ cache_file =~ /^cookbooks\/([^\/]+)\//
246
+ unless cookbook_hash.has_key?($1)
247
+ Chef::Log.info("Removing #{cache_file} from the cache; its cookbook is no longer needed on this client.")
248
+ cache.delete(cache_file)
249
+ end
250
+ end
251
+ end
252
+
253
+ # Update the file caches for a given cache segment. Takes a segment name
254
+ # and a hash that matches one of the cookbooks/_attribute_files style
255
+ # remote file listings.
256
+ #
257
+ # === Parameters
258
+ # cookbook<Chef::Cookbook>:: The cookbook to update
259
+ # valid_cache_entries<Hash>:: Out-param; Added to this hash are the files that
260
+ # were referred to by this cookbook
261
+ def self.sync_cookbook_file_cache(cookbook)
262
+ Chef::Log.debug("Synchronizing cookbook #{cookbook.name}")
263
+
264
+ # files and templates are lazily loaded, and will be done later.
265
+ eager_segments = COOKBOOK_SEGMENTS.dup
266
+ eager_segments.delete(:files)
267
+ eager_segments.delete(:templates)
268
+
269
+ eager_segments.each do |segment|
270
+ segment_filenames = Array.new
271
+ cookbook.manifest[segment].each do |manifest_record|
272
+ # segment = cookbook segment
273
+ # remote_list = list of file hashes
274
+ #
275
+ # We need the list of known good attribute files, so we can delete any that are
276
+ # just laying about.
277
+
278
+ cache_filename = File.join("cookbooks", cookbook.name, manifest_record['path'])
279
+ valid_cache_entries[cache_filename] = true
280
+
281
+ current_checksum = nil
282
+ if cache.has_key?(cache_filename)
283
+ current_checksum = checksum_cookbook_file(cache.load(cache_filename, false))
284
+ end
285
+
286
+ # If the checksums are different between on-disk (current) and on-server
287
+ # (remote, per manifest), do the update. This will also execute if there
288
+ # is no current checksum.
289
+ if current_checksum != manifest_record['checksum']
290
+ raw_file = chef_server_rest.get_rest(manifest_record[:url], true)
291
+
292
+ Chef::Log.info("Storing updated #{cache_filename} in the cache.")
293
+ cache.move_to(raw_file.path, cache_filename)
294
+ else
295
+ Chef::Log.debug("Not storing #{cache_filename}, as the cache is up to date.")
296
+ end
297
+
298
+ # make the segment filenames a full path.
299
+ full_path_cache_filename = cache.load(cache_filename, false)
300
+ segment_filenames << full_path_cache_filename
301
+ end
302
+
303
+ # replace segment filenames with a full-path one.
304
+ if segment.to_sym == :recipes
305
+ cookbook.recipe_filenames = segment_filenames
306
+ elsif segment.to_sym == :attributes
307
+ cookbook.attribute_filenames = segment_filenames
308
+ else
309
+ cookbook.segment_filenames(segment).replace(segment_filenames)
310
+ end
311
+ end
312
+ end
313
+
314
+ def self.cleanup_file_cache
315
+ unless Chef::Config[:solo]
316
+ # Delete each file in the cache that we didn't encounter in the
317
+ # manifest.
318
+ cache.find(File.join(%w{cookbooks ** *})).each do |cache_filename|
319
+ unless valid_cache_entries[cache_filename]
320
+ Chef::Log.info("Removing #{cache_filename} from the cache; it is no longer on the server.")
321
+ cache.delete(cache_filename)
322
+ end
323
+ end
324
+ end
325
+ end
326
+
327
+ # Register a notification to cleanup unused files from cookbooks
328
+ Chef::Client.when_run_completes_successfully do |run_status|
329
+ cleanup_file_cache
330
+ end
331
+
332
+ # Creates a new Chef::CookbookVersion object.
333
+ #
334
+ # === Returns
335
+ # object<Chef::CookbookVersion>:: Duh. :)
336
+ def initialize(name, couchdb=nil)
337
+ @name = name
338
+ @attribute_filenames = Array.new
339
+ @definition_filenames = Array.new
340
+ @template_filenames = Array.new
341
+ @file_filenames = Array.new
342
+ @recipe_filenames = Array.new
343
+ @recipe_filenames_by_name = Hash.new
344
+ @library_filenames = Array.new
345
+ @resource_filenames = Array.new
346
+ @provider_filenames = Array.new
347
+ @metadata_filenames = Array.new
348
+ @root_dir = nil
349
+ @root_filenames = Array.new
350
+ @couchdb_id = nil
351
+ @couchdb = couchdb || Chef::CouchDB.new
352
+ @couchdb_rev = nil
353
+ @status = :ready
354
+ @manifest = nil
355
+ @file_vendor = nil
356
+ @metadata = Chef::Cookbook::Metadata.new
357
+ end
358
+
359
+ def version
360
+ metadata.version
361
+ end
362
+
363
+ def version=(new_version)
364
+ manifest["version"] = new_version
365
+ metadata.version(new_version)
366
+ end
367
+
368
+ # A manifest is a Mash that maps segment names to arrays of manifest
369
+ # records (see #preferred_manifest_record for format of manifest records),
370
+ # as well as describing cookbook metadata. The manifest follows a form
371
+ # like the following:
372
+ #
373
+ # {
374
+ # :cookbook_name = "apache2",
375
+ # :version = "1.0",
376
+ # :name = "Apache 2"
377
+ # :metadata = ???TODO: timh/cw: 5-24-2010: describe this format,
378
+ #
379
+ # :files => [
380
+ # {
381
+ # :name => "afile.rb",
382
+ # :path => "files/ubuntu-9.10/afile.rb",
383
+ # :checksum => "2222",
384
+ # :specificity => "ubuntu-9.10"
385
+ # },
386
+ # ],
387
+ # :templates => [ manifest_record1, ... ],
388
+ # ...
389
+ # }
390
+ def manifest
391
+ unless @manifest
392
+ generate_manifest
393
+ end
394
+ @manifest
395
+ end
396
+
397
+ def manifest=(new_manifest)
398
+ @manifest = Mash.new new_manifest
399
+ @checksums = extract_checksums_from_manifest(@manifest)
400
+ @manifest_records_by_path = extract_manifest_records_by_path(@manifest)
401
+
402
+ COOKBOOK_SEGMENTS.each do |segment|
403
+ next unless @manifest.has_key?(segment)
404
+ filenames = @manifest[segment].map{|manifest_record| manifest_record['name']}
405
+
406
+ if segment == :recipes
407
+ self.recipe_filenames = filenames
408
+ elsif segment == :attributes
409
+ self.attribute_filenames = filenames
410
+ else
411
+ segment_filenames(segment).clear
412
+ filenames.each { |filename| segment_filenames(segment) << filename }
413
+ end
414
+ end
415
+ end
416
+
417
+ # Returns a hash of checksums to either nil or the on disk path (which is
418
+ # done by generate_manifest).
419
+ def checksums
420
+ unless @checksums
421
+ generate_manifest
422
+ end
423
+ @checksums
424
+ end
425
+
426
+ def full_name
427
+ "#{name}-#{version}"
428
+ end
429
+
430
+ def attribute_filenames=(*filenames)
431
+ @attribute_filenames = filenames.flatten
432
+ @attribute_filenames_by_short_filename = filenames_by_name(attribute_filenames)
433
+ attribute_filenames
434
+ end
435
+
436
+ ## BACKCOMPAT/DEPRECATED - Remove these and fix breakage before release [DAN - 5/20/2010]##
437
+ alias :attribute_files :attribute_filenames
438
+ alias :attribute_files= :attribute_filenames=
439
+
440
+ # Return recipe names in the form of cookbook_name::recipe_name
441
+ def fully_qualified_recipe_names
442
+ results = Array.new
443
+ recipe_filenames_by_name.each_key do |rname|
444
+ results << "#{name}::#{rname}"
445
+ end
446
+ results
447
+ end
448
+
449
+ def recipe_filenames=(*filenames)
450
+ @recipe_filenames = filenames.flatten
451
+ @recipe_filenames_by_name = filenames_by_name(recipe_filenames)
452
+ recipe_filenames
453
+ end
454
+
455
+ ## BACKCOMPAT/DEPRECATED - Remove these and fix breakage before release [DAN - 5/20/2010]##
456
+ alias :recipe_files :recipe_filenames
457
+ alias :recipe_files= :recipe_filenames=
458
+
459
+ # called from DSL
460
+ def load_recipe(recipe_name, run_context)
461
+ unless recipe_filenames_by_name.has_key?(recipe_name)
462
+ raise ArgumentError, "Cannot find a recipe matching #{recipe_name} in cookbook #{name}"
463
+ end
464
+
465
+ Chef::Log.debug("Found recipe #{recipe_name} in cookbook #{name}")
466
+ recipe = Chef::Recipe.new(name, recipe_name, run_context)
467
+ recipe_filename = recipe_filenames_by_name[recipe_name]
468
+
469
+ unless recipe_filename
470
+ raise Chef::Exceptions::RecipeNotFound, "could not find recipe #{recipe_name} for cookbook #{name}"
471
+ end
472
+
473
+ recipe.from_file(recipe_filename)
474
+ recipe
475
+ end
476
+
477
+ def segment_filenames(segment)
478
+ unless COOKBOOK_SEGMENTS.include?(segment)
479
+ raise ArgumentError, "invalid segment #{segment}: must be one of #{COOKBOOK_SEGMENTS.join(', ')}"
480
+ end
481
+
482
+ case segment.to_sym
483
+ when :resources
484
+ @resource_filenames
485
+ when :providers
486
+ @provider_filenames
487
+ when :recipes
488
+ @recipe_filenames
489
+ when :libraries
490
+ @library_filenames
491
+ when :definitions
492
+ @definition_filenames
493
+ when :attributes
494
+ @attribute_filenames
495
+ when :files
496
+ @file_filenames
497
+ when :templates
498
+ @template_filenames
499
+ when :root_files
500
+ @root_filenames
501
+ end
502
+ end
503
+
504
+ # Determine the most specific manifest record for the given
505
+ # segment/filename, given information in the node. Throws
506
+ # FileNotFound if there is no such segment and filename in the
507
+ # manifest.
508
+ #
509
+ # A manifest record is a Mash that follows the following form:
510
+ # {
511
+ # :name => "example.rb",
512
+ # :path => "files/default/example.rb",
513
+ # :specificity => "default",
514
+ # :checksum => "1234"
515
+ # }
516
+ def preferred_manifest_record(node, segment, filename)
517
+ preferences = preferences_for_path(node, segment, filename)
518
+
519
+ # ensure that we generate the manifest, which will also generate
520
+ # @manifest_records_by_path
521
+ manifest
522
+
523
+ # in order of prefernce, look for the filename in the manifest
524
+ found_pref = preferences.find {|preferred_filename| @manifest_records_by_path[preferred_filename] }
525
+ if found_pref
526
+ @manifest_records_by_path[found_pref]
527
+ else
528
+ raise Chef::Exceptions::FileNotFound, "cookbook #{name} does not contain file #{segment}/#{filename}"
529
+ end
530
+ end
531
+
532
+ def preferred_filename_on_disk_location(node, segment, filename, current_filepath=nil)
533
+ manifest_record = preferred_manifest_record(node, segment, filename)
534
+ if current_filepath && (manifest_record['checksum'] == self.class.checksum_cookbook_file(current_filepath))
535
+ nil
536
+ else
537
+ file_vendor.get_filename(manifest_record['path'])
538
+ end
539
+ end
540
+
541
+ def relative_filenames_in_preferred_directory(node, segment, dirname)
542
+ preferences = preferences_for_path(node, segment, dirname)
543
+ filenames_by_pref = Hash.new
544
+ preferences.each { |pref| filenames_by_pref[pref] = Array.new }
545
+
546
+ manifest[segment].each do |manifest_record|
547
+ manifest_record_path = manifest_record[:path]
548
+
549
+ # find the NON SPECIFIC filenames, but prefer them by filespecificity.
550
+ # For example, if we have a file:
551
+ # 'files/default/somedir/somefile.conf' we only keep
552
+ # 'somedir/somefile.conf'. If there is also
553
+ # 'files/$hostspecific/somedir/otherfiles' that matches the requested
554
+ # hostname specificity, that directory will win, as it is more specific.
555
+ #
556
+ # This is clearly ugly b/c the use case is for remote directory, where
557
+ # we're just going to make cookbook_files out of these and make the
558
+ # cookbook find them by filespecificity again. but it's the shortest
559
+ # path to "success" for now.
560
+ if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)})\/.+$/
561
+ specificity_dirname = $1
562
+ non_specific_path = manifest_record_path[/#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)}\/(.+)$/, 1]
563
+ # Record the specificity_dirname only if it's in the list of
564
+ # valid preferences
565
+ if filenames_by_pref[specificity_dirname]
566
+ filenames_by_pref[specificity_dirname] << non_specific_path
567
+ end
568
+ end
569
+ end
570
+
571
+ best_pref = preferences.find { |pref| !filenames_by_pref[pref].empty? }
572
+
573
+ raise Chef::Exceptions::FileNotFound, "cookbook #{name} has no directory #{segment}/#{dirname}" unless best_pref
574
+
575
+ filenames_by_pref[best_pref]
576
+
577
+ end
578
+
579
+ # Determine the manifest records from the most specific directory
580
+ # for the given node. See #preferred_manifest_record for a
581
+ # description of entries of the returned Array.
582
+ def preferred_manifest_records_for_directory(node, segment, dirname)
583
+ preferences = preferences_for_path(node, segment, dirname)
584
+ records_by_pref = Hash.new
585
+ preferences.each { |pref| records_by_pref[pref] = Array.new }
586
+
587
+ manifest[segment].each do |manifest_record|
588
+ manifest_record_path = manifest_record[:path]
589
+
590
+ # extract the preference part from the path.
591
+ if manifest_record_path =~ /(#{Regexp.escape(segment.to_s)}\/[^\/]+\/#{Regexp.escape(dirname)})\/.+$/
592
+ # Note the specificy_dirname includes the segment and
593
+ # dirname argument as above, which is what
594
+ # preferences_for_path returns. It could be
595
+ # "files/ubuntu-9.10/dirname", for example.
596
+ specificity_dirname = $1
597
+
598
+ # Record the specificity_dirname only if it's in the list of
599
+ # valid preferences
600
+ if records_by_pref[specificity_dirname]
601
+ records_by_pref[specificity_dirname] << manifest_record
602
+ end
603
+ end
604
+ end
605
+
606
+ best_pref = preferences.find { |pref| !records_by_pref[pref].empty? }
607
+
608
+ raise Chef::Exceptions::FileNotFound, "cookbook #{name} has no directory #{segment}/#{dirname}" unless best_pref
609
+
610
+ records_by_pref[best_pref]
611
+ end
612
+
613
+
614
+ # Given a node, segment and path (filename or directory name),
615
+ # return the priority-ordered list of preference locations to
616
+ # look.
617
+ def preferences_for_path(node, segment, path)
618
+ # only files and templates can be platform-specific
619
+ if segment.to_sym == :files || segment.to_sym == :templates
620
+ begin
621
+ platform, version = Chef::Platform.find_platform_and_version(node)
622
+ rescue ArgumentError => e
623
+ # Skip platform/version if they were not found by find_platform_and_version
624
+ if e.message =~ /Cannot find a (?:platform|version)/
625
+ platform = "/unknown_platform/"
626
+ version = "/unknown_platform_version/"
627
+ else
628
+ raise
629
+ end
630
+ end
631
+
632
+ fqdn = node[:fqdn]
633
+
634
+ # Most specific to least specific places to find the path
635
+ [
636
+ File.join(segment.to_s, "host-#{fqdn}", path),
637
+ File.join(segment.to_s, "#{platform}-#{version}", path),
638
+ File.join(segment.to_s, platform.to_s, path),
639
+ File.join(segment.to_s, "default", path)
640
+ ]
641
+ else
642
+ [File.join(segment, path)]
643
+ end
644
+ end
645
+ private :preferences_for_path
646
+
647
+ def to_hash
648
+ result = manifest.dup
649
+ result['chef_type'] = 'cookbook_version'
650
+ result["_rev"] = couchdb_rev if couchdb_rev
651
+ result.to_hash
652
+ end
653
+
654
+ def to_json(*a)
655
+ result = self.to_hash
656
+ result['json_class'] = self.class.name
657
+ result.to_json(*a)
658
+ end
659
+
660
+ def self.json_create(o)
661
+ cookbook_version = new(o["cookbook_name"])
662
+ if o.has_key?('_rev')
663
+ cookbook_version.couchdb_rev = o["_rev"] if o.has_key?("_rev")
664
+ o.delete("_rev")
665
+ end
666
+ if o.has_key?("_id")
667
+ cookbook_version.couchdb_id = o["_id"] if o.has_key?("_id")
668
+ cookbook_version.index_id = cookbook_version.couchdb_id
669
+ o.delete("_id")
670
+ end
671
+ cookbook_version.manifest = o
672
+ # We want the Chef::Cookbook::Metadata object to always be inflated
673
+ cookbook_version.metadata = Chef::Cookbook::Metadata.from_hash(o["metadata"])
674
+ cookbook_version
675
+ end
676
+
677
+ def generate_manifest_with_urls(&url_generator)
678
+ rendered_manifest = manifest.dup
679
+ COOKBOOK_SEGMENTS.each do |segment|
680
+ if rendered_manifest.has_key?(segment)
681
+ rendered_manifest[segment].each do |manifest_record|
682
+ url_options = { :cookbook_name => name.to_s, :cookbook_version => version, :checksum => manifest_record["checksum"] }
683
+ manifest_record["url"] = url_generator.call(url_options)
684
+ end
685
+ end
686
+ end
687
+ rendered_manifest
688
+ end
689
+
690
+ def metadata_json_file
691
+ File.join(root_dir, "metadata.json")
692
+ end
693
+
694
+ def metadata_rb_file
695
+ File.join(root_dir, "metadata.rb")
696
+ end
697
+
698
+ def reload_metadata!
699
+ if File.exists?(metadata_json_file)
700
+ metadata.from_json(IO.read(metadata_json_file))
701
+ end
702
+ end
703
+
704
+ ##
705
+ # REST API
706
+ ##
707
+ def self.chef_server_rest
708
+ Chef::REST.new(Chef::Config[:chef_server_url])
709
+ end
710
+
711
+ def chef_server_rest
712
+ self.class.chef_server_rest
713
+ end
714
+
715
+ def save
716
+ chef_server_rest.put_rest("cookbooks/#{name}/#{version}", self)
717
+ self
718
+ end
719
+ alias :create :save
720
+
721
+ def destroy
722
+ chef_server_rest.delete_rest("cookbooks/#{name}/#{version}")
723
+ self
724
+ end
725
+
726
+ def self.load(name, version="_latest")
727
+ version = "_latest" if version == "latest"
728
+ chef_server_rest.get_rest("cookbooks/#{name}/#{version}")
729
+ end
730
+
731
+ def self.list
732
+ chef_server_rest.get_rest('cookbooks')
733
+ end
734
+
735
+ ##
736
+ # Given a +cookbook_name+, get a list of all versions that exist on the
737
+ # server.
738
+ # ===Returns
739
+ # [String]:: Array of cookbook versions, which are strings like 'x.y.z'
740
+ # nil:: if the cookbook doesn't exist. an error will also be logged.
741
+ def self.available_versions(cookbook_name)
742
+ chef_server_rest.get_rest("cookbooks/#{cookbook_name}").values.flatten
743
+ rescue Net::HTTPServerException => e
744
+ if e.to_s =~ /^404/
745
+ Chef::Log.error("Cannot find a cookbook named #{cookbook_name}")
746
+ nil
747
+ else
748
+ raise
749
+ end
750
+ end
751
+
752
+ # Get the newest version of all cookbooks
753
+ def self.latest_cookbooks
754
+ chef_server_rest.get_rest('cookbooks/_latest')
755
+ end
756
+
757
+ ##
758
+ # Couchdb
759
+ ##
760
+
761
+ def self.cdb_by_name(cookbook_name, couchdb=nil)
762
+ cdb = (couchdb || Chef::CouchDB.new)
763
+ options = { :startkey => cookbook_name, :endkey => cookbook_name }
764
+ rs = cdb.get_view("cookbooks", "all_with_version", options)
765
+ rs["rows"].inject({}) { |memo, row| memo.has_key?(row["key"]) ? memo[row["key"]] << row["value"] : memo[row["key"]] = [ row["value"] ]; memo }
766
+ end
767
+
768
+ def self.create_design_document(couchdb=nil)
769
+ (couchdb || Chef::CouchDB.new).create_design_document("cookbooks", DESIGN_DOCUMENT)
770
+ end
771
+
772
+ def self.cdb_list_latest(inflate=false, couchdb=nil)
773
+ couchdb ||= Chef::CouchDB.new
774
+ if inflate
775
+ doc_ids = cdb_list_latest_ids.map {|i|i["id"]}
776
+ couchdb.bulk_get(doc_ids)
777
+ else
778
+ results = couchdb.get_view("cookbooks", "all_latest_version", :group=>true)["rows"]
779
+ results.inject({}) { |mapped, row| mapped[row["key"]] = row["value"]; mapped}
780
+ end
781
+ end
782
+
783
+ def self.cdb_list_latest_ids(inflate=false, couchdb=nil)
784
+ couchdb ||= Chef::CouchDB.new
785
+ results = couchdb.get_view("cookbooks", "all_latest_version_by_id", :group=>true)["rows"]
786
+ results.map { |name_and_id| name_and_id["value"]}
787
+ end
788
+
789
+ def self.cdb_list(inflate=false, couchdb=nil)
790
+ rs = (couchdb || Chef::CouchDB.new).list("cookbooks", inflate)
791
+ lookup = (inflate ? "value" : "key")
792
+ rs["rows"].collect { |r| r[lookup] }
793
+ end
794
+
795
+ def self.cdb_load(name, version='latest', couchdb=nil)
796
+ cdb = couchdb || Chef::CouchDB.new
797
+ if version == "latest" || version == "_latest"
798
+ rs = cdb.get_view("cookbooks", "all_latest_version", :key => name, :descending => true, :group => true, :reduce => true)["rows"].first
799
+ cdb.load("cookbook_version", "#{rs["key"]}-#{rs["value"]}")
800
+ else
801
+ cdb.load("cookbook_version", "#{name}-#{version}")
802
+ end
803
+ end
804
+
805
+ def cdb_destroy
806
+ (couchdb || Chef::CouchDB.new).delete("cookbook_version", full_name, couchdb_rev)
807
+ end
808
+
809
+ # Runs on Chef Server (API); deletes the cookbook from couchdb and also destroys associated
810
+ # checksum documents
811
+ def purge
812
+ checksums.keys.each do |checksum|
813
+ begin
814
+ Chef::Checksum.cdb_load(checksum, couchdb).purge
815
+ rescue Chef::Exceptions::CouchDBNotFound
816
+ end
817
+ end
818
+ cdb_destroy
819
+ end
820
+
821
+ def cdb_save
822
+ @couchdb_rev = couchdb.store("cookbook_version", full_name, self)["rev"]
823
+ end
824
+
825
+ def couchdb_id=(value)
826
+ @couchdb_id = value
827
+ @index_id = value
828
+ end
829
+
830
+ private
831
+
832
+ # For each filename, produce a mapping of base filename (i.e. recipe name
833
+ # or attribute file) to on disk location
834
+ def filenames_by_name(filenames)
835
+ filenames.select{|filename| filename =~ /\.rb$/}.inject({}){|memo, filename| memo[File.basename(filename, '.rb')] = filename ; memo }
836
+ end
837
+
838
+ # See #manifest for a description of the manifest return value.
839
+ # See #preferred_manifest_record for a description an individual manifest record.
840
+ def generate_manifest
841
+ manifest = Mash.new({
842
+ :recipes => Array.new,
843
+ :definitions => Array.new,
844
+ :libraries => Array.new,
845
+ :attributes => Array.new,
846
+ :files => Array.new,
847
+ :templates => Array.new,
848
+ :resources => Array.new,
849
+ :providers => Array.new,
850
+ :root_files => Array.new
851
+ })
852
+ checksums_to_on_disk_paths = {}
853
+
854
+ COOKBOOK_SEGMENTS.each do |segment|
855
+ segment_filenames(segment).each do |segment_file|
856
+ next if File.directory?(segment_file)
857
+
858
+ file_name = nil
859
+ path = nil
860
+ specificity = "default"
861
+
862
+ if segment == :root_files
863
+ matcher = segment_file.match(".+/#{Regexp.escape(name.to_s)}/(.+)")
864
+ file_name = matcher[1]
865
+ path = file_name
866
+ elsif segment == :templates || segment == :files
867
+ matcher = segment_file.match("/#{Regexp.escape(name.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+?)/(.+))")
868
+ unless matcher
869
+ Chef::Log.debug("Skipping file #{segment_file}, as it doesn't have a proper segment.")
870
+ next
871
+ end
872
+ path = matcher[1]
873
+ specificity = matcher[2]
874
+ file_name = matcher[3]
875
+ else
876
+ matcher = segment_file.match("/#{Regexp.escape(name.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+))")
877
+ path = matcher[1]
878
+ file_name = matcher[2]
879
+ end
880
+
881
+ csum = self.class.checksum_cookbook_file(segment_file)
882
+ checksums_to_on_disk_paths[csum] = segment_file
883
+ rs = Mash.new({
884
+ :name => file_name,
885
+ :path => path,
886
+ :checksum => csum
887
+ })
888
+ rs[:specificity] = specificity
889
+
890
+ manifest[segment] << rs
891
+ end
892
+ end
893
+
894
+ manifest[:cookbook_name] = name.to_s
895
+ manifest[:metadata] = metadata
896
+ manifest[:version] = metadata.version
897
+ manifest[:name] = full_name
898
+
899
+ @checksums = checksums_to_on_disk_paths
900
+ @manifest = manifest
901
+ @manifest_records_by_path = extract_manifest_records_by_path(manifest)
902
+ end
903
+
904
+ def file_vendor
905
+ unless @file_vendor
906
+ @file_vendor = Chef::Cookbook::FileVendor.create_from_manifest(manifest)
907
+ end
908
+ @file_vendor
909
+ end
910
+
911
+ def extract_checksums_from_manifest(manifest)
912
+ checksums = {}
913
+ COOKBOOK_SEGMENTS.each do |segment|
914
+ next unless manifest.has_key?(segment)
915
+ manifest[segment].each do |manifest_record|
916
+ checksums[manifest_record[:checksum]] = nil
917
+ end
918
+ end
919
+ checksums
920
+ end
921
+
922
+ def extract_manifest_records_by_path(manifest)
923
+ manifest_records_by_path = {}
924
+ COOKBOOK_SEGMENTS.each do |segment|
925
+ next unless manifest.has_key?(segment)
926
+ manifest[segment].each do |manifest_record|
927
+ manifest_records_by_path[manifest_record[:path]] = manifest_record
928
+ end
929
+ end
930
+ manifest_records_by_path
931
+ end
932
+
933
+ end
934
+ end