Documentation
¶
Overview ¶
Package record contains the highlevel types used for tracking fingerprinted blobs. These blobs are typically stored as files, but the same content may also be present in an archive file, docker image, git repo, or some other format where the original content can be retrieved but isn't necessarily stored in the same representation a the original blob (eg, it may be compressed).
Index ¶
- type ArchiveFile
- type Distribution
- type DockerImage
- type DockerLayer
- type File
- type Fingerprint
- func (c Fingerprint) CacheID() uint64
- func (f *Fingerprint) CalculateSums(data io.Reader, size int64) error
- func (f Fingerprint) GetDigest(alg string) hash.Digest
- func (f Fingerprint) HasDigest(other hash.Digest) bool
- func (f *Fingerprint) Is(other interface{}) bool
- func (c Fingerprint) IsCached() bool
- func (f Fingerprint) SRI() string
- func (c *Fingerprint) SetCacheID(id uint64)
- func (f Fingerprint) String() string
- func (f *Fingerprint) UpdateWith(of *Fingerprint) int
- type FingerprintMatcher
- type GitRepoSource
- type SerializedArchiveFile
- type SerializedFile
- type SerializedFingerprint
- type SerializedGitRepo
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ArchiveFile ¶
type ArchiveFile struct {
File *File `yaml:",omitempty"`
Entries []*File `yaml:",omitempty"`
// contains filtered or unexported fields
}
ArchiveFile is a mapping between an archive file and all of the files it directly contains. The entries themselves may also have an associated ArchiveFile instance, but that is not tracked in this structure.
func (*ArchiveFile) SetCacheID ¶
func (c *ArchiveFile) SetCacheID(id uint64)
type Distribution ¶
Distribution is a collection of objects packaged together in some form. A Distribution is similar to an archive but does not require that an actual archive exist. An example of a distribution is all of the materials published as part of a release.
type DockerImage ¶
type DockerImage struct {
Name string
Layers []*DockerLayer
RepoDigests []string
ImageID string
// contains filtered or unexported fields
}
DockerImage is a top-level object containing multiple children. Note that it does not include a Fingerprint property. This is because Docker does not use any sort of consistent representation for its images and thus a Fingerprint can only ever map to a specific run of `docker save` which makes it very useless.
func (*DockerImage) SetCacheID ¶
func (c *DockerImage) SetCacheID(id uint64)
type DockerLayer ¶
type DockerLayer struct {
Name string
TarSum string
Files []*File
// Fingerprint here refers to a fingerprint of the tar stream that was read
// to extract the layer contents. It does not map to any canonical image or
// layer identifier because Docker does not support consistent hashing.
Fingerprint *Fingerprint
}
DockerLayer represents a docker image layer, which consists primarily of files
type File ¶
type File struct {
Path string
Fingerprint *Fingerprint `yaml:"hashes,omitempty"`
// contains filtered or unexported fields
}
File represents a fingerprinted file by mapping a Path string to a Fingerprint.
func (File) Is ¶
Is implements the FingerprintMather interface allowing a File to be compared to another object such as a Fingerprint or another File.
func (*File) SetCacheID ¶
func (c *File) SetCacheID(id uint64)
type Fingerprint ¶
type Fingerprint struct {
GitSHA hash.GitShaDigest `yaml:",omitempty"`
MD5 hash.MD5Digest `yaml:",omitempty"`
SHA1 hash.SHA1Digest `yaml:",omitempty"`
SHA256 hash.SHA256Digest `yaml:",omitempty"`
SHA384 hash.SHA384Digest `yaml:",omitempty"`
SHA512 hash.SHA512Digest `yaml:",omitempty"`
Hwy64 hash.Highway64Digest `yaml:",omitempty"`
Hwy128 hash.Highway128Digest `yaml:",omitempty"`
Hwy256 hash.Highway256Digest `yaml:",omitempty"`
Size int64 `yaml:",omitempty"`
// contains filtered or unexported fields
}
Fingerprint is the core of binprint representing a universally unique (when sufficiently populated) identifier for any blob of bytes (typically a file).
func Self ¶
func Self() (*Fingerprint, error)
Self returns a Fingerprint of the executable being run. If an error is not returned, the all subsequent calls will return the same value without re-calculating it.
func (*Fingerprint) CalculateSums ¶
func (f *Fingerprint) CalculateSums(data io.Reader, size int64) error
CalculateSums calculates any sums missing on the Fingerprint using the provided io.Reader and given file size. If the given size is <= 0 then a gitsha is not calculated. Any sums that are already set (have non-zero-values) are not overwritten and their hash is not recalculated or verified.
func (Fingerprint) GetDigest ¶
func (f Fingerprint) GetDigest(alg string) hash.Digest
GetDigest returns an existing hash.Digest calculated using the given algorithm. If the algorithm is not valid then nil is returned.
func (Fingerprint) HasDigest ¶
func (f Fingerprint) HasDigest(other hash.Digest) bool
HasDigest checks if the hash.Digest matches any of the Fingerprint's hash.Digests
func (*Fingerprint) Is ¶
func (f *Fingerprint) Is(other interface{}) bool
Is performs a full or partial match against the argument. If the argument is another Fingerprint then the fingerprints are considered equivalent if they have any matching non-zero digests. If the argument is a digest then it is matched against the corresponding digest in the Fingerprint. If the argument is a File then a comparison is made against the Fingerprint of that File.
func (Fingerprint) SRI ¶
func (f Fingerprint) SRI() string
SRI returns a string of space separated subresource integrity values, which are base64 encoded hashes prefixed with the name of the hash algorithm. This multi-value string can be used as-is in the "integrity" attribute of a <script> tag so that the browser can perform integrity checks when downloading scripts from potentially untrusted 3rd party CDNs. NPM has also adopted sha512 SRI values for the "dist.integrity" property in package manifests for hosted packages as well as in lock files (package-lock.json, npm-shrinkwrap.json). For more information see:
func (*Fingerprint) SetCacheID ¶
func (c *Fingerprint) SetCacheID(id uint64)
func (Fingerprint) String ¶
func (f Fingerprint) String() string
func (*Fingerprint) UpdateWith ¶
func (f *Fingerprint) UpdateWith(of *Fingerprint) int
UpdateWith fills in any digests that are missing with the digests provided by `other`. Returns the number of hashes that are copied.
type FingerprintMatcher ¶
type FingerprintMatcher func(*Fingerprint) bool
FingerprintMatcher describes a function which matches a Fingerprint given to it.
type GitRepoSource ¶
type GitRepoSource struct {
Commit hash.GitShaDigest
Tag string `yaml:",omitempty"`
Branch string `yaml:",omitempty"`
URL string `yaml:",omitempty"`
Files []*File `yaml:",omitempty"`
// contains filtered or unexported fields
}
GitRepoSource is a container representation of a git commit of a repository
func (GitRepoSource) Find ¶
func (r GitRepoSource) Find(i *Fingerprint) []*File
Find returns a list of Files contained in the git repo that match the provided fingerprint.
func (*GitRepoSource) RecordBlob ¶
func (r *GitRepoSource) RecordBlob(f *File)
RecordBlob records the given file as being part of this repo@commit
func (*GitRepoSource) SetCacheID ¶
func (c *GitRepoSource) SetCacheID(id uint64)
func (GitRepoSource) URN ¶
func (r GitRepoSource) URN() string
URN is a self-describing unique identifier for a specific commit of a specific repository.
type SerializedArchiveFile ¶
SerializedArchiveFile is an alternative representation of ArchiveFile that uses uint64 keys instead of pointers
type SerializedFile ¶
SerializedFile is an alternative representation of ArchiveFile that uses uint64 keys instead of pointers.
type SerializedFingerprint ¶
type SerializedFingerprint struct {
ID uint64
Fingerprint `yaml:",inline"`
}
SerializedFingerprint is a variant of Fingerprint that is suitable for serializing with a serialization specific numeric id
func (*SerializedFingerprint) SetCacheID ¶
func (c *SerializedFingerprint) SetCacheID(id uint64)
type SerializedGitRepo ¶
type SerializedGitRepo struct {
ID uint64
Commit hash.GitShaDigest
Tag string `yaml:",omitempty"`
Branch string `yaml:",omitempty"`
URL string `yaml:",omitempty"`
Files []uint64 `yaml:",omitempty"`
}
SerializedGitRepo is an alternative form of GitRepoSource that uses numeric IDs instead of pointers
type Store ¶
type Store interface {
GetStatFingerprint(os.FileInfo) *Fingerprint
PutStatFingerprint(os.FileInfo, *Fingerprint)
PersistRememberedObjects()
PutFingerprint(*Fingerprint) *Fingerprint
GetFingerprintByGitSHA([20]byte) *Fingerprint
FindMatchingFingerprint(FingerprintMatcher) *Fingerprint
PutFile(*File) *File
GetFileByNameAndGitSHA(string, [20]byte) *File
FindFilesWithFingerprint(*Fingerprint) []*File
PutGitSource(*GitRepoSource) *GitRepoSource
FindGitSourceByURN(string) *GitRepoSource
FindGitSourcesContainingFingerprint(*Fingerprint) []*GitRepoSource
PutArchiveFile(*ArchiveFile) *ArchiveFile
GetArchiveFile(*File) *ArchiveFile
FindArchiveFilesContainingFingerprint(*Fingerprint) []*ArchiveFile
}
Store provides the API to be implemented by a storage backend. A storage backend is required for records because of their interconnected nature.