~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to lib/puppet/file_serving/content.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mto: (3.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080726154345-1fmgo76b4l72ulvc
ImportĀ upstreamĀ versionĀ 0.24.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
#  Created by Luke Kanies on 2007-10-16.
 
3
#  Copyright (c) 2007. All rights reserved.
 
4
 
 
5
require 'puppet/indirector'
 
6
require 'puppet/file_serving'
 
7
require 'puppet/file_serving/file_base'
 
8
require 'puppet/file_serving/indirection_hooks'
 
9
 
 
10
# A class that handles retrieving file contents.
 
11
# It only reads the file when its content is specifically
 
12
# asked for.
 
13
class Puppet::FileServing::Content < Puppet::FileServing::FileBase
 
14
    extend Puppet::Indirector
 
15
    indirects :file_content, :extend => Puppet::FileServing::IndirectionHooks
 
16
 
 
17
    attr_reader :path
 
18
 
 
19
    # Read the content of our file in.
 
20
    def content
 
21
        # This stat can raise an exception, too.
 
22
        raise(ArgumentError, "Cannot read the contents of links unless following links") if stat().ftype == "symlink" 
 
23
 
 
24
        ::File.read(full_path())
 
25
    end
 
26
 
 
27
    # Just return the file contents as the yaml.  This allows us to
 
28
    # avoid escaping or any such thing.  LAK:NOTE Not really sure how
 
29
    # this will behave if the file contains yaml...  I think the far
 
30
    # side needs to understand that it's a plain string.
 
31
    def to_yaml
 
32
        content
 
33
    end
 
34
end