Back to

Package isolated

Latest Go to latest

The latest major version is .

Published: Aug 1, 2020 | License: Apache-2.0 | Module:


Package isolated defines the isolated common code shared by the client and server.



const IsolatedFormatVersion = "1.4"

IsolatedFormatVersion is version of *.isolated file format. Put into JSON.

func GetCompressor

func GetCompressor(namespace string, out io.Writer) (io.WriteCloser, error)

GetCompressor returns a fresh instance of the compression algorithm.

It must be closed after use.

It is currently hardcoded to RFC 1950 (zlib).

func GetDecompressor

func GetDecompressor(namespace string, in io.Reader) (io.ReadCloser, error)

GetDecompressor returns a fresh instance of the decompression algorithm.

It must be closed after use.

It is currently hardcoded to RFC 1950 (zlib).

func GetHash

func GetHash(namespace string) crypto.Hash

GetHash returns a fresh instance of the hashing algorithm to be used to calculate the HexDigest.

A prefix of "sha256-" and "sha512-" respectively returns a sha-256 and sha-512 instance. Otherwise a sha-1 instance is returned.

func HashFile

func HashFile(h crypto.Hash, path string) (isolateservice.HandlersEndpointsV1Digest, error)

HashFile hashes a file and returns a HandlersEndpointsV1Digest out of it.

func Pack

func Pack(values []int64) ([]byte, error)

Pack returns a deflate'd buffer of delta encoded varints.

func Unpack

func Unpack(data []byte) ([]int64, error)

Unpack decompresses a deflate'd delta encoded list of varints.

type File

type File struct {
	Digest HexDigest `json:"h,omitempty"`
	Link   *string   `json:"l,omitempty"`
	Mode   *int      `json:"m,omitempty"`
	Size   *int64    `json:"s,omitempty"`
	Type   FileType  `json:"t,omitempty"`

File describes a single file referenced by content in a .isolated file.

For regular files, the Digest, Mode, and Size fields should be set, and the Type field should be set for non-basic files. For symbolic links, only the Link field should be set.

func BasicFile

func BasicFile(d HexDigest, mode int, size int64) File

BasicFile returns a File populated for a basic file.

func SymLink(link string) File

SymLink returns a File populated for a symbolic link.

func TarFile

func TarFile(d HexDigest, size int64) File

TarFile returns a file populated for a tar archive file.

type FileType

type FileType string

FileType describes the type of file being isolated.

const (
	// Basic represents normal files. It is the default type.
	Basic FileType = "basic"

	// ArArchive represents an ar archive containing a large number of small files.
	ArArchive FileType = "ar"

	// TarArchive represents a tar archive containing a large number of small files.
	TarArchive FileType = "tar"

type HexDigest

type HexDigest string

HexDigest is the hash of a file that is hex-encoded. Only lower case letters are accepted.

func Hash

func Hash(h crypto.Hash, src io.Reader) (HexDigest, error)

Hash hashes a reader and returns a HexDigest from it.

func HashBytes

func HashBytes(h crypto.Hash, content []byte) HexDigest

HashBytes hashes content and returns a HexDigest from it.

func Sum

func Sum(h hash.Hash) HexDigest

Sum is a shortcut to get a HexDigest from a hash.Hash.

func (HexDigest) Validate

func (d HexDigest) Validate(h crypto.Hash) bool

Validate returns true if the hash is valid.

type HexDigests

type HexDigests []HexDigest

HexDigests is a slice of HexDigest that implements sort.Interface.

func (HexDigests) Len

func (h HexDigests) Len() int

func (HexDigests) Less

func (h HexDigests) Less(i, j int) bool

func (HexDigests) Swap

func (h HexDigests) Swap(i, j int)

type Isolated

type Isolated struct {
	Algo        string          `json:"algo"` // Must be "sha-1"
	Command     []string        `json:"command,omitempty"`
	Files       map[string]File `json:"files,omitempty"`
	Includes    HexDigests      `json:"includes,omitempty"`
	ReadOnly    *ReadOnlyValue  `json:"read_only,omitempty"`
	RelativeCwd string          `json:"relative_cwd,omitempty"`
	Version     string          `json:"version"`

Isolated is the data from a JSON serialized .isolated file.

func New

func New(h crypto.Hash) *Isolated

New returns a new Isolated with the default Algo and Version.

type ReadOnlyValue

type ReadOnlyValue int

ReadOnlyValue defines permissions on isolated files.

const (
	// Writable means that both files and directories are writeable. This should
	// not be used.
	Writable ReadOnlyValue = 0
	// FilesReadOnly means that files are read only but directories are
	// writeable. This permits the process executed to create temporary files in
	// the current directory. This is the recommended value and this is the
	// default value.
	FilesReadOnly ReadOnlyValue = 1
	// DirsReadOnly means that both files and directories are read-only. This
	// enforces strict no-junk policy that the process cannot create files in the
	// temporary mapped directory.
	DirsReadOnly ReadOnlyValue = 2

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier