class Puppet::HTTP::Service::FileServer

The FileServer service is used to retrieve file metadata and content.

@api public

Constants

API

@return [String] Default API for the FileServer service

PATH_REGEX

@return [RegEx] RegEx used to determine if a path contains a leading slash

Public Class Methods

new(client, session, server, port) click to toggle source

Use `Puppet::HTTP::Session.route_to(:fileserver)` to create or get an instance of this class.

@param [Puppet::HTTP::Client] client @param [Puppet::HTTP::Session] session @param [String] server (`Puppet`) If an explicit server is given,

create a service using that server. If server is nil, the default value
is used to create the service.

@param [Integer] port (`Puppet`) If an explicit port is given, create

a service using that port. If port is nil, the default value is used to
create the service.
Calls superclass method Puppet::HTTP::Service::new
   # File lib/puppet/http/service/file_server.rb
25 def initialize(client, session, server, port)
26   url = build_url(API, server || Puppet[:server], port || Puppet[:serverport])
27   super(client, session, url)
28 end

Public Instance Methods

get_file_content(path:, environment:, &block) click to toggle source

Submit a GET request to the server to retrieve content of a file.

@param [String] path path to the file to retrieve data from @param [String] environment the name of the environment we are operating in

@yield [Sting] Yields the body of the response returned from the server

@return [Puppet::HTTP::Response] The request response

@api public

    # File lib/puppet/http/service/file_server.rb
137 def get_file_content(path:, environment:, &block)
138   validate_path(path)
139 
140   headers = add_puppet_headers('Accept' => 'application/octet-stream')
141   response = @client.get(
142     with_base_url("/file_content#{path}"),
143     headers: headers,
144     params: {
145       environment: environment
146     }
147   ) do |res|
148     if res.success?
149       res.read_body(&block)
150     end
151   end
152 
153   process_response(response)
154 
155   response
156 end
get_file_metadata(path:, environment:, links: :manage, checksum_type: Puppet[:digest_algorithm], source_permissions: :ignore) click to toggle source

Submit a GET request to the server to retrieve the metadata for a specified file.

@param [String] path path to the file to retrieve data from @param [String] environment the name of the environment we are operating in @param [Symbol] links Can be one of either `:follow` or `:manage`, defines

how links are handled.

@param [String] checksum_type The digest algorithm used to verify the file.

Defaults to `sha256`.

@param [Symbol] source_permissions Can be one of `:use`, `:use_when_creating`,

or `:ignore`. This parameter tells the server if it should include the
file permissions in the response. If set to `:ignore`, the server will
return default permissions.

@return [Array<Puppet::HTTP::Response, Puppet::FileServing::Metadata>] An

array with the request response and the deserialized metadata for the
file returned from the server

@api public

   # File lib/puppet/http/service/file_server.rb
49 def get_file_metadata(path:, environment:, links: :manage, checksum_type: Puppet[:digest_algorithm], source_permissions: :ignore)
50   validate_path(path)
51 
52   headers = add_puppet_headers('Accept' => get_mime_types(Puppet::FileServing::Metadata).join(', '))
53 
54   response = @client.get(
55     with_base_url("/file_metadata#{path}"),
56     headers: headers,
57     params: {
58       links: links,
59       checksum_type: checksum_type,
60       source_permissions: source_permissions,
61       environment: environment
62     }
63   )
64 
65   process_response(response)
66 
67   [response, deserialize(response, Puppet::FileServing::Metadata)]
68 end
get_file_metadatas(path: nil, environment:, recurse: :false, recurselimit: nil, max_files: nil, ignore: nil, links: :manage, checksum_type: Puppet[:digest_algorithm], source_permissions: :ignore) click to toggle source

Submit a GET request to the server to retrieve the metadata for multiple files

@param [String] path path to the file(s) to retrieve data from @param [String] environment the name of the environment we are operating in @param [Symbol] recurse Can be `:true`, `:false`, or `:remote`. Defines if

we recursively return the contents of the directory. Used in conjunction
with `:recurselimit`. See the reference documentation for the file type
for more details.

@param [Integer] recurselimit When `recurse` is set, `recurselimit` defines

how far Puppet should descend into subdirectories. `0` is effectively the
same as `recurse => false`, `1` will return files and directories directly
inside the defined directory, `2` will return the direct content of the
directory as well as the contents of the _first_ level of subdirectories.
The pattern continues for each incremental value. See the reference
documentation for the file type for more details.

@param [Array<String>] ignore An optional array of files to ignore, ie `['CVS', '.git', '.hg']` @param [Symbol] links Can be one of either `:follow` or `:manage`, defines

how links are handled.

@param [String] checksum_type The digest algorithm used to verify the file.

Currently if fips is enabled, this defaults to `sha256`. Otherwise, it's `md5`.

@param [Symbol] source_permissions Can be one of `:use`, `:use_when_creating`,

or `:ignore`. This parameter tells the server if it should include the
file permissions in the report. If set to `:ignore`, the server will return
default permissions.

@return [Array<Puppet::HTTP::Response, Array<Puppet::FileServing::Metadata>>]

An array with the request response and an array of the deserialized
metadata for each file returned from the server

@api public

    # File lib/puppet/http/service/file_server.rb
101 def get_file_metadatas(path: nil, environment:, recurse: :false, recurselimit: nil, max_files: nil, ignore: nil, links: :manage, checksum_type: Puppet[:digest_algorithm], source_permissions: :ignore)
102   validate_path(path)
103 
104   headers = add_puppet_headers('Accept' => get_mime_types(Puppet::FileServing::Metadata).join(', '))
105 
106   response = @client.get(
107     with_base_url("/file_metadatas#{path}"),
108     headers: headers,
109     params: {
110       recurse: recurse,
111       recurselimit: recurselimit,
112       max_files: max_files,
113       ignore: ignore,
114       links: links,
115       checksum_type: checksum_type,
116       source_permissions: source_permissions,
117       environment: environment,
118     }
119   )
120 
121   process_response(response)
122 
123   [response, deserialize_multiple(response, Puppet::FileServing::Metadata)]
124 end
get_static_file_content(path:, environment:, code_id:, &block) click to toggle source

Submit a GET request to retrieve file content using the `static_file_content` API uniquely identified by (`code_id`, `environment`, `path`).

@param [String] path path to the file to retrieve data from @param [String] environment the name of the environment we are operating in @param [String] code_id Defines the version of the resource to return

@yield [String] Yields the body of the response returned

@return [Puppet::HTTP::Response] The request response

@api public

    # File lib/puppet/http/service/file_server.rb
171 def get_static_file_content(path:, environment:, code_id:, &block)
172   validate_path(path)
173 
174   headers = add_puppet_headers('Accept' => 'application/octet-stream')
175   response = @client.get(
176     with_base_url("/static_file_content#{path}"),
177     headers: headers,
178     params: {
179       environment: environment,
180       code_id: code_id,
181     }
182   ) do |res|
183     if res.success?
184       res.read_body(&block)
185     end
186   end
187 
188   process_response(response)
189 
190   response
191 end

Private Instance Methods

validate_path(path) click to toggle source
    # File lib/puppet/http/service/file_server.rb
195 def validate_path(path)
196   raise ArgumentError, "Path must start with a slash" unless path =~ PATH_REGEX
197 end