util

package
v0.0.0-...-938d447 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StatusWrap

func StatusWrap(err error, msg string) error

StatusWrap prepends a string to the message of an existing error.

func StatusWrapWithCode

func StatusWrapWithCode(err error, code codes.Code, msg string) error

StatusWrapWithCode prepends a string to the message of an existing error, while replacing the error code.

func StatusWrapf

func StatusWrapf(err error, format string, args ...interface{}) error

StatusWrapf prepends a formatted string to the message of an existing error.

func StatusWrapfWithCode

func StatusWrapfWithCode(err error, code codes.Code, format string, args ...interface{}) error

StatusWrapfWithCode prepends a formatted string to the message of an existing error, while replacing the error code.

func UnmarshalConfigurationFromFile

func UnmarshalConfigurationFromFile(path string, configuration proto.Message) error

UnmarshalConfigurationFromFile reads a jsonnet file, renders it, unmarshal the output into a protobuf configuration message.

Types

type Digest

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

Digest holds the identification of an object stored in the Content Addressable Storage (CAS) or Action Cache (AC). The use of this object is preferred over remoteexecution.Digest for a couple of reasons.

  • Instances of these objects are guaranteed not to contain any degenerate values. The hash has already been decoded from hexadecimal to binary. The size is non-negative.
  • They keep track of the instance as part of the digest, which allows us to keep function signatures across the codebase simple.
  • They provide utility functions for deriving new digests from them. This ensures that outputs of build actions automatically use the same instance name and hashing algorithm.

func MustNewDigest

func MustNewDigest(instance string, partialDigest *remoteexecution.Digest) *Digest

MustNewDigest constructs a Digest similar to NewDigest, but never returns an error. Instead, execution will abort if the resulting instance would be degenerate. Useful for unit testing.

func NewDigest

func NewDigest(instance string, partialDigest *remoteexecution.Digest) (*Digest, error)

NewDigest constructs a Digest object from an instance name and a protocol-level digest object. The instance returned by this function is guaranteed to be non-degenerate.

func NewDigestFromBytestreamPath

func NewDigestFromBytestreamPath(path string) (*Digest, error)

NewDigestFromBytestreamPath creates a Digest from a string having one of the following two formats:

- blobs/${hash}/${size} - ${instance}/blobs/${hash}/${size}

This notation is used by Bazel to refer to files accessible through a gRPC Bytestream service.

func (*Digest) GetHashBytes

func (d *Digest) GetHashBytes() []byte

GetHashBytes returns the hash of the object as a slice of bytes.

func (*Digest) GetHashString

func (d *Digest) GetHashString() string

GetHashString returns the hash of the object as a string.

func (*Digest) GetInstance

func (d *Digest) GetInstance() string

GetInstance returns the instance name of the object.

func (*Digest) GetKey

func (d *Digest) GetKey(format DigestKeyFormat) string

GetKey generates a string representation of the digest object that may be used as keys in hash tables.

func (*Digest) GetPartialDigest

func (d *Digest) GetPartialDigest() *remoteexecution.Digest

GetPartialDigest encodes the digest into the format used by the remote execution protocol, so that it may be stored in messages returned to the client.

func (*Digest) GetSizeBytes

func (d *Digest) GetSizeBytes() int64

GetSizeBytes returns the size of the object, in bytes.

func (*Digest) NewDerivedDigest

func (d *Digest) NewDerivedDigest(partialDigest *remoteexecution.Digest) (*Digest, error)

NewDerivedDigest creates a Digest object that uses the same instance name as the one from which it is derived. This can be used to refer to inputs (command, directories, files) of an action.

func (*Digest) NewDigestGenerator

func (d *Digest) NewDigestGenerator() *DigestGenerator

NewDigestGenerator creates a writer that may be used to compute digests of newly created files.

func (*Digest) NewHasher

func (d *Digest) NewHasher() hash.Hash

NewHasher creates a standard hash.Hash object that may be used to compute a checksum of data. The hash.Hash object uses the same algorithm as the one that was used to create the digest, making it possible to validate data against a digest.

func (*Digest) String

func (d *Digest) String() string

type DigestGenerator

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

DigestGenerator is a writer that may be used to compute digests of newly created files.

func (*DigestGenerator) Sum

func (dg *DigestGenerator) Sum() *Digest

Sum creates a new digest based on the data written into the DigestGenerator.

func (*DigestGenerator) Write

func (dg *DigestGenerator) Write(p []byte) (int, error)

Write a chunk of data from a newly created file into the state of the DigestGenerator.

type DigestKeyFormat

type DigestKeyFormat int

DigestKeyFormat is an enumeration type that determines the format of object keys returned by Digest.GetKey().

const (
	// DigestKeyWithoutInstance lets Digest.GetKey() return a key
	// that does not include the name of the instance; only the hash
	// and the size.
	DigestKeyWithoutInstance DigestKeyFormat = iota
	// DigestKeyWithInstance lets Digest.GetKey() return a key
	// that includes the hash, size and instance name.
	DigestKeyWithInstance
)

Jump to

Keyboard shortcuts

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