diff options
author | Adam Jacob <adam@hjksolutions.com> | 2008-07-28 17:57:49 -0700 |
---|---|---|
committer | Adam Jacob <adam@hjksolutions.com> | 2008-07-28 17:57:49 -0700 |
commit | 8d4c3be22c5dbb030e96bcbac12679de7a09b0fe (patch) | |
tree | 6fd5282dccb98e63ce8fae5277e7cadf8acc204a /lib/chef/provider/template.rb | |
parent | d734c714c1e7598ddba40b47c26d10f002e06420 (diff) | |
download | chef-8d4c3be22c5dbb030e96bcbac12679de7a09b0fe.tar.gz |
Updating search tickets
Diffstat (limited to 'lib/chef/provider/template.rb')
-rw-r--r-- | lib/chef/provider/template.rb | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/chef/provider/template.rb b/lib/chef/provider/template.rb new file mode 100644 index 0000000000..47ffc810bf --- /dev/null +++ b/lib/chef/provider/template.rb @@ -0,0 +1,69 @@ +# +# 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. +# +# 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 +# + +require File.join(File.dirname(__FILE__), "file") +require 'uri' + +class Chef + class Provider + class Template < Chef::Provider::File + + def action_create + r = Chef::REST.new(Chef::Config[:template_url]) + template_url = nil + if @new_resource.template =~ /^http/ + template_url = @new_resource.template + else + template_url = "cookbooks/#{@new_resource.cookbook_name}/templates/#{@new_resource.template}" + 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 + 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 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 + + end + end +end
\ No newline at end of file |