slug

package module
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2024 License: MPL-2.0 Imports: 9 Imported by: 19

README

go-slug

Build Status GitHub license GoDoc Go Report Card GitHub issues

Package go-slug offers functions for packing and unpacking Terraform Enterprise compatible slugs. Slugs are gzip compressed tar files containing Terraform configuration files.

Installation

Installation can be done with a normal go get:

go get -u github.com/hashicorp/go-slug

Documentation

For the complete usage of go-slug, see the full package docs.

Example

Packing or unpacking a slug is pretty straight forward as shown in the following example:

package main

import (
	"bytes"
	"io/ioutil"
	"log"
	"os"

	slug "github.com/hashicorp/go-slug"
)

func main() {
	// First create a buffer for storing the slug.
	buf := bytes.NewBuffer(nil)

	// Then call the Pack function with a directory path containing the
	// configuration files and an io.Writer to write the slug to.
	if _, err := slug.Pack("testdata/archive-dir", buf, false); err != nil {
		log.Fatal(err)
	}

	// Create a directory to unpack the slug contents into.
	dst, err := ioutil.TempDir("", "slug")
	if err != nil {
		log.Fatal(err)
	}
	defer os.RemoveAll(dst)

	// Unpacking a slug is done by calling the Unpack function with an
	// io.Reader to read the slug from and a directory path of an existing
	// directory to store the unpacked configuration files.
	if err := slug.Unpack(buf, dst); err != nil {
		log.Fatal(err)
	}
}

Issues and Contributing

If you find an issue with this package, please report an issue. If you'd like, we welcome any contributions. Fork this repository and submit a pull request.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Unpack

func Unpack(r io.Reader, dst string) error

Unpack is used to read and extract the contents of a slug to the dst directory, which must be an absolute path. Symlinks within the slug are supported, provided their targets are relative and point to paths within the destination directory.

Types

type IllegalSlugError added in v0.6.0

type IllegalSlugError struct {
	Err error
}

IllegalSlugError indicates the provided slug (io.Writer for Pack, io.Reader for Unpack) violates a rule about its contents. For example, an absolute or external symlink. It implements the error interface.

func (*IllegalSlugError) Error added in v0.6.0

func (e *IllegalSlugError) Error() string

func (*IllegalSlugError) Unwrap added in v0.6.0

func (e *IllegalSlugError) Unwrap() error

Unwrap returns the underlying issue with the provided Slug into the error chain.

type Meta

type Meta struct {
	// The list of files contained in the slug.
	Files []string

	// Total size of the slug in bytes.
	Size int64
}

Meta provides detailed information about a slug.

func Pack

func Pack(src string, w io.Writer, dereference bool) (*Meta, error)

Pack at the package level is used to maintain compatibility with existing code that relies on this function signature. New options related to packing slugs should be added to the Packer struct instead.

type Packer added in v0.7.0

type Packer struct {
	// contains filtered or unexported fields
}

Packer holds options for the Pack function.

func NewPacker added in v0.7.0

func NewPacker(options ...PackerOption) (*Packer, error)

NewPacker is a constructor for Packer.

func (*Packer) Pack added in v0.7.0

func (p *Packer) Pack(src string, w io.Writer) (*Meta, error)

Pack creates a slug from a src directory, and writes the new slug to w. Returns metadata about the slug and any errors.

When dereference is set to true, symlinks with a target outside of the src directory will be dereferenced. When dereference is set to false symlinks with a target outside the src directory are omitted from the slug.

func (*Packer) Unpack added in v0.10.0

func (p *Packer) Unpack(r io.Reader, dst string) error

Unpack unpacks the archive data in r into directory dst.

type PackerOption added in v0.7.0

type PackerOption func(*Packer) error

PackerOption is a functional option that can configure non-default Packers.

func AllowSymlinkTarget added in v0.10.0

func AllowSymlinkTarget(path string) PackerOption

AllowSymlinkTarget relaxes safety checks on symlinks with targets matching path. Specifically, absolute symlink targets (e.g. "/foo/bar") and relative targets (e.g. "../foo/bar") which resolve to a path outside of the source/destination directories for pack/unpack operations respectively, may be expressly permitted, whereas they are forbidden by default. Exercise caution when using this option. A symlink matches path if its target resolves to path exactly, or if path is a parent directory of target.

func ApplyTerraformIgnore added in v0.7.0

func ApplyTerraformIgnore() PackerOption

ApplyTerraformIgnore is a PackerOption that will apply the .terraformignore rules and skip packing files it specifies.

func DereferenceSymlinks() PackerOption

DereferenceSymlinks is a PackerOption that will allow symlinks that reference a target outside of the source directory by copying the link target, turning it into a normal file within the archive.

Directories

Path Synopsis
internal
ignorefiles
Package ignorefiles deals with the ".terraformignore" file format, which is a convention similar to ".gitignore" that specifies path patterns that match files Terraform should discard or ignore when interpreting a package fetched from a remote location.
Package ignorefiles deals with the ".terraformignore" file format, which is a convention similar to ".gitignore" that specifies path patterns that match files Terraform should discard or ignore when interpreting a package fetched from a remote location.
Package sourceaddrs deals with the various types of source code address that Terraform can gather into a source bundle via the sibling package "sourcebundle".
Package sourceaddrs deals with the various types of source code address that Terraform can gather into a source bundle via the sibling package "sourcebundle".
Package sourcebundle deals with the construction of and later consumption of "source bundles", which are in some sense "meta-slugs" that capture a variety of different source packages together into a single working directory, which can optionally be bundled up into an archive for insertion into a blob storage system.
Package sourcebundle deals with the construction of and later consumption of "source bundles", which are in some sense "meta-slugs" that capture a variety of different source packages together into a single working directory, which can optionally be bundled up into an archive for insertion into a blob storage system.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL