Class: Puppet::HTTP::Service::FileServer Private

Inherits:
Puppet::HTTP::Service show all
Defined in:
lib/puppet/http/service/file_server.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The FileServer service is used to retrieve file metadata and content

Constant Summary collapse

API =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns Default API for the FileServer service.

Returns:

  • (String)

    Default API for the FileServer service

'/puppet/v3'.freeze
PATH_REGEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Returns RegEx used to determine if a path contains a leading slash.

Returns:

  • (RegEx)

    RegEx used to determine if a path contains a leading slash

/^\//

Constants inherited from Puppet::HTTP::Service

EXCLUDED_FORMATS, SERVICE_NAMES

Instance Attribute Summary

Attributes inherited from Puppet::HTTP::Service

#url

Instance Method Summary collapse

Methods inherited from Puppet::HTTP::Service

#connect, create_service, valid_name?, #with_base_url

Constructor Details

#initialize(client, session, server, port) ⇒ FileServer

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FileServer.

Parameters:

  • client (Puppet::HTTP::Client)
  • session (Puppet::HTTP::Session)
  • server (String)

    (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.

  • port (Integer)

    (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.



29
30
31
32
# File 'lib/puppet/http/service/file_server.rb', line 29

def initialize(client, session, server, port)
  url = build_url(API, server || Puppet[:server], port || Puppet[:masterport])
  super(client, session, url)
end

Instance Method Details

#get_file_content(path:, environment:) {|Sting| ... } ⇒ Puppet::HTTP::Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • path (String)

    path to the file to retrieve data from

  • environment (String)

    the name of the environment we are operating in

Yields:

  • (Sting)

    Yields the body of the response returned from the server

Returns:



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/puppet/http/service/file_server.rb', line 145

def get_file_content(path:, environment:, &block)
  validate_path(path)

  headers = add_puppet_headers('Accept' => 'application/octet-stream')
  response = @client.get(
    with_base_url("/file_content#{path}"),
    headers: headers,
    params: {
      environment: environment
    }
  ) do |res|
    if res.success?
      res.read_body(&block)
    end
  end

  process_response(response)

  response
end

#get_file_metadata(path:, environment:, links: :manage, checksum_type: Puppet[:digest_algorithm], source_permissions: :ignore) ⇒ Array<Puppet::HTTP::Response, Puppet::FileServing::Metadata>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • path (String)

    path to the file to retrieve data from

  • environment (String)

    the name of the environment we are operating in

  • links (Symbol) (defaults to: :manage)

    Can be one of either ‘:follow` or `:manage`, defines how links are handled.

  • checksum_type (String) (defaults to: Puppet[:digest_algorithm])

    The digest algorithm used to verify the file. Currently if fips is enabled, this defaults to ‘sha256`. Otherwise, it defaults to `md5`.

  • source_permissions (Symbol) (defaults to: :ignore)

    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.

Returns:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/puppet/http/service/file_server.rb', line 56

def (path:, environment:, links: :manage, checksum_type: Puppet[:digest_algorithm], source_permissions: :ignore)
  validate_path(path)

  headers = add_puppet_headers('Accept' => get_mime_types(Puppet::FileServing::Metadata).join(', '))

  response = @client.get(
    with_base_url("/file_metadata#{path}"),
    headers: headers,
    params: {
      links: links,
      checksum_type: checksum_type,
      source_permissions: source_permissions,
      environment: environment
    }
  )

  process_response(response)

  [response, deserialize(response, Puppet::FileServing::Metadata)]
end

#get_file_metadatas(path: nil, environment:, recurse: :false, recurselimit: nil, ignore: nil, links: :manage, checksum_type: , source_permissions: :ignore) ⇒ Array<Puppet::HTTP::Response, Array<Puppet::FileServing::Metadata>>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

  • path (String) (defaults to: nil)

    path to the file(s) to retrieve data from

  • environment (String)

    the name of the environment we are operating in

  • recurse (Symbol) (defaults to: :false)

    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.

  • recurselimit (Integer) (defaults to: nil)

    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.

  • ignore (Array<String>) (defaults to: nil)

    An optional array of files to ignore, ie ‘[’CVS’, ‘.git’, ‘.hg’]‘

  • links (Symbol) (defaults to: :manage)

    Can be one of either ‘:follow` or `:manage`, defines how links are handled.

  • checksum_type (String) (defaults to: )

    The digest algorithm used to verify the file. Currently if fips is enabled, this defaults to ‘sha256`. Otherwise, it’s ‘md5`.

  • source_permissions (Symbol) (defaults to: :ignore)

    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.

Returns:



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/puppet/http/service/file_server.rb', line 109

def get_file_metadatas(path: nil, environment:, recurse: :false, recurselimit: nil, ignore: nil, links: :manage, checksum_type: Puppet[:digest_algorithm], source_permissions: :ignore)
  validate_path(path)

  headers = add_puppet_headers('Accept' => get_mime_types(Puppet::FileServing::Metadata).join(', '))

  response = @client.get(
    with_base_url("/file_metadatas#{path}"),
    headers: headers,
    params: {
      recurse: recurse,
      recurselimit: recurselimit,
      ignore: ignore,
      links: links,
      checksum_type: checksum_type,
      source_permissions: source_permissions,
      environment: environment,
    }
  )

  process_response(response)

  [response, deserialize_multiple(response, Puppet::FileServing::Metadata)]
end

#get_static_file_content(path:, environment:, code_id:) {|String| ... } ⇒ Puppet::HTTP::Response

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Submit a GET request to

Parameters:

  • path (String)

    path to the file to retrieve data from

  • environment (String)

    the name of the environment we are operating in

  • code_id (String)

    Defines the version of the resource to return

Yields:

  • (String)

    Yields the body of the response returned

Returns:



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/puppet/http/service/file_server.rb', line 179

def get_static_file_content(path:, environment:, code_id:, &block)
  validate_path(path)

  headers = add_puppet_headers('Accept' => 'application/octet-stream')
  response = @client.get(
    with_base_url("/static_file_content#{path}"),
    headers: headers,
    params: {
      environment: environment,
      code_id: code_id,
    }
  ) do |res|
    if res.success?
      res.read_body(&block)
    end
  end

  process_response(response)

  response
end