internal

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FileSchemeHTTP is the http file scheme.
	FileSchemeHTTP FileScheme = iota + 1
	// FileSchemeHTTPS is the https file scheme.
	FileSchemeHTTPS
	// FileSchemeLocal is the local file scheme.
	FileSchemeLocal
	// FileSchemeStdio is the stdio file scheme.
	//
	// This can reference either stdin or stdout depending on if we are
	// reading or writing.
	FileSchemeStdio
	// FileSchemeStdin is the stdin file scheme.
	FileSchemeStdin
	// FileSchemeStdout is the stdout file scheme.
	FileSchemeStdout
	// FileSchemeNull is the null file scheme.
	FileSchemeNull

	// GitSchemeHTTP is the http git scheme.
	GitSchemeHTTP GitScheme = iota + 1
	// GitSchemeHTTPS is the https git scheme.
	GitSchemeHTTPS
	// GitSchemeLocal is the local git scheme.
	GitSchemeLocal
	// GitSchemeSSH is the ssh git scheme.
	GitSchemeSSH
	// GitSchemeGit is the git git scheme.
	GitSchemeGit

	// ArchiveTypeTar is a tar archive.
	ArchiveTypeTar ArchiveType = iota + 1
	// ArchiveTypeZip is a zip archive.
	ArchiveTypeZip

	// CompressionTypeNone is no compression.
	CompressionTypeNone CompressionType = iota + 1
	// CompressionTypeGzip is gzip compression.
	CompressionTypeGzip
	// CompressionTypeZstd is zstd compression.
	CompressionTypeZstd
)

Variables

This section is empty.

Functions

func NewCannotSpecifyCompressionForZipError

func NewCannotSpecifyCompressionForZipError() error

NewCannotSpecifyCompressionForZipError is a fetch error.

func NewCannotSpecifyGitBranchAndTagError

func NewCannotSpecifyGitBranchAndTagError() error

NewCannotSpecifyGitBranchAndTagError is a fetch error.

func NewCannotSpecifyTagWithRefError

func NewCannotSpecifyTagWithRefError() error

NewCannotSpecifyTagWithRefError is a fetch error.

func NewCompressionUnknownError

func NewCompressionUnknownError(compression string) error

NewCompressionUnknownError is a fetch error.

func NewDepthParseError

func NewDepthParseError(s string) error

NewDepthParseError is a fetch error.

func NewDepthZeroError

func NewDepthZeroError() error

NewDepthZeroError is a fetch error.

func NewFormatCannotBeDeterminedError

func NewFormatCannotBeDeterminedError(value string) error

NewFormatCannotBeDeterminedError is a fetch error.

func NewFormatNotAllowedError

func NewFormatNotAllowedError(format string, allowedFormats map[string]struct{}) error

NewFormatNotAllowedError is a fetch error.

func NewFormatOverrideNotAllowedForDevNullError

func NewFormatOverrideNotAllowedForDevNullError(devNull string) error

NewFormatOverrideNotAllowedForDevNullError is a fetch error.

func NewFormatUnknownError

func NewFormatUnknownError(formatString string) error

NewFormatUnknownError is a fetch error.

func NewInvalidPathError

func NewInvalidPathError(format string, path string) error

NewInvalidPathError is a fetch error.

func NewNoPathError

func NewNoPathError() error

NewNoPathError is a fetch error.

func NewOptionsCouldNotParseRecurseSubmodulesError

func NewOptionsCouldNotParseRecurseSubmodulesError(s string) error

NewOptionsCouldNotParseRecurseSubmodulesError is a fetch error.

func NewOptionsCouldNotParseStripComponentsError

func NewOptionsCouldNotParseStripComponentsError(s string) error

NewOptionsCouldNotParseStripComponentsError is a fetch error.

func NewOptionsInvalidForFormatError

func NewOptionsInvalidForFormatError(format string, s string) error

NewOptionsInvalidForFormatError is a fetch error.

func NewOptionsInvalidKeyError

func NewOptionsInvalidKeyError(key string) error

NewOptionsInvalidKeyError is a fetch error.

func NewPathUnknownGzError

func NewPathUnknownGzError(path string) error

NewPathUnknownGzError is a fetch error.

func NewProtoFileCannotBeDevPathError added in v1.19.0

func NewProtoFileCannotBeDevPathError(format string, path string) error

NewProtoFileCannotBeDevPathError is a fetch error.

func NewReadDisabledError

func NewReadDisabledError(scheme string) error

NewReadDisabledError is a fetch error.

func NewReadGitDisabledError

func NewReadGitDisabledError() error

NewReadGitDisabledError is a fetch error.

func NewReadHTTPDisabledError

func NewReadHTTPDisabledError() error

NewReadHTTPDisabledError is a fetch error.

func NewReadLocalDisabledError

func NewReadLocalDisabledError() error

NewReadLocalDisabledError is a fetch error.

func NewReadModuleDisabledError

func NewReadModuleDisabledError() error

NewReadModuleDisabledError is a fetch error.

func NewReadStdioDisabledError

func NewReadStdioDisabledError() error

NewReadStdioDisabledError is a fetch error.

func NewRealCleanPathError

func NewRealCleanPathError(path string) error

NewRealCleanPathError is a fetch error.

func NewWriteDisabledError

func NewWriteDisabledError(scheme string) error

NewWriteDisabledError is a fetch error.

func NewWriteHTTPDisabledError

func NewWriteHTTPDisabledError() error

NewWriteHTTPDisabledError is a fetch error.

func NewWriteLocalDisabledError

func NewWriteLocalDisabledError() error

NewWriteLocalDisabledError is a fetch error.

func NewWriteStdioDisabledError

func NewWriteStdioDisabledError() error

NewWriteStdioDisabledError is a fetch error.

Types

type ArchiveFormatOption

type ArchiveFormatOption func(*archiveFormatInfo)

ArchiveFormatOption is a archive format option.

func WithArchiveDefaultCompressionType

func WithArchiveDefaultCompressionType(defaultCompressionType CompressionType) ArchiveFormatOption

WithArchiveDefaultCompressionType sets the default compression type.

Note this should never be set for zip.

type ArchiveRef

type ArchiveRef interface {
	FileRef
	BucketRef
	ArchiveType() ArchiveType
	// Applied before subdir
	StripComponents() uint32
	// Will be empty instead of "." for root directory
	SubDirPath() string
	// contains filtered or unexported methods
}

ArchiveRef is an archive reference.

An ArchiveRef is a special type of reference that can be either a FileRef or a BucketRef. Note that if ArchiveType is ArchiveTypeZip, CompressionType will always be CompressionTypeNone.

func NewArchiveRef

func NewArchiveRef(
	path string,
	archiveType ArchiveType,
	compressionType CompressionType,
	stripComponents uint32,
	subDirPath string,
) (ArchiveRef, error)

NewArchiveRef returns a new ArchiveRef.

type ArchiveType

type ArchiveType int

ArchiveType is a archive type.

type BucketRef

type BucketRef interface {
	Ref
	// contains filtered or unexported methods
}

BucketRef is a bucket reference.

type CompressionType

type CompressionType int

CompressionType is a compression type.

type DirFormatOption

type DirFormatOption func(*dirFormatInfo)

DirFormatOption is a dir format option.

type DirRef

type DirRef interface {
	// Path is the path to the reference.
	//
	// This will be the non-empty normalized directory path for directories.
	Path() string
	BucketRef
	// contains filtered or unexported methods
}

DirRef is a local directory reference.

func NewDirRef

func NewDirRef(path string) (DirRef, error)

NewDirRef returns a new DirRef.

type FileRef

type FileRef interface {
	Ref
	// Path is the path to the reference.
	//
	// This will be the non-empty path minus the scheme for http and https files.
	// This will be the non-empty normalized file path for local files.
	// This will be empty for stdio and null files.
	Path() string
	FileScheme() FileScheme
	CompressionType() CompressionType
	// contains filtered or unexported methods
}

FileRef is a file reference.

type FileScheme

type FileScheme int

FileScheme is a file scheme.

type GetBucketOption

type GetBucketOption func(*getBucketOptions)

GetBucketOption is a GetBucket option.

func WithGetBucketTerminateFileNames

func WithGetBucketTerminateFileNames(terminateFileNames [][]string) GetBucketOption

WithGetBucketTerminateFileNames only applies if subdir is specified.

The terminate files are organized as a slice of slices of file names. Priority will be given to the first slice of terminate file names, which will be workspace configuration files. The second layer of priority will be given to modules.

This says that for a given subdir, ascend directories until you reach a file with one of these names, and if you do, the returned bucket will be for the directory with this filename, while SubDirPath on the returned bucket will be set to the original subdir relative to the terminate file.

This is used for workspaces and modules. So if you have i.e. "proto/foo" subdir, and terminate file "proto/buf.work.yaml", the returned bucket will be for "proto", and the SubDirPath will be "foo".

The terminateFileNames are expected to be valid and have no slashes. Example of terminateFileNames:

[][]string{
	[]string{"buf.work.yaml", "buf.work"},
	[]string{"buf.yaml", "buf.mod"},
}.

type GetFileOption

type GetFileOption func(*getFileOptions)

GetFileOption is a GetFile option.

func WithGetFileKeepFileCompression

func WithGetFileKeepFileCompression() GetFileOption

WithGetFileKeepFileCompression says to return compressed.

type GetModuleOption

type GetModuleOption func(*getModuleOptions)

GetModuleOption is a GetModule option.

type GetParsedRefOption

type GetParsedRefOption func(*getParsedRefOptions)

GetParsedRefOption is a GetParsedRef option.

func WithAllowedFormats

func WithAllowedFormats(formats ...string) GetParsedRefOption

WithAllowedFormats limits the allowed formats to the given formats.

type GitFormatOption

type GitFormatOption func(*gitFormatInfo)

GitFormatOption is a git format option.

type GitRef

type GitRef interface {
	// Path is the path to the reference.
	//
	// This will be the non-empty path minus the scheme for http, https, ssh, and git repositories.
	// This will be the non-empty normalized directory path for local git repositories.
	Path() string
	BucketRef
	GitScheme() GitScheme
	// Optional. May be nil, in which case clone the default branch.
	GitName() git.Name
	// Will always be >= 1
	Depth() uint32
	RecurseSubmodules() bool
	// Will be empty instead of "." for root directory
	SubDirPath() string
	// contains filtered or unexported methods
}

GitRef is a git reference.

func NewGitRef

func NewGitRef(
	path string,
	gitName git.Name,
	depth uint32,
	recurseSubmodules bool,
	subDirPath string,
) (GitRef, error)

NewGitRef returns a new GitRef.

type GitScheme

type GitScheme int

GitScheme is a git scheme.

type HasFormat

type HasFormat interface {
	Format() string
}

HasFormat is an object that has a format.

type ModuleFormatOption

type ModuleFormatOption func(*moduleFormatInfo)

ModuleFormatOption is a module format option.

type ModuleRef

type ModuleRef interface {
	Ref
	ModuleReference() bufmoduleref.ModuleReference
	// contains filtered or unexported methods
}

ModuleRef is a module reference.

func NewModuleRef

func NewModuleRef(path string) (ModuleRef, error)

NewModuleRef returns a new ModuleRef.

The path must be in the form server/owner/repository/branch[:digest].

type ParsedArchiveRef

type ParsedArchiveRef interface {
	ArchiveRef
	HasFormat
}

ParsedArchiveRef is a parsed ArchiveRef.

func NewDirectParsedArchiveRef

func NewDirectParsedArchiveRef(
	format string,
	path string,
	fileScheme FileScheme,
	archiveType ArchiveType,
	compressionType CompressionType,
	stripComponents uint32,
	subDirPath string,
) ParsedArchiveRef

NewDirectParsedArchiveRef returns a new ParsedArchiveRef with no validation checks.

This should only be used for testing.

type ParsedBucketRef

type ParsedBucketRef interface {
	BucketRef
	HasFormat
}

ParsedBucketRef is a parsed BucketRef.

type ParsedDirRef

type ParsedDirRef interface {
	DirRef
	HasFormat
}

ParsedDirRef is a parsed DirRef.

func NewDirectParsedDirRef

func NewDirectParsedDirRef(format string, path string) ParsedDirRef

NewDirectParsedDirRef returns a new ParsedDirRef with no validation checks.

This should only be used for testing.

type ParsedFileRef

type ParsedFileRef interface {
	FileRef
	HasFormat
}

ParsedFileRef is a parsed FileRef.

type ParsedGitRef

type ParsedGitRef interface {
	GitRef
	HasFormat
}

ParsedGitRef is a parsed GitRef.

func NewDirectParsedGitRef

func NewDirectParsedGitRef(
	format string,
	path string,
	gitScheme GitScheme,
	gitName git.Name,
	recurseSubmodules bool,
	depth uint32,
	subDirPath string,
) ParsedGitRef

NewDirectParsedGitRef returns a new ParsedGitRef with no validation checks.

This should only be used for testing.

type ParsedModuleRef

type ParsedModuleRef interface {
	ModuleRef
	HasFormat
}

ParsedModuleRef is a parsed ModuleRef.

func NewDirectParsedModuleRef

func NewDirectParsedModuleRef(
	format string,
	moduleReference bufmoduleref.ModuleReference,
) ParsedModuleRef

NewDirectParsedModuleRef returns a new ParsedModuleRef with no validation checks.

This should only be used for testing.

type ParsedProtoFileRef added in v1.0.0

type ParsedProtoFileRef interface {
	ProtoFileRef
	HasFormat
}

ParsedProtoFileRef is a parsed ProtoFileRef.

type ParsedRef

type ParsedRef interface {
	Ref
	HasFormat
}

ParsedRef is a parsed Ref.

type ParsedSingleRef

type ParsedSingleRef interface {
	SingleRef
	HasFormat
}

ParsedSingleRef is a parsed SingleRef.

func NewDirectParsedSingleRef

func NewDirectParsedSingleRef(
	format string,
	path string,
	fileScheme FileScheme,
	compressionType CompressionType,
) ParsedSingleRef

NewDirectParsedSingleRef returns a new ParsedSingleRef with no validation checks.

This should only be used for testing.

type ProtoFileFormatOption added in v1.0.0

type ProtoFileFormatOption func(*protoFileFormatInfo)

ProtoFileFormatOption is a single file format option.

type ProtoFileRef added in v1.0.0

type ProtoFileRef interface {
	BucketRef
	// Path is the normalized path to the file reference.
	Path() string
	// IncludePackageFiles says to include the same package files TODO update comment
	IncludePackageFiles() bool
	// contains filtered or unexported methods
}

ProtoFileRef is a file reference that incorporates a BucketRef.

type PutFileOption

type PutFileOption func(*putFileOptions)

PutFileOption is a PutFile option.

func WithPutFileNoFileCompression

func WithPutFileNoFileCompression() PutFileOption

WithPutFileNoFileCompression says to put s uncompressed.

type RawRef

type RawRef struct {
	// Will always be set
	// Not normalized yet
	Path string
	// Will always be set
	// Set via RawRefProcessor if not explicitly set
	Format string
	// Only set for single, archive formats
	// Cannot be set for zip archives
	CompressionType CompressionType
	// Only set for archive, git formats
	SubDirPath string
	// Only set for git formats
	// Only one of GitBranch and GitTag will be set
	GitBranch string
	// Only set for git formats
	// Only one of GitBranch and GitTag will be set
	GitTag string
	// Only set for git formats
	// Specifies an exact git reference to use with git checkout.
	// Can be used on its own or with GitBranch. Not allowed with GitTag.
	// This is defined as anything that can be given to git checkout.
	GitRef string
	// Only set for git formats
	GitRecurseSubmodules bool
	// Only set for git formats.
	// The depth to use when cloning a repository. Only allowed when GitRef
	// is set. Defaults to 50 if unset.
	GitDepth uint32
	// Only set for archive formats
	ArchiveStripComponents uint32
	// Only set for proto file ref format.
	// Sets whether or not to include the files in the rest of the package
	// in the image for the ProtoFileRef.
	// This defaults to false.
	IncludePackageFiles bool
}

RawRef is an unprocessed ref used for WithRefProcessor.

A RawRefProcessor will allow modifications to a RawRef before continuing parsing. This allows defaults to be inferred from the path.

The Path will be the only value set when the RawRefProcessor is invoked, and is not normalized. After the RawRefProcessor is called, options will be parsed.

type ReadBucketCloser

type ReadBucketCloser interface {
	storage.ReadBucketCloser

	// RelativeRootPath is the relative path to the root of the bucket
	// based on the current working directory.
	//
	// This will be set if a terminate filename was specified and found.
	RelativeRootPath() string
	// SubDirPath is the subdir within the Bucket of the actual asset.
	//
	// This will be set if a terminate filename was specified and found.
	// If so, the actual Bucket will be the directory that contained
	// this terminate file, and the subdir will be the subdir of
	// the actual asset relative to the terminate file.
	SubDirPath() string
	// SetSubDirPath sets the value of `SubDirPath`.
	//
	// This should only be called if a terminate file name was specified and found outside of
	// a workspace where the bucket is originally closed.
	SetSubDirPath(string)
}

ReadBucketCloser is a bucket returned from GetBucket.

type ReadBucketCloserWithTerminateFileProvider added in v1.0.0

type ReadBucketCloserWithTerminateFileProvider interface {
	ReadBucketCloser

	// TerminateFileProvider returns a TerminateFileProvider.
	TerminateFileProvider() TerminateFileProvider
}

ReadBucketCloserWithTerminateFileProvider is a ReadBucketCloser with a TerminateFileProvider.

type ReadWriteBucketCloser

type ReadWriteBucketCloser interface {
	ReadBucketCloser
	storage.WriteBucket
}

ReadWriteBucketCloser is a bucket potentially returned from GetBucket.

The returned ReadBucketCloser may be upgradeable to a ReadWriteBucketCloser.

type Reader

type Reader interface {
	// GetFile gets the file.
	// SingleRefs and ArchiveRefs will result in decompressed files unless KeepFileCompression is set.
	GetFile(
		ctx context.Context,
		container app.EnvStdinContainer,
		fileRef FileRef,
		options ...GetFileOption,
	) (io.ReadCloser, error)
	// GetBucket gets the bucket.
	//
	// The returned ReadBucketCloser may actually be upgradeable to a ReadWriteBucketCloser.
	GetBucket(
		ctx context.Context,
		container app.EnvStdinContainer,
		bucketRef BucketRef,
		options ...GetBucketOption,
	) (ReadBucketCloserWithTerminateFileProvider, error)
	// GetModule gets the module.
	GetModule(
		ctx context.Context,
		container app.EnvStdinContainer,
		moduleRef ModuleRef,
		options ...GetModuleOption,
	) (bufmodule.Module, error)
}

Reader is a reader.

func NewReader

func NewReader(
	logger *zap.Logger,
	storageosProvider storageos.Provider,
	options ...ReaderOption,
) Reader

NewReader returns a new Reader.

type ReaderOption

type ReaderOption func(*reader)

ReaderOption is a Reader option.

func WithReaderGit

func WithReaderGit(gitCloner git.Cloner) ReaderOption

WithReaderGit enables Git.

func WithReaderHTTP

func WithReaderHTTP(httpClient *http.Client, httpAuthenticator httpauth.Authenticator) ReaderOption

WithReaderHTTP enables HTTP.

func WithReaderLocal

func WithReaderLocal() ReaderOption

WithReaderLocal enables local.

func WithReaderModule

func WithReaderModule(
	moduleResolver bufmodule.ModuleResolver,
	moduleReader bufmodule.ModuleReader,
) ReaderOption

WithReaderModule enables modules.

func WithReaderStdio

func WithReaderStdio() ReaderOption

WithReaderStdio enables stdio.

type Ref

type Ref interface {
	// contains filtered or unexported methods
}

Ref is a reference.

type RefParser

type RefParser interface {
	// GetParsedRef gets the ParsedRef for the value.
	//
	// The returned ParsedRef will be either a ParsedSingleRef, ParsedArchiveRef, ParsedDirRef, ParsedGitRef, or ParsedModuleRef.
	//
	// The options should be used to validate that you are getting one of the correct formats.
	GetParsedRef(ctx context.Context, value string, options ...GetParsedRefOption) (ParsedRef, error)
}

RefParser parses references.

func NewRefParser

func NewRefParser(logger *zap.Logger, options ...RefParserOption) RefParser

NewRefParser returns a new RefParser.

type RefParserOption

type RefParserOption func(*refParser)

RefParserOption is an RefParser option.

func WithArchiveFormat

func WithArchiveFormat(format string, archiveType ArchiveType, options ...ArchiveFormatOption) RefParserOption

WithArchiveFormat attaches the given format as an archive format.

It is up to the user to not incorrectly attached a format twice.

func WithDirFormat

func WithDirFormat(format string, options ...DirFormatOption) RefParserOption

WithDirFormat attaches the given format as a dir format.

It is up to the user to not incorrectly attached a format twice.

func WithGitFormat

func WithGitFormat(format string, options ...GitFormatOption) RefParserOption

WithGitFormat attaches the given format as a git format.

It is up to the user to not incorrectly attached a format twice.

func WithModuleFormat

func WithModuleFormat(format string, options ...ModuleFormatOption) RefParserOption

WithModuleFormat attaches the given format as a module format.

It is up to the user to not incorrectly attach a format twice.

func WithProtoFileFormat added in v1.0.0

func WithProtoFileFormat(format string, options ...ProtoFileFormatOption) RefParserOption

WithProtoFileFormat attaches the given format as a single file format.

It is up to the user to not incorrectly attach a format twice.

func WithRawRefProcessor

func WithRawRefProcessor(rawRefProcessor func(*RawRef) error) RefParserOption

WithRawRefProcessor attaches the given RawRefProcessor.

If format is not manually specified, the RefParser will use this format parser with the raw path, that is not normalized.

func WithSingleFormat

func WithSingleFormat(format string, options ...SingleFormatOption) RefParserOption

WithSingleFormat attaches the given format as a single format.

It is up to the user to not incorrectly attached a format twice.

type SingleFormatOption

type SingleFormatOption func(*singleFormatInfo)

SingleFormatOption is a single format option.

func WithSingleDefaultCompressionType

func WithSingleDefaultCompressionType(defaultCompressionType CompressionType) SingleFormatOption

WithSingleDefaultCompressionType sets the default compression type.

type SingleRef

type SingleRef interface {
	FileRef
	// contains filtered or unexported methods
}

SingleRef is a non-archive file reference.

func NewSingleRef

func NewSingleRef(path string, compressionType CompressionType) (SingleRef, error)

NewSingleRef returns a new SingleRef.

type TerminateFile added in v1.0.0

type TerminateFile interface {
	// Name returns the name of the TerminateFile (i.e. the base of the fully-qualified file paths).
	Name() string
	// Path returns the normalized directory path where the TemrinateFile is located.
	Path() string
}

TerminateFile is a terminate file.

type TerminateFileProvider added in v1.0.0

type TerminateFileProvider interface {
	// GetTerminateFiles returns the list of terminate files in priority order.
	GetTerminateFiles() []TerminateFile
}

TerminateFileProvider provides TerminateFiles.

type Writer

type Writer interface {
	// PutFile puts the file.
	PutFile(
		ctx context.Context,
		container app.EnvStdoutContainer,
		fileRef FileRef,
		options ...PutFileOption,
	) (io.WriteCloser, error)
}

Writer is a writer.

func NewWriter

func NewWriter(
	logger *zap.Logger,
	options ...WriterOption,
) Writer

NewWriter returns a new Writer.

type WriterOption

type WriterOption func(*writer)

WriterOption is an Writer option.

func WithWriterLocal

func WithWriterLocal() WriterOption

WithWriterLocal enables local.

func WithWriterStdio

func WithWriterStdio() WriterOption

WithWriterStdio enables stdio.

Jump to

Keyboard shortcuts

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