Class: PEClient::Resource::PuppetV3::FileBucket

Inherits:
Base
  • Object
show all
Defined in:
lib/pe_client/resources/puppet.v3/file_bucket.rb

Overview

Manages the contents of files in the file bucket. All access to files is managed with the md5 checksum of the file contents, represented as :md5. Where used, :filename means the full absolute path of the file on the client system. This is usually optional and used as an error check to make sure correct file is retrieved. The environment is required in all requests but ignored, as the file bucket does not distinguish between environments.

Constant Summary collapse

BASE_PATH =

The base path for Puppet API v3 File Bucket endpoints.

"#{PuppetV3::BASE_PATH}/file_bucket_file".freeze
HEADERS =

Common headers for file bucket requests

{"Content-Type": "application/octet-stream", Accept: "application/octet-stream"}.freeze

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from PEClient::Resource::Base

Instance Method Details

#get(md5:, environment:, filename: nil) ⇒ String

Retrieve the contents of a file.

Parameters:

  • md5 (String)

    The MD5 checksum of the file.

  • environment (String)

    Required but ignored.

  • filename (String) (defaults to: nil)

    The full absolute path of the file on the client system.

Returns:

  • (String)


43
44
45
# File 'lib/pe_client/resources/puppet.v3/file_bucket.rb', line 43

def get(md5:, environment:, filename: nil)
  @client.get path(md5, filename), params: {environment:}, headers: HEADERS
end

#head(md5:, environment:, filename: nil) ⇒ Hash

Check if a file is present in the filebucket This behaves identically to #get, only returning headers.

Parameters:

  • md5 (String)

    The MD5 checksum of the file.

  • environment (String)

    Required but ignored.

  • filename (String) (defaults to: nil)

    The full absolute path of the file on the client system.

Returns:

  • (Hash)


55
56
57
# File 'lib/pe_client/resources/puppet.v3/file_bucket.rb', line 55

def head(md5:, environment:, filename: nil)
  @client.head path(md5, filename), params: {environment:}, headers: HEADERS
end

#save(md5:, file:, environment:, filename: nil) ⇒ String

Save a file to the filebucket The body should contain the file contents. This saves the file using the md5 sum of the file contents. If :filename is provided, it adds the path to a list for the given file. If the md5 sum in the request is incorrect, the file will be instead saved under the correct checksum.

Parameters:

  • md5 (String)

    The MD5 checksum of the file.

  • file (String)

    The contents of the file to save.

  • environment (String)

    Required but ignored.

  • filename (String) (defaults to: nil)

    The full absolute path of the file on the client system

Returns:

  • (String)


70
71
72
# File 'lib/pe_client/resources/puppet.v3/file_bucket.rb', line 70

def save(md5:, file:, environment:, filename: nil)
  @client.put path(md5, filename), body: file, params: {environment:}, headers: HEADERS
end