~ubuntu-branches/ubuntu/trusty/puppet/trusty

« back to all changes in this revision

Viewing changes to lib/puppet/type/file/source.rb

  • Committer: Package Import Robot
  • Author(s): Stig Sandbeck Mathisen
  • Date: 2011-10-22 14:08:22 UTC
  • mfrom: (1.1.25) (3.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20111022140822-odxde5lohc45yhuz
Tags: 2.7.6-1
* New upstream release (CVE-2011-3872)
* Remove cherry-picked "groupadd_aix_warning" patch
* Install all new manpages

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
      on the local host, whereas `agent` will connect to the
43
43
      puppet server that it received the manifest from.
44
44
 
45
 
      See the [fileserver configuration documentation](http://projects.puppetlabs.com/projects/puppet/wiki/File_Serving_Configuration) for information on how to configure
 
45
      See the [fileserver configuration documentation](http://docs.puppetlabs.com/guides/file_serving.html) for information on how to configure
46
46
      and use file services within Puppet.
47
47
 
48
48
      If you specify multiple file sources for a file, then the first
66
66
    validate do |sources|
67
67
      sources = [sources] unless sources.is_a?(Array)
68
68
      sources.each do |source|
 
69
        next if Puppet::Util.absolute_path?(source)
 
70
 
69
71
        begin
70
72
          uri = URI.parse(URI.escape(source))
71
73
        rescue => detail
72
74
          self.fail "Could not understand source #{source}: #{detail}"
73
75
        end
74
76
 
75
 
        self.fail "Cannot use URLs of type '#{uri.scheme}' as source for fileserving" unless uri.scheme.nil? or %w{file puppet}.include?(uri.scheme)
 
77
        self.fail "Cannot use relative URLs '#{source}'" unless uri.absolute?
 
78
        self.fail "Cannot use opaque URLs '#{source}'" unless uri.hierarchical?
 
79
        self.fail "Cannot use URLs of type '#{uri.scheme}' as source for fileserving" unless %w{file puppet}.include?(uri.scheme)
76
80
      end
77
81
    end
78
82
 
 
83
    SEPARATOR_REGEX = [Regexp.escape(File::SEPARATOR.to_s), Regexp.escape(File::ALT_SEPARATOR.to_s)].join
 
84
 
79
85
    munge do |sources|
80
86
      sources = [sources] unless sources.is_a?(Array)
81
 
      sources.collect { |source| source.sub(/\/$/, '') }
 
87
      sources.map do |source|
 
88
        source = source.sub(/[#{SEPARATOR_REGEX}]+$/, '')
 
89
 
 
90
        if Puppet::Util.absolute_path?(source)
 
91
          URI.unescape(Puppet::Util.path_to_uri(source).to_s)
 
92
        else
 
93
          source
 
94
        end
 
95
      end
82
96
    end
83
97
 
84
98
    def change_to_s(currentvalue, newvalue)
95
109
    end
96
110
 
97
111
    # Look up (if necessary) and return remote content.
98
 
    cached_attr(:content) do
 
112
    def content
 
113
      return @content if @content
99
114
      raise Puppet::DevError, "No source for content was stored with the metadata" unless metadata.source
100
115
 
101
116
      unless tmp = Puppet::FileServing::Content.indirection.find(metadata.source)
102
117
        fail "Could not find any content at %s" % metadata.source
103
118
      end
104
 
      tmp.content
 
119
      @content = tmp.content
105
120
    end
106
121
 
107
122
    # Copy the values from the source to the resource.  Yay.
137
152
      ! (metadata.nil? or metadata.ftype.nil?)
138
153
    end
139
154
 
 
155
    attr_writer :metadata
 
156
 
140
157
    # Provide, and retrieve if necessary, the metadata for this file.  Fail
141
158
    # if we can't find data about this host, and fail if there are any
142
159
    # problems in our query.
143
 
    cached_attr(:metadata) do
 
160
    def metadata
 
161
      return @metadata if @metadata
144
162
      return nil unless value
145
 
      result = nil
146
163
      value.each do |source|
147
164
        begin
148
165
          if data = Puppet::FileServing::Metadata.indirection.find(source)
149
 
            result = data
150
 
            result.source = source
 
166
            @metadata = data
 
167
            @metadata.source = source
151
168
            break
152
169
          end
153
170
        rescue => detail
154
171
          fail detail, "Could not retrieve file metadata for #{source}: #{detail}"
155
172
        end
156
173
      end
157
 
      fail "Could not retrieve information from source(s) #{value.join(", ")}" unless result
158
 
      result
 
174
      fail "Could not retrieve information from environment #{Puppet[:environment]} source(s) #{value.join(", ")}" unless @metadata
 
175
      @metadata
159
176
    end
160
177
 
161
178
    def local?
162
 
      found? and uri and (uri.scheme || "file") == "file"
 
179
      found? and scheme == "file"
163
180
    end
164
181
 
165
182
    def full_path
166
 
      URI.unescape(uri.path) if found? and uri
 
183
      Puppet::Util.uri_to_path(uri) if found?
167
184
    end
168
185
 
169
186
    def server
173
190
    def port
174
191
      (uri and uri.port) or Puppet.settings[:masterport]
175
192
    end
176
 
 
177
193
    private
178
194
 
 
195
    def scheme
 
196
      (uri and uri.scheme)
 
197
    end
 
198
 
179
199
    def uri
180
200
      @uri ||= URI.parse(URI.escape(metadata.source))
181
201
    end