git

package
v1.62.2 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	MaxEntriesChannelSize     = 100000
	ValidationParallelisation = 32
)

Functions

func CloneWithLimits

func CloneWithLimits(ctx context.Context, dir string, limits ILimits, gitOptions *GitActionConfig) (err error)

CloneWithLimits clones a repository with limits on the max tree depth, the max repository size, the max file count, the max individual file size, and the max entries

Types

type CloneObject

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

func NewCloneObject

func NewCloneObject() *CloneObject

func (*CloneObject) Checkout

func (c *CloneObject) Checkout(gitOptions *GitActionConfig) (err error)

func (*CloneObject) Clone

func (c *CloneObject) Clone(ctx context.Context, path string, cfg *GitActionConfig) (err error)

Clone without checkout or validation

func (*CloneObject) SetupLimits

func (c *CloneObject) SetupLimits(cfg ILimits) (err error)

func (*CloneObject) ValidateRepository

func (c *CloneObject) ValidateRepository(ctx context.Context) (err error)

After cloning without checkout, valdiate the repository to check for git bombs

type Entry

type Entry struct {
	TreeEntry object.TreeEntry
	TreeDepth int64
	Seen      string
}

type GitActionConfig

type GitActionConfig struct {
	// The (possibly remote) repository URL to clone from.
	URL string `mapstructure:"url"`
	// Auth credentials, if required, to use with the remote repository.
	Auth http.BasicAuth `mapstructure:"auth"`
	// Limit fetching to the specified number of commits.
	Depth int `mapstructure:"depth"`
	// Regerence can be a hash, a branch, or a tag
	Reference string `mapstructure:"ref"`
	// RecurseSubmodules after the clone is created, initialize all submodules
	// within, using their default settings. This option is ignored if the
	// cloned repository does not have a worktree.
	RecurseSubmodules bool `mapstructure:"recursive_submodules"`
	// Tags describe how the tags will be fetched from the remote repository,
	// by default is AllTags.
	Tags git.TagMode `mapstructure:"tags"`
	// CreateBranch a new branch named Branch and start it at Hash.
	CreateBranch bool `mapstructure:"create_branch"`
	// No checkout of HEAD after clone if true.
	NoCheckout bool
}

GitActionConfig describes how a clone or checkout should be performed.

func NewGitActionConfig

func NewGitActionConfig(url string) GitActionConfig

func (*GitActionConfig) GetAuth

func (c *GitActionConfig) GetAuth() *http.BasicAuth

func (*GitActionConfig) GetCreate

func (c *GitActionConfig) GetCreate() bool

func (*GitActionConfig) GetDepth

func (c *GitActionConfig) GetDepth() int

func (*GitActionConfig) GetNoCheckout

func (c *GitActionConfig) GetNoCheckout() bool

func (*GitActionConfig) GetRecursiveSubModules

func (c *GitActionConfig) GetRecursiveSubModules() bool

func (*GitActionConfig) GetReference added in v1.17.1

func (c *GitActionConfig) GetReference() string

func (*GitActionConfig) GetTags

func (c *GitActionConfig) GetTags() git.TagMode

func (*GitActionConfig) GetURL

func (c *GitActionConfig) GetURL() string

func (*GitActionConfig) Validate

func (c *GitActionConfig) Validate() error

type IGitActionConfig

type IGitActionConfig interface {
	config.IServiceConfiguration
	GetUrl() string
	GetAuth() transport.AuthMethod
	GetDepth() int
	GetReference() string
	GetRecursiveSubModules() git.SubmoduleRescursivity
	GetTags() git.TagMode
	GetCreate() bool
	GetNoCheckout() bool
}

type ILimits

type ILimits interface {
	config.IServiceConfiguration
	// Apply states whether the limit should be applied
	Apply() bool
	// GetMaxFileSize returns the maximum size in byte a file can have on a file system
	GetMaxFileSize() int64
	// GetMaxTotalSize returns the maximum size in byte a location can have on a file system (whether it is a file or a folder)
	GetMaxTotalSize() int64
	// GetMaxFileCount returns the maximum number of files allowed in a reposittory
	GetMaxFileCount() int64
	// GetMaxTreeDepth returns the maximum tree depth for a repository
	GetMaxTreeDepth() int64
	// GetMaxEntries returns the maximum total entries allowed in the it repo
	GetMaxEntries() int64
	// GetMaxTrueSize returns the maximum true size of the repo based on blobs
	GetMaxTrueSize() int64
}

ILimits defines general GitLimits for actions performed during a git clone

func DefaultLimits

func DefaultLimits() ILimits

DefaultLimits defines default file system FileSystemLimits

func NewLimits

func NewLimits(maxFileSize, maxTotalSize, maxFileCount, maxTreeDepth, maxEntries, maxTrueSize int64) ILimits

NewLimits defines file system FileSystemLimits.

func NoLimits

func NoLimits() ILimits

NoLimits defines no file system FileSystemLimits

type Limits

type Limits struct {
	MaxFileSize  int64 `mapstructure:"max_file_size"`
	MaxTotalSize int64 `mapstructure:"max_total_size"`
	MaxFileCount int64 `mapstructure:"max_file_count"`
	MaxTreeDepth int64 `mapstructure:"max_tree_depth"`
	MaxEntries   int64 `mapstructure:"max_entries"`
	MaxTrueSize  int64 `mapstructure:"max_true_size"`
}

Limits defines file system limits

func (*Limits) Apply

func (l *Limits) Apply() bool

func (*Limits) GetMaxEntries

func (l *Limits) GetMaxEntries() int64

func (*Limits) GetMaxFileCount

func (l *Limits) GetMaxFileCount() int64

func (*Limits) GetMaxFileSize

func (l *Limits) GetMaxFileSize() int64

func (*Limits) GetMaxTotalSize

func (l *Limits) GetMaxTotalSize() int64

func (*Limits) GetMaxTreeDepth

func (l *Limits) GetMaxTreeDepth() int64

func (*Limits) GetMaxTrueSize added in v1.20.0

func (l *Limits) GetMaxTrueSize() int64

func (*Limits) Validate

func (l *Limits) Validate() error

Jump to

Keyboard shortcuts

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