Class: PEClient::Resource::PuppetDB::AdminV1::Archive

Inherits:
Base
  • Object
show all
Defined in:
lib/pe_client/resources/puppet_db/admin.v1/archive.rb

Overview

The archive endpoint can be used for importing and exporting PuppetDB archives.

Constant Summary collapse

BASE_PATH =

The base path for PuppetDB Admin v1 Archive endpoints.

"#{AdminV1::BASE_PATH}/archive".freeze

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

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

Instance Method Details

#export(path:, anonymization_profile: nil) ⇒ String

This endpoint can be used to stream a tarred, gzipped backup archive of PuppetDB to your local machine.

Parameters:

  • path (String)

    The local file path where the archive will be saved.

  • anonymization_profile (String) (defaults to: nil)

    The level of anonymization applied to the archive files.

Returns:

  • (String)

    The tarred, gzipped backup archive of PuppetDB.

See Also:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pe_client/resources/puppet_db/admin.v1/archive.rb', line 52

def export(path:, anonymization_profile: nil)
  response = nil
  File.open(path, "wb") do |file|
    # Using the Connection object directly to stream the response to a file.
    response = @client.connection.get BASE_PATH, {anonymization_profile:}.compact, {Accept: "application/octet-stream"} do |req|
      req.options.on_data = proc do |chunk, _overall_received_bytes|
        file.write(chunk)
      end
    end
  end
  @client.handle_response response, headers_only: true

  path
end

#import(archive:) ⇒ Hash

This endpoint can be used for streaming a PuppetDB archive into PuppetDB.

Parameters:

  • archive (String)

    The archive file to import to the PuppetDB. This should be a path to the local file. This archive must have a file called puppetdb-bak/metadata.json as the first entry in the tarfile with a key command_versions which is a JSON object mapping PuppetDB command names to their version.

Returns:

  • (Hash)

See Also:



39
40
41
42
# File 'lib/pe_client/resources/puppet_db/admin.v1/archive.rb', line 39

def import(archive:)
  @client.post BASE_PATH,
    body: {archive: Faraday::Multipart::FilePart.new(archive, "application/octet-stream", File.basename(archive))}
end