class Puppet::HTTP::Service::FileServer
The FileServer service is used to retrieve file metadata and content.
@api public
Constants
- API
@return [String] Default
APIfor theFileServerservice- PATH_REGEX
@return [RegEx] RegEx used to determine if a path contains a leading slash
Public Class Methods
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.
Puppet::HTTP::Service::new
# File lib/puppet/http/service/file_server.rb 26 def initialize(client, session, server, port) 27 url = build_url(API, server || Puppet[:server], port || Puppet[:serverport]) 28 super(client, session, url) 29 end
Public Instance Methods
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 138 def get_file_content(path:, environment:, &block) 139 validate_path(path) 140 141 headers = add_puppet_headers('Accept' => 'application/octet-stream') 142 response = @client.get( 143 with_base_url("/file_content#{path}"), 144 headers: headers, 145 params: { 146 environment: environment 147 } 148 ) do |res| 149 if res.success? 150 res.read_body(&block) 151 end 152 end 153 154 process_response(response) 155 156 response 157 end
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 50 def get_file_metadata(path:, environment:, links: :manage, checksum_type: Puppet[:digest_algorithm], source_permissions: :ignore) 51 validate_path(path) 52 53 headers = add_puppet_headers('Accept' => get_mime_types(Puppet::FileServing::Metadata).join(', ')) 54 55 response = @client.get( 56 with_base_url("/file_metadata#{path}"), 57 headers: headers, 58 params: { 59 links: links, 60 checksum_type: checksum_type, 61 source_permissions: source_permissions, 62 environment: environment 63 } 64 ) 65 66 process_response(response) 67 68 [response, deserialize(response, Puppet::FileServing::Metadata)] 69 end
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 102 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) 103 validate_path(path) 104 105 headers = add_puppet_headers('Accept' => get_mime_types(Puppet::FileServing::Metadata).join(', ')) 106 107 response = @client.get( 108 with_base_url("/file_metadatas#{path}"), 109 headers: headers, 110 params: { 111 recurse: recurse, 112 recurselimit: recurselimit, 113 max_files: max_files, 114 ignore: ignore, 115 links: links, 116 checksum_type: checksum_type, 117 source_permissions: source_permissions, 118 environment: environment, 119 } 120 ) 121 122 process_response(response) 123 124 [response, deserialize_multiple(response, Puppet::FileServing::Metadata)] 125 end
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 172 def get_static_file_content(path:, environment:, code_id:, &block) 173 validate_path(path) 174 175 headers = add_puppet_headers('Accept' => 'application/octet-stream') 176 response = @client.get( 177 with_base_url("/static_file_content#{path}"), 178 headers: headers, 179 params: { 180 environment: environment, 181 code_id: code_id, 182 } 183 ) do |res| 184 if res.success? 185 res.read_body(&block) 186 end 187 end 188 189 process_response(response) 190 191 response 192 end
Private Instance Methods
# File lib/puppet/http/service/file_server.rb 196 def validate_path(path) 197 raise ArgumentError, "Path must start with a slash" unless path =~ PATH_REGEX 198 end