summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--History.txt5
-rw-r--r--LICENSE201
-rwxr-xr-xbin/chef-client26
-rwxr-xr-xbin/chef-indexer25
-rwxr-xr-xbin/chef-server25
-rwxr-xr-xbin/chef-solo25
-rw-r--r--examples/config/cookbooks/fakefile/recipes/default.rb9
-rw-r--r--examples/config/cookbooks/fakefile/templates/default/monkey.erb3
-rw-r--r--examples/config/cookbooks/fakefile/templates/default/somefile.erb3
-rw-r--r--lib/chef.rb27
-rw-r--r--lib/chef/client.rb25
-rw-r--r--lib/chef/compile.rb29
-rw-r--r--lib/chef/config.rb25
-rw-r--r--lib/chef/cookbook.rb25
-rw-r--r--lib/chef/cookbook_loader.rb68
-rw-r--r--lib/chef/couchdb.rb17
-rw-r--r--lib/chef/exceptions.rb25
-rw-r--r--lib/chef/file_store.rb17
-rw-r--r--lib/chef/log.rb29
-rw-r--r--lib/chef/log/formatter.rb29
-rw-r--r--lib/chef/mixin/check_helper.rb26
-rw-r--r--lib/chef/mixin/from_file.rb28
-rw-r--r--lib/chef/mixin/params_validate.rb30
-rw-r--r--lib/chef/node.rb26
-rw-r--r--lib/chef/openid_registration.rb26
-rw-r--r--lib/chef/platform.rb33
-rw-r--r--lib/chef/provider.rb26
-rw-r--r--lib/chef/provider/directory.rb26
-rw-r--r--lib/chef/provider/file.rb61
-rw-r--r--lib/chef/provider/link.rb26
-rw-r--r--lib/chef/provider/template.rb97
-rw-r--r--lib/chef/queue.rb24
-rw-r--r--lib/chef/recipe.rb26
-rw-r--r--lib/chef/resource.rb26
-rw-r--r--lib/chef/resource/directory.rb28
-rw-r--r--lib/chef/resource/file.rb33
-rw-r--r--lib/chef/resource/link.rb28
-rw-r--r--lib/chef/resource/template.rb31
-rw-r--r--lib/chef/resource_collection.rb24
-rw-r--r--lib/chef/resource_definition.rb24
-rw-r--r--lib/chef/rest.rb51
-rw-r--r--lib/chef/runner.rb26
-rw-r--r--lib/chef/search.rb24
-rw-r--r--lib/chef/search_index.rb24
-rw-r--r--lib/chef_server/controllers/application.rb18
-rw-r--r--lib/chef_server/controllers/cookbook_templates.rb66
-rw-r--r--lib/chef_server/controllers/cookbooks.rb18
-rw-r--r--lib/chef_server/controllers/exceptions.rb18
-rw-r--r--lib/chef_server/controllers/nodes.rb18
-rw-r--r--lib/chef_server/controllers/openid_consumer.rb18
-rw-r--r--lib/chef_server/controllers/openid_register.rb19
-rw-r--r--lib/chef_server/controllers/openid_server.rb18
-rw-r--r--lib/chef_server/controllers/search.rb18
-rw-r--r--lib/chef_server/controllers/search_entries.rb18
-rw-r--r--lib/chef_server/helpers/global_helpers.rb18
-rw-r--r--lib/chef_server/helpers/nodes_helper.rb18
-rw-r--r--lib/chef_server/helpers/openid_server_helpers.rb18
-rw-r--r--lib/chef_server/init.rb22
-rw-r--r--lib/chef_server/views/cookbook_templates/index.html.haml8
-rw-r--r--lib/chef_server/views/cookbooks/show.html.haml8
-rw-r--r--spec/unit/provider/file_spec.rb13
-rw-r--r--spec/unit/provider/template_spec.rb85
-rw-r--r--spec/unit/rest_spec.rb29
63 files changed, 1240 insertions, 620 deletions
diff --git a/History.txt b/History.txt
index 5080d3f7fb..ee966db3b8 100644
--- a/History.txt
+++ b/History.txt
@@ -10,4 +10,7 @@ Mon Jun 9 01:57:58 PDT 2008
* Compiled first full recipes over a network, with registration and authorization.
Thu Jul 10 19:59:46 PDT 2008
- * Search support functional! \ No newline at end of file
+ * Search support functional!
+
+Sat Aug 16 17:46:34 PDT 2008
+ * Compiled a template! \ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000000..11069edd79
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
+
+APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+Copyright [yyyy] [name of copyright owner]
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
diff --git a/bin/chef-client b/bin/chef-client
index d7567ea5a8..7be305f5e6 100755
--- a/bin/chef-client
+++ b/bin/chef-client
@@ -4,22 +4,20 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
$: << File.join(File.dirname(__FILE__), "..", "lib")
diff --git a/bin/chef-indexer b/bin/chef-indexer
index 5ac363f58b..76606e9219 100755
--- a/bin/chef-indexer
+++ b/bin/chef-indexer
@@ -4,22 +4,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
$: << File.join(File.dirname(__FILE__), "..", "lib")
diff --git a/bin/chef-server b/bin/chef-server
index dfdb720ab7..1322fdd03f 100755
--- a/bin/chef-server
+++ b/bin/chef-server
@@ -4,22 +4,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
# Based on the 'merb' command, by Ezra
diff --git a/bin/chef-solo b/bin/chef-solo
index 194f2beeae..ecc06afb79 100755
--- a/bin/chef-solo
+++ b/bin/chef-solo
@@ -4,22 +4,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
$: << File.join(File.dirname(__FILE__), "..", "lib")
diff --git a/examples/config/cookbooks/fakefile/recipes/default.rb b/examples/config/cookbooks/fakefile/recipes/default.rb
index 2ee933716a..a0fef8449d 100644
--- a/examples/config/cookbooks/fakefile/recipes/default.rb
+++ b/examples/config/cookbooks/fakefile/recipes/default.rb
@@ -1,5 +1,4 @@
-
file "/tmp/foo" do
owner "adam"
mode 0644
@@ -10,10 +9,14 @@ end
template "/tmp/foo-template" do
owner "adam"
mode 0644
- template "template"
+ template "monkey.erb"
variables({
:one => 'two',
- :el_che => 'rhymefest'
+ :el_che => 'rhymefest',
+ :white => {
+ :stripes => "are the best",
+ :at => "the sleazy rock thing"
+ }
})
end
diff --git a/examples/config/cookbooks/fakefile/templates/default/monkey.erb b/examples/config/cookbooks/fakefile/templates/default/monkey.erb
new file mode 100644
index 0000000000..ec77de8420
--- /dev/null
+++ b/examples/config/cookbooks/fakefile/templates/default/monkey.erb
@@ -0,0 +1,3 @@
+This is a <%= @one %> with <%= @el_che %>
+
+It was rendered on a system with the ipaddress of <%= @node[:ipaddress]%> \ No newline at end of file
diff --git a/examples/config/cookbooks/fakefile/templates/default/somefile.erb b/examples/config/cookbooks/fakefile/templates/default/somefile.erb
deleted file mode 100644
index 8c7ffed237..0000000000
--- a/examples/config/cookbooks/fakefile/templates/default/somefile.erb
+++ /dev/null
@@ -1,3 +0,0 @@
-Here you go!
-
-<%= @some_variable %>
diff --git a/lib/chef.rb b/lib/chef.rb
index 4b132e6189..ac7f43adef 100644
--- a/lib/chef.rb
+++ b/lib/chef.rb
@@ -1,21 +1,20 @@
+#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
require 'rubygems'
diff --git a/lib/chef/client.rb b/lib/chef/client.rb
index 681260eee2..593086c9ff 100644
--- a/lib/chef/client.rb
+++ b/lib/chef/client.rb
@@ -1,22 +1,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
require File.join(File.dirname(__FILE__), "mixin", "params_validate")
diff --git a/lib/chef/compile.rb b/lib/chef/compile.rb
index 83192d4f26..d5f38368ed 100644
--- a/lib/chef/compile.rb
+++ b/lib/chef/compile.rb
@@ -1,26 +1,19 @@
#
-# Chef::Compile
-#
-# Compile a nodes resources.
-#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
class Chef
class Compile
diff --git a/lib/chef/config.rb b/lib/chef/config.rb
index cf4faf727e..dd44baf220 100644
--- a/lib/chef/config.rb
+++ b/lib/chef/config.rb
@@ -1,22 +1,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
require File.join(File.dirname(__FILE__), "mixin", "check_helper")
require File.join(File.dirname(__FILE__), "mixin", "from_file")
diff --git a/lib/chef/cookbook.rb b/lib/chef/cookbook.rb
index b7c6506a99..46fc956d83 100644
--- a/lib/chef/cookbook.rb
+++ b/lib/chef/cookbook.rb
@@ -1,22 +1,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
class Chef
class Cookbook
diff --git a/lib/chef/cookbook_loader.rb b/lib/chef/cookbook_loader.rb
index ee4e1891e3..6f6c8d8010 100644
--- a/lib/chef/cookbook_loader.rb
+++ b/lib/chef/cookbook_loader.rb
@@ -1,22 +1,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
class Chef
class CookbookLoader
@@ -63,16 +60,18 @@ class Chef
cookbook_settings[cookbook_name][:recipe_files],
cookbook_settings[cookbook_name][:ignore_regexes]
)
- load_files_unless_basename(
- File.join(cookbook, "templates", "*.erb"),
+ load_cascading_files(
+ File.join(cookbook, "templates", "**", "*.erb"),
+ File.join(cookbook, "templates"),
cookbook_settings[cookbook_name][:template_files],
cookbook_settings[cookbook_name][:ignore_regexes]
)
- load_files_unless_basename(
- File.join(cookbook, "files", "*"),
- cookbook_settings[cookbook_name][:remote_files],
- cookbook_settings[cookbook_name][:ignore_regexes]
- )
+ load_cascading_files(
+ File.join(cookbook, "files", "**", "*"),
+ File.join(cookbook, "files"),
+ cookbook_settings[cookbook_name][:remote_files],
+ cookbook_settings[cookbook_name][:ignore_regexes]
+ )
end
end
cookbook_settings.each_key do |cookbook|
@@ -113,14 +112,21 @@ class Chef
end
results
end
-
- def load_files_unless_basename(file_glob, result_array, ignore_regexes)
+
+ def load_cascading_files(file_glob, base_path, result_array, ignore_regexes)
Dir[file_glob].each do |file|
- skip = false
- ignore_regexes.each do |exp|
- skip = true if exp.match(file)
+ next if skip_file(file, ignore_regexes)
+ file =~ /^#{base_path}\/(.+)$/
+ singlecopy = $1
+ unless result_array.detect { |f| f =~ /#{singlecopy}$/ }
+ result_array << file
end
- next if skip
+ end
+ end
+
+ def load_files_unless_basename(file_glob, result_array, ignore_regexes)
+ Dir[file_glob].each do |file|
+ next if skip_file(file, ignore_regexes)
file_basename = File.basename(file)
# If we've seen a file with this basename before, skip it.
unless result_array.detect { |f| File.basename(f) == file_basename }
@@ -129,5 +135,13 @@ class Chef
end
end
+ def skip_file(file, ignore_regexes)
+ skip = false
+ ignore_regexes.each do |exp|
+ skip = true if exp.match(file)
+ end
+ skip
+ end
+
end
end \ No newline at end of file
diff --git a/lib/chef/couchdb.rb b/lib/chef/couchdb.rb
index 83bf3982f7..22a651ca48 100644
--- a/lib/chef/couchdb.rb
+++ b/lib/chef/couchdb.rb
@@ -1,3 +1,20 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
require File.join(File.dirname(__FILE__), "mixin", "params_validate")
require 'digest/sha2'
require 'json'
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb
index 687b962b0e..94a6950414 100644
--- a/lib/chef/exceptions.rb
+++ b/lib/chef/exceptions.rb
@@ -1,22 +1,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
class Chef
class Exception
diff --git a/lib/chef/file_store.rb b/lib/chef/file_store.rb
index 4981cec802..6f030784a1 100644
--- a/lib/chef/file_store.rb
+++ b/lib/chef/file_store.rb
@@ -1,3 +1,20 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
require File.join(File.dirname(__FILE__), "mixin", "params_validate")
require 'digest/sha2'
require 'json'
diff --git a/lib/chef/log.rb b/lib/chef/log.rb
index cf8b0b45e9..ff98cc9dff 100644
--- a/lib/chef/log.rb
+++ b/lib/chef/log.rb
@@ -1,26 +1,19 @@
#
-# Chef::Logger
-#
-# A simple wrapper for the standard Ruby Logger.
-#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
require 'logger'
diff --git a/lib/chef/log/formatter.rb b/lib/chef/log/formatter.rb
index 1c7044bdb1..9f758178f5 100644
--- a/lib/chef/log/formatter.rb
+++ b/lib/chef/log/formatter.rb
@@ -1,26 +1,19 @@
#
-# Chef::Log::Formatter
-#
-# A custom Logger::Formatter implementation for Chef.
-#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
require 'logger'
require 'time'
diff --git a/lib/chef/mixin/check_helper.rb b/lib/chef/mixin/check_helper.rb
index a4208c7e49..959b57cbb7 100644
--- a/lib/chef/mixin/check_helper.rb
+++ b/lib/chef/mixin/check_helper.rb
@@ -1,21 +1,19 @@
+#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
class Chef
module Mixin
diff --git a/lib/chef/mixin/from_file.rb b/lib/chef/mixin/from_file.rb
index b1ad600ef8..05f7fe8e8b 100644
--- a/lib/chef/mixin/from_file.rb
+++ b/lib/chef/mixin/from_file.rb
@@ -1,25 +1,19 @@
#
-# Chef::Mixin::FromFile
-#
-# A mixin that adds instance_eval support to a given object.
-#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
#
class Chef
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb
index 2f6e432024..6448e31811 100644
--- a/lib/chef/mixin/params_validate.rb
+++ b/lib/chef/mixin/params_validate.rb
@@ -1,27 +1,19 @@
-#
-# Chef::Mixin::ParamsValidate
-#
-# Because I can't deal with not having named params. Strongly based on Dave Rolsky's excellent
-# Params::Validate module for Perl. Please don't blame him, though, this is full of bugs. :)
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
class Chef
module Mixin
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 38b8ccc5d4..83cd134e92 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -1,23 +1,19 @@
#
-# Chef::Node
-#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
#
require File.join(File.dirname(__FILE__), "mixin", "check_helper")
diff --git a/lib/chef/openid_registration.rb b/lib/chef/openid_registration.rb
index a887e05c2c..748c865097 100644
--- a/lib/chef/openid_registration.rb
+++ b/lib/chef/openid_registration.rb
@@ -1,23 +1,19 @@
#
-# Chef::Node::OpenIDRegistration
-#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
#
diff --git a/lib/chef/platform.rb b/lib/chef/platform.rb
index 4114d5960b..d3e7db60e6 100644
--- a/lib/chef/platform.rb
+++ b/lib/chef/platform.rb
@@ -1,22 +1,20 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
Dir[File.join(File.dirname(__FILE__), 'provider/**/*.rb')].sort.each { |lib| require lib }
require File.join(File.dirname(__FILE__), 'mixin', 'params_validate')
@@ -87,7 +85,7 @@ class Chef
end
end
- def find_provider_for_node(node, resource_type)
+ def find_platform_and_version(node)
platform = nil
version = nil
if node.attribute?("lsbdistid")
@@ -108,6 +106,11 @@ class Chef
end
raise ArgumentError, "Cannot find a version for #{node}" unless version
+ return platform, version
+ end
+
+ def find_provider_for_node(node, resource_type)
+ platform, version = find_platform_and_version(node)
provider = find_provider(platform, version, resource_type)
end
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb
index 32e2491028..b1949631f1 100644
--- a/lib/chef/provider.rb
+++ b/lib/chef/provider.rb
@@ -1,22 +1,20 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
class Chef
class Provider
diff --git a/lib/chef/provider/directory.rb b/lib/chef/provider/directory.rb
index da6770e47b..34257504fc 100644
--- a/lib/chef/provider/directory.rb
+++ b/lib/chef/provider/directory.rb
@@ -1,22 +1,20 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
require File.join(File.dirname(__FILE__), "file")
diff --git a/lib/chef/provider/file.rb b/lib/chef/provider/file.rb
index 7bb729cd87..d8644f50ee 100644
--- a/lib/chef/provider/file.rb
+++ b/lib/chef/provider/file.rb
@@ -1,25 +1,24 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
require 'digest/md5'
require 'etc'
+require 'fileutils'
class Chef
class Provider
@@ -32,17 +31,18 @@ class Chef
@current_resource.owner(cstats.uid)
@current_resource.group(cstats.gid)
@current_resource.mode("%o" % (cstats.mode & 007777))
- checksum
+ @current_resource.checksum(checksum(@current_resource.path))
end
@current_resource
end
- def checksum
+ def checksum(file)
digest = Digest::MD5.new
- IO.foreach(@current_resource.path) do |line|
- digest << line
+ fh = ::File.open(file)
+ fh.each do |line|
+ digest.update(line)
end
- @current_resource.checksum(digest.hexdigest)
+ digest.hexdigest
end
# Compare the ownership of a file. Returns true if they are the same, false if they are not.
@@ -125,6 +125,7 @@ class Chef
def action_delete
if ::File.exists?(@new_resource.path) && ::File.writable?(@new_resource.path)
+ backup
Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.path}")
::File.delete(@new_resource.path)
@new_resource.updated = true
@@ -141,6 +142,28 @@ class Chef
@new_resource.updated = true
end
+ def backup
+ if @new_resource.backup
+ time = Time.now
+ savetime = time.strftime("%Y%m%d%H%M%S")
+ backup_filename = "#{@new_resource.path}.chef-#{savetime}"
+ Chef::Log.info("Backing up #{@new_resource} to #{backup_filename}")
+ FileUtils.cp(@new_resource.path, backup_filename)
+
+ # Clean up after the number of backups
+ slice_number = @new_resource.backup - 1
+ backup_files = Dir["#{@new_resource.path}.chef-*"].sort { |a,b| b <=> a }
+ if backup_files.length >= @new_resource.backup
+ remainder = backup_files.slice(slice_number..-1)
+ remainder.each do |backup_to_delete|
+ Chef::Log.info("Removing backup of #{@new_resource} at #{backup_to_delete}")
+ FileUtils.rm(backup_to_delete)
+ end
+ end
+
+ end
+ end
+
end
end
end \ No newline at end of file
diff --git a/lib/chef/provider/link.rb b/lib/chef/provider/link.rb
index 4a1254de9b..843a4ad009 100644
--- a/lib/chef/provider/link.rb
+++ b/lib/chef/provider/link.rb
@@ -1,22 +1,20 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
class Chef
class Provider
diff --git a/lib/chef/provider/template.rb b/lib/chef/provider/template.rb
index 47ffc810bf..78736f2882 100644
--- a/lib/chef/provider/template.rb
+++ b/lib/chef/provider/template.rb
@@ -1,25 +1,25 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
require File.join(File.dirname(__FILE__), "file")
require 'uri'
+require 'erubis'
+require 'tempfile'
class Chef
class Provider
@@ -27,43 +27,58 @@ class Chef
def action_create
r = Chef::REST.new(Chef::Config[:template_url])
- template_url = nil
- if @new_resource.template =~ /^http/
- template_url = @new_resource.template
+
+ template_url = generate_url(@new_resource.template)
+ raw_template_file = r.get_rest(template_url, true)
+
+ template_file = render_template(raw_template_file.path)
+
+ update = false
+ if ::File.exists?(@new_resource.path)
+ @new_resource.checksum(self.checksum(template_file.path))
+ if @new_resource.checksum != @current_resource.checksum
+ Chef::Log.debug("#{@new_resource} changed from #{@current_resource.checksum} to #{@new_resource.checksum}")
+ Chef::Log.info("Updating #{@new_resource} at #{@new_resource.path}")
+ update = true
+ end
else
- template_url = "cookbooks/#{@new_resource.cookbook_name}/templates/#{@new_resource.template}"
+ Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
+ update = true
end
- template = r.get_rest(template_url)
-
- unless ::File.exists?(@new_resource.path)
- Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
- ::File.open(@new_resource.path, "w+") { |f| }
- @new_resource.updated = true
+ if update
+ FileUtils.cp(template_file.path, @new_resource.path)
end
+
set_owner if @new_resource.owner != nil
set_group if @new_resource.group != nil
set_mode if @new_resource.mode != nil
end
-
- def action_delete
- if ::File.exists?(@new_resource.path) && ::File.writable?(@new_resource.path)
- Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.path}")
- ::File.delete(@new_resource.path)
- @new_resource.updated = true
- else
- raise "Cannot delete #{@new_resource} at #{@new_resource_path}!"
- end
+ end
+
+ def render_template(file)
+ eruby = Erubis::Eruby.new(::File.read(file))
+ context = @new_resource.variables
+ context[:node] = @node
+ output = eruby.evaluate(context)
+ final_tempfile = Tempfile.new("chef-rendered-template")
+ final_tempfile.puts(output)
+ final_tempfile.close
+ final_tempfile
+ end
+
+ def generate_url(url)
+ template_url = nil
+ if url =~ /^http/
+ template_url = url
+ else
+ template_url = "cookbooks/#{@new_resource.cookbook_name}/templates?"
+ template_url += "id=#{url}"
+ platform, version = Chef::Platform.find_platform_and_version(@node)
+ template_url += "&platform=#{platform}&version=#{version}"
end
- def action_touch
- action_create
- time = Time.now
- Chef::Log.info("Updating #{@new_resource} with new atime/mtime of #{time}")
- ::File.utime(time, time, @new_resource.path)
- @new_resource.updated = true
- end
-
+ return template_url
end
end
end \ No newline at end of file
diff --git a/lib/chef/queue.rb b/lib/chef/queue.rb
index 795670d79a..86eb7df257 100644
--- a/lib/chef/queue.rb
+++ b/lib/chef/queue.rb
@@ -1,21 +1,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
#
require File.join(File.dirname(__FILE__), "mixin", "params_validate")
diff --git a/lib/chef/recipe.rb b/lib/chef/recipe.rb
index c161bbdae6..f8344c545f 100644
--- a/lib/chef/recipe.rb
+++ b/lib/chef/recipe.rb
@@ -1,22 +1,20 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
require File.join(File.dirname(__FILE__), "mixin", "from_file")
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 3bd1ddde2e..afd7163a43 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -1,22 +1,20 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
require File.join(File.dirname(__FILE__), "mixin", "params_validate")
require File.join(File.dirname(__FILE__), "mixin", "check_helper")
diff --git a/lib/chef/resource/directory.rb b/lib/chef/resource/directory.rb
index 1e13891fae..e66d8ef948 100644
--- a/lib/chef/resource/directory.rb
+++ b/lib/chef/resource/directory.rb
@@ -1,30 +1,28 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
class Chef
class Resource
class Directory < Chef::Resource
def initialize(name, collection=nil, node=nil)
- @resource_name = :directory
super(name, collection, node)
+ @resource_name = :directory
@path = name
@action = :create
@allowed_actions.push(:create, :delete)
diff --git a/lib/chef/resource/file.rb b/lib/chef/resource/file.rb
index f1cfa86f9a..099bd76591 100644
--- a/lib/chef/resource/file.rb
+++ b/lib/chef/resource/file.rb
@@ -1,33 +1,30 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
-
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
class Chef
class Resource
class File < Chef::Resource
def initialize(name, collection=nil, node=nil)
- @resource_name = :file
super(name, collection, node)
+ @resource_name = :file
@path = name
- @backup = true
+ @backup = 5
@action = "create"
@allowed_actions.push(:create, :delete, :touch)
end
@@ -36,7 +33,7 @@ class Chef
set_or_return(
:backup,
arg,
- :kind_of => [ Integer, TrueClass, FalseClass ]
+ :kind_of => [ Integer, FalseClass ]
)
end
diff --git a/lib/chef/resource/link.rb b/lib/chef/resource/link.rb
index 5ec3b39b25..46b5793b0f 100644
--- a/lib/chef/resource/link.rb
+++ b/lib/chef/resource/link.rb
@@ -1,30 +1,28 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
class Chef
class Resource
class Link < Chef::Resource
def initialize(name, collection=nil, node=nil)
- @resource_name = :link
super(name, collection, node)
+ @resource_name = :link
@source_file = name
@action = :create
@link_type = :symbolic
diff --git a/lib/chef/resource/template.rb b/lib/chef/resource/template.rb
index 25df8c712d..c64d07e187 100644
--- a/lib/chef/resource/template.rb
+++ b/lib/chef/resource/template.rb
@@ -1,31 +1,28 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
-
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
class Chef
class Resource
class Template < Chef::Resource::File
def initialize(name, collection=nil, node=nil)
- @resource_name = :template
super(name, collection, node)
+ @resource_name = :template
@action = "create"
@template = nil
@variables = Hash.new
@@ -41,7 +38,7 @@ class Chef
def variables(args=nil)
set_or_return(
- :vars,
+ :variables,
args,
:kind_of => [ Hash ]
)
diff --git a/lib/chef/resource_collection.rb b/lib/chef/resource_collection.rb
index e53a759460..874ea64378 100644
--- a/lib/chef/resource_collection.rb
+++ b/lib/chef/resource_collection.rb
@@ -1,21 +1,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
#
class Chef
diff --git a/lib/chef/resource_definition.rb b/lib/chef/resource_definition.rb
index 4bc048188f..85466b8541 100644
--- a/lib/chef/resource_definition.rb
+++ b/lib/chef/resource_definition.rb
@@ -1,21 +1,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
#
require File.join(File.dirname(__FILE__), "mixin", "from_file")
diff --git a/lib/chef/rest.rb b/lib/chef/rest.rb
index e4474fb9eb..d4630c3e8c 100644
--- a/lib/chef/rest.rb
+++ b/lib/chef/rest.rb
@@ -1,27 +1,26 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
#
require File.join(File.dirname(__FILE__), "mixin", "params_validate")
require 'net/https'
require 'uri'
require 'json'
+require 'tempfile'
class Chef
class REST
@@ -32,8 +31,8 @@ class Chef
end
# Send an HTTP GET request to the path
- def get_rest(path)
- run_request(:GET, create_url(path))
+ def get_rest(path, raw=false)
+ run_request(:GET, create_url(path), false, 10, raw)
end
# Send an HTTP DELETE request to the path
@@ -68,7 +67,7 @@ class Chef
# the helper methods (get_rest, post_rest, etc.)
#
# Will return the body of the response on success.
- def run_request(method, url, data=false, limit=10)
+ def run_request(method, url, data=false, limit=10, raw=false)
raise ArgumentError, 'HTTP redirect too deep' if limit == 0
http = Net::HTTP.new(url.host, url.port)
@@ -79,9 +78,12 @@ class Chef
end
end
http.read_timeout = Chef::Config[:rest_timeout]
- headers = {
- 'Accept' => "application/json",
- }
+ headers = Hash.new
+ unless raw
+ headers = {
+ 'Accept' => "application/json",
+ }
+ end
if @cookies["#{url.host}:#{url.port}"]
headers['Cookie'] = @cookies["#{url.host}:#{url.port}"]
end
@@ -115,13 +117,20 @@ class Chef
if res['content-type'] == "application/json"
JSON.parse(res.body)
else
- res.body
+ if raw
+ tf = Tempfile.new("chef-rest")
+ tf.puts(res.body)
+ tf.close
+ tf
+ else
+ res.body
+ end
end
elsif res.kind_of?(Net::HTTPRedirection)
if res['set-cookie']
@cookies["#{url.host}:#{url.port}"] = res['set-cookie']
end
- run_request(:GET, create_url(res['location']), false, limit - 1)
+ run_request(:GET, create_url(res['location']), false, limit - 1, raw)
else
res.error!
end
diff --git a/lib/chef/runner.rb b/lib/chef/runner.rb
index 60f3082e88..0c5f91b796 100644
--- a/lib/chef/runner.rb
+++ b/lib/chef/runner.rb
@@ -1,22 +1,20 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# http://www.apache.org/licenses/LICENSE-2.0
#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
require File.join(File.dirname(__FILE__), "mixin", "params_validate")
diff --git a/lib/chef/search.rb b/lib/chef/search.rb
index dba38f79e9..229f738399 100644
--- a/lib/chef/search.rb
+++ b/lib/chef/search.rb
@@ -1,21 +1,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
#
require File.join(File.dirname(__FILE__), "mixin", "params_validate")
diff --git a/lib/chef/search_index.rb b/lib/chef/search_index.rb
index d4d4f77042..932a451999 100644
--- a/lib/chef/search_index.rb
+++ b/lib/chef/search_index.rb
@@ -1,21 +1,19 @@
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
-# License:: GNU General Public License version 2 or later
-#
-# This program and entire repository is free software; you can
-# redistribute it and/or modify it under the terms of the GNU
-# General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or any later version.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
+# http://www.apache.org/licenses/LICENSE-2.0
#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
#
require File.join(File.dirname(__FILE__), "mixin", "params_validate")
diff --git a/lib/chef_server/controllers/application.rb b/lib/chef_server/controllers/application.rb
index 4a0d247306..a288b87dba 100644
--- a/lib/chef_server/controllers/application.rb
+++ b/lib/chef_server/controllers/application.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
class Application < Merb::Controller
def fix_up_node_id
diff --git a/lib/chef_server/controllers/cookbook_templates.rb b/lib/chef_server/controllers/cookbook_templates.rb
index 56338ac3f5..4cb5e4622c 100644
--- a/lib/chef_server/controllers/cookbook_templates.rb
+++ b/lib/chef_server/controllers/cookbook_templates.rb
@@ -1,29 +1,77 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
class CookbookTemplates < Application
provides :html, :json
- def load_cookbook(with_content=false)
+ def load_cookbook_templates()
@cl = Chef::CookbookLoader.new
@cookbook = @cl[params[:cookbook_id]]
raise NotFound unless @cookbook
+
@templates = Hash.new
@cookbook.template_files.each do |tf|
- @templates[File.basename(tf)] = {
- :file => tf,
+ full = File.expand_path(tf)
+ name = File.basename(full)
+ tf =~ /^.+#{params[:cookbook_id]}[\\|\/]templates[\\|\/](.+?)[\\|\/]#{name}/
+ singlecopy = $1
+ @templates[full] = {
+ :name => name,
+ :singlecopy => singlecopy,
+ :file => full,
}
- @templates[File.basename(tf)][:contents] = File.read(tf) if with_content
end
+ @templates
end
def index
- load_cookbook(false)
- display @templates
+ if params[:id]
+ show
+ else
+ load_cookbook_templates()
+ display @templates
+ end
end
def show
- load_cookbook(true)
- @template = @templates[params[:id]]
- display @template
+ load_cookbook_templates()
+ preferences = [
+ File.join("host-#{params[:fqdn]}", "#{params[:id]}"),
+ File.join("#{params[:platform]}-#{params[:version]}", "#{params[:id]}"),
+ File.join("#{params[:platform]}", "#{params[:id]}"),
+ File.join("default", "#{params[:id]}")
+ ]
+ to_send = nil
+ @templates.each_key do |file|
+ Chef::Log.debug("Looking at #{file}")
+ preferences.each do |pref|
+ Chef::Log.debug("Compared to #{pref}")
+ if file =~ /#{pref}/
+ Chef::Log.debug("Matched #{pref} for #{file}!")
+ to_send = file
+ break
+ end
+ end
+ break if to_send
+ end
+ raise NotFound, "Cannot find a suitable template!" unless to_send
+ send_file(to_send)
end
end
diff --git a/lib/chef_server/controllers/cookbooks.rb b/lib/chef_server/controllers/cookbooks.rb
index d18b3506a2..3e68d1f4bc 100644
--- a/lib/chef_server/controllers/cookbooks.rb
+++ b/lib/chef_server/controllers/cookbooks.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
class Cookbooks < Application
provides :html, :json
diff --git a/lib/chef_server/controllers/exceptions.rb b/lib/chef_server/controllers/exceptions.rb
index 7f72e57ad2..d8f7307637 100644
--- a/lib/chef_server/controllers/exceptions.rb
+++ b/lib/chef_server/controllers/exceptions.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
class Exceptions < Application
provides :html, :json
diff --git a/lib/chef_server/controllers/nodes.rb b/lib/chef_server/controllers/nodes.rb
index aa7273c47d..a1ba1131ac 100644
--- a/lib/chef_server/controllers/nodes.rb
+++ b/lib/chef_server/controllers/nodes.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
class Nodes < Application
provides :html, :json
diff --git a/lib/chef_server/controllers/openid_consumer.rb b/lib/chef_server/controllers/openid_consumer.rb
index 39e8173f24..4e3980ce3d 100644
--- a/lib/chef_server/controllers/openid_consumer.rb
+++ b/lib/chef_server/controllers/openid_consumer.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
require 'pathname'
require "openid"
diff --git a/lib/chef_server/controllers/openid_register.rb b/lib/chef_server/controllers/openid_register.rb
index a6c30c95c5..34851bc517 100644
--- a/lib/chef_server/controllers/openid_register.rb
+++ b/lib/chef_server/controllers/openid_register.rb
@@ -1,5 +1,20 @@
-# Controller for handling the login, logout process for "users" of our
-# little server. Users have no password. This is just an example.
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
require 'openid'
diff --git a/lib/chef_server/controllers/openid_server.rb b/lib/chef_server/controllers/openid_server.rb
index 7c89e33d99..4cdaf67adb 100644
--- a/lib/chef_server/controllers/openid_server.rb
+++ b/lib/chef_server/controllers/openid_server.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
require 'pathname'
# load the openid library, first trying rubygems
diff --git a/lib/chef_server/controllers/search.rb b/lib/chef_server/controllers/search.rb
index 17c0d553a4..0abbf352b8 100644
--- a/lib/chef_server/controllers/search.rb
+++ b/lib/chef_server/controllers/search.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
class Search < Application
provides :html, :json
diff --git a/lib/chef_server/controllers/search_entries.rb b/lib/chef_server/controllers/search_entries.rb
index ab79b57b3c..c93add3dc5 100644
--- a/lib/chef_server/controllers/search_entries.rb
+++ b/lib/chef_server/controllers/search_entries.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
class SearchEntries < Application
provides :html, :json
diff --git a/lib/chef_server/helpers/global_helpers.rb b/lib/chef_server/helpers/global_helpers.rb
index 1ef7ac9331..f3b15129a8 100644
--- a/lib/chef_server/helpers/global_helpers.rb
+++ b/lib/chef_server/helpers/global_helpers.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
module Merb
module GlobalHelpers
# helpers defined here available to all views.
diff --git a/lib/chef_server/helpers/nodes_helper.rb b/lib/chef_server/helpers/nodes_helper.rb
index 5e6c25c453..44a190a7c6 100644
--- a/lib/chef_server/helpers/nodes_helper.rb
+++ b/lib/chef_server/helpers/nodes_helper.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
module Merb
module NodesHelper
def recipe_list(node)
diff --git a/lib/chef_server/helpers/openid_server_helpers.rb b/lib/chef_server/helpers/openid_server_helpers.rb
index 73be9cab27..dc56d2742f 100644
--- a/lib/chef_server/helpers/openid_server_helpers.rb
+++ b/lib/chef_server/helpers/openid_server_helpers.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
module Merb
module OpenidServerHelper
diff --git a/lib/chef_server/init.rb b/lib/chef_server/init.rb
index cf1d17e224..886a378cb7 100644
--- a/lib/chef_server/init.rb
+++ b/lib/chef_server/init.rb
@@ -1,3 +1,21 @@
+#
+# Author:: Adam Jacob (<adam@hjksolutions.com>)
+# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
Merb.root = File.join(File.dirname(__FILE__))
#
@@ -141,10 +159,12 @@ Merb::Router.prepare do |r|
end
r.match("/cookbooks/_attribute_files").to(:controller => "cookbooks", :action => "attribute_files")
+# r.match("/cookbooks/:cookbook_id/templates").to(:controller => "cookbook_templates", :action => "index")
+
r.resources :cookbooks do |cookbooks|
cookbooks.resources :templates, :controller => "cookbook_templates"
end
-
+
#r.resources :openid do |res|
# res.resources :register, :controller => "openid_register"
# res.resources :server, :controller => "openid_server"
diff --git a/lib/chef_server/views/cookbook_templates/index.html.haml b/lib/chef_server/views/cookbook_templates/index.html.haml
new file mode 100644
index 0000000000..307aefd812
--- /dev/null
+++ b/lib/chef_server/views/cookbook_templates/index.html.haml
@@ -0,0 +1,8 @@
+%h1 Cookbook Templates
+- @templates.each do |template, data|
+ .index
+ %table
+ %tr
+ %td
+ %a{ :href => url(:cookbook_template, { :cookbook_id => params[:cookbook_id], :id => data[:link_name], :version => data[:version] }) }
+ = "#{data[:version]} - #{data[:name]}"
diff --git a/lib/chef_server/views/cookbooks/show.html.haml b/lib/chef_server/views/cookbooks/show.html.haml
index 58175c298c..d97964f436 100644
--- a/lib/chef_server/views/cookbooks/show.html.haml
+++ b/lib/chef_server/views/cookbooks/show.html.haml
@@ -1,6 +1,7 @@
%h1= "Cookbook #{h @cookbook.name}"
.cookbook
- if @cookbook.attribute_files.length > 0
+ %h2 Attribute Files
- @cookbook.attribute_files.each do |af|
= partial(:attribute_file, :name => File.basename(af), :contents => File.read(af))
@@ -15,4 +16,9 @@
%h2 Recipe Files
%h3= File.basename(rf)
= Uv.parse(File.read(rf), "xhtml", "ruby", true, "twilight")
- \ No newline at end of file
+
+- if @cookbook.template_files.length > 0
+ - @cookbook.template_files.each do |tf|
+ %h2 Template Files
+ %h3= File.basename(tf)
+ = Uv.parse(File.read(tf), "xhtml", "html_rails", true, "twilight")
diff --git a/spec/unit/provider/file_spec.rb b/spec/unit/provider/file_spec.rb
index 3b894ad02a..af7ce7ecd9 100644
--- a/spec/unit/provider/file_spec.rb
+++ b/spec/unit/provider/file_spec.rb
@@ -186,6 +186,7 @@ describe Chef::Provider::File do
it "should delete the file if it exists and is writable on action_delete" do
@provider.load_current_resource
@provider.new_resource.stub!(:path).and_return("/tmp/monkeyfoo")
+ @provider.stub!(:backup).and_return(true)
File.should_receive("exists?").with(@provider.new_resource.path).and_return(true)
File.should_receive("writable?").with(@provider.new_resource.path).and_return(true)
File.should_receive(:delete).with(@provider.new_resource.path).and_return(true)
@@ -194,6 +195,7 @@ describe Chef::Provider::File do
it "should raise an error if it cannot delete the file" do
@provider.load_current_resource
+ @provider.stub!(:backup).and_return(true)
@provider.new_resource.stub!(:path).and_return("/tmp/monkeyfoo")
File.should_receive("exists?").with(@provider.new_resource.path).and_return(false)
lambda { @provider.action_delete }.should raise_error()
@@ -209,4 +211,15 @@ describe Chef::Provider::File do
@provider.action_touch
end
+ it "should backup a file no more than :backup times" do
+ @provider.load_current_resource
+ @provider.new_resource.stub!(:path).and_return("/tmp/s-20080705111233")
+ @provider.new_resource.stub!(:backup).and_return(2)
+ Dir.stub!(:[]).and_return([ "/tmp/s-20080705111233", "/tmp/s-20080705111232", "/tmp/s-20080705111223"])
+ FileUtils.should_receive(:rm).with("/tmp/s-20080705111232").once.and_return(true)
+ FileUtils.should_receive(:rm).with("/tmp/s-20080705111223").once.and_return(true)
+ FileUtils.stub!(:cp).and_return(true)
+ @provider.backup
+ end
+
end \ No newline at end of file
diff --git a/spec/unit/provider/template_spec.rb b/spec/unit/provider/template_spec.rb
new file mode 100644
index 0000000000..773180348c
--- /dev/null
+++ b/spec/unit/provider/template_spec.rb
@@ -0,0 +1,85 @@
+require File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "spec_helper"))
+
+describe Chef::Provider::Template, "action_create" do
+ before(:each) do
+ @rest = mock(Chef::REST, { :get_rest => "/tmp/foobar" })
+ @tempfile = mock(Tempfile, { :path => "/tmp/foo", })
+ @rest.stub!(:get_rest).and_return(@tempfile)
+ @resource = Chef::Resource::Template.new("seattle")
+ @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt"))
+ @resource.template("http://foo")
+ @node = Chef::Node.new
+ @node.name "latte"
+ @provider = Chef::Provider::Template.new(@node, @resource)
+ @provider.stub!(:checksum).and_return("dad86c61eea237932f201009e5431609")
+ @provider.current_resource = @resource.clone
+ @provider.current_resource.checksum("dad86c61eea237932f201009e5431609")
+ FileUtils.stub!(:cp).and_return(true)
+ end
+
+ def do_action_create
+ Chef::REST.stub!(:new).and_return(@rest)
+ @provider.action_create
+ end
+
+ it "should get the template based on the resources template value" do
+ @rest.should_receive(:get_rest).with(@resource.template, true).and_return(@tempfile)
+ do_action_create
+ end
+
+ it "should set the checksum of the new resource to the value of the returned template" do
+ @resource.should_receive(:checksum).with("dad86c61eea237932f201009e5431609").once
+ @resource.should_receive(:checksum).twice
+ do_action_create
+ end
+
+ it "should not copy the tempfile to the real file if the checksums match" do
+ FileUtils.should_not_receive(:cp)
+ do_action_create
+ end
+
+ it "should copy the tempfile to the real file if the checksums do not match" do
+ @provider.stub!(:checksum).and_return("dad86c61eea237932f201009e5431607")
+ FileUtils.should_receive(:cp).with(@tempfile.path, @resource.path)
+ do_action_create
+ end
+
+ it "should set the owner if provided" do
+ @resource.owner("adam")
+ @provider.should_receive(:set_owner).and_return(true)
+ do_action_create
+ end
+
+ it "should set the group if provided" do
+ @resource.group("adam")
+ @provider.should_receive(:set_group).and_return(true)
+ do_action_create
+ end
+
+ it "should set the mode if provided" do
+ @resource.mode(0676)
+ @provider.should_receive(:set_mode).and_return(true)
+ do_action_create
+ end
+end
+
+describe Chef::Provider::Template, "generate_url" do
+
+ before(:each) do
+ @resource = Chef::Resource::Template.new("seattle")
+ @resource.cookbook_name = "daft"
+ @resource.path(File.join(File.dirname(__FILE__), "..", "..", "data", "seattle.txt"))
+ @node = Chef::Node.new
+ @node.name "latte"
+ @provider = Chef::Provider::Template.new(@node, @resource)
+ end
+
+ it "should return a raw url if it starts with http" do
+ @provider.generate_url('http://foobar').should eql("http://foobar")
+ end
+
+ it "should return a composed url if it does not start with http" do
+ Chef::Platform.stub!(:find_platform_and_version).and_return(["monkey", "1.0"])
+ @provider.generate_url('default/something').should eql("cookbooks/daft/templates?id=default/something&platform=monkey&version=1.0")
+ end
+end \ No newline at end of file
diff --git a/spec/unit/rest_spec.rb b/spec/unit/rest_spec.rb
index fea42da6bf..efa1cff204 100644
--- a/spec/unit/rest_spec.rb
+++ b/spec/unit/rest_spec.rb
@@ -39,7 +39,7 @@ describe Chef::REST, "get_rest method" do
it "should call run_request :GET with the composed url object" do
URI.stub!(:parse).and_return(true)
r = Chef::REST.new("url")
- r.should_receive(:run_request).with(:GET, true).and_return(true)
+ r.should_receive(:run_request).with(:GET, true, false, 10, false).and_return(true)
r.get_rest("monkey")
end
end
@@ -115,11 +115,13 @@ describe Chef::REST, "run_request method" do
@request_mock.stub!(:method).and_return(true)
@request_mock.stub!(:path).and_return(true)
@http_mock.stub!(:request).and_return(@http_response_mock)
+ @tf_mock = mock(Tempfile, { :puts => true, :close => true })
+ Tempfile.stub!(:new).with("chef-rest").and_return(@tf_mock)
end
- def do_run_request(method=:GET, data=false, limit=10)
+ def do_run_request(method=:GET, data=false, limit=10, raw=false)
Net::HTTP.stub!(:new).and_return(@http_mock)
- @r.run_request(method, @url_mock, data, limit)
+ @r.run_request(method, @url_mock, data, limit, raw)
end
it "should raise an exception if the redirect limit is 0" do
@@ -203,4 +205,25 @@ describe Chef::REST, "run_request method" do
@http_response_mock.should_receive(:error!)
do_run_request
end
+
+ it "should build a new HTTP GET request without the application/json accept header for raw reqs" do
+ Net::HTTP::Get.should_receive(:new).with("/?foo=bar", {}).and_return(@request_mock)
+ do_run_request(:GET, false, 10, true)
+ end
+
+ it "should create a tempfile for the output of a raw request" do
+ Tempfile.should_receive(:new).with("chef-rest").and_return(@tf_mock)
+ do_run_request(:GET, false, 10, true).should eql(@tf_mock)
+ end
+
+ it "should populate the tempfile with the value of the raw request" do
+ @tf_mock.should_receive(:puts, "ninja").once.and_return(true)
+ do_run_request(:GET, false, 10, true)
+ end
+
+ it "should close the tempfile if we're doing a raw request" do
+ @tf_mock.should_receive(:close).once.and_return(true)
+ do_run_request(:GET, false, 10, true)
+ end
+
end