packages

package
v1.20.6 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: MIT Imports: 38 Imported by: 52

Documentation

Index

Constants

View Source
const EmptyFileKey = ""

EmptyFileKey is a named constant for an empty file key

Variables

View Source
var (
	// ErrDuplicatePackage indicates a duplicated package error
	ErrDuplicatePackage = util.NewAlreadyExistErrorf("package already exists")
	// ErrPackageNotExist indicates a package not exist error
	ErrPackageNotExist = util.NewNotExistErrorf("package does not exist")
)
View Source
var (
	// ErrDuplicatePackageFile indicates a duplicated package file error
	ErrDuplicatePackageFile = util.NewAlreadyExistErrorf("package file already exists")
	// ErrPackageFileNotExist indicates a package file not exist error
	ErrPackageFileNotExist = util.NewNotExistErrorf("package file does not exist")
)
View Source
var ErrDuplicatePackageVersion = util.NewAlreadyExistErrorf("package version already exists")

ErrDuplicatePackageVersion indicates a duplicated package version error

View Source
var ErrPackageBlobNotExist = util.NewNotExistErrorf("package blob does not exist")

ErrPackageBlobNotExist indicates a package blob not exist error

View Source
var ErrPackageBlobUploadNotExist = util.NewNotExistErrorf("package blob upload does not exist")

ErrPackageBlobUploadNotExist indicates a package blob upload not exist error

View Source
var ErrPackageCleanupRuleNotExist = util.NewNotExistErrorf("package blob does not exist")

Functions

func CalculateFileSize added in v1.19.0

func CalculateFileSize(ctx context.Context, opts *PackageFileSearchOptions) (int64, error)

CalculateFileSize sums up all blob sizes matching the search options. It does NOT respect the deduplication of blobs.

func CountVersions added in v1.17.4

func CountVersions(ctx context.Context, opts *PackageSearchOptions) (int64, error)

CountVersions counts all versions of packages matching the search options

func DeleteAllProperties

func DeleteAllProperties(ctx context.Context, refType PropertyType, refID int64) error

DeleteAllProperties deletes all properties of a ref

func DeleteBlobByID

func DeleteBlobByID(ctx context.Context, blobID int64) error

DeleteBlobByID deletes a blob by id

func DeleteBlobUploadByID

func DeleteBlobUploadByID(ctx context.Context, id string) error

DeleteBlobUploadByID deletes the blob upload

func DeleteCleanupRuleByID added in v1.17.4

func DeleteCleanupRuleByID(ctx context.Context, ruleID int64) error

func DeleteFileByID

func DeleteFileByID(ctx context.Context, fileID int64) error

DeleteFileByID deletes a file

func DeletePackageByID

func DeletePackageByID(ctx context.Context, packageID int64) error

DeletePackageByID deletes a package by id

func DeletePropertyByID

func DeletePropertyByID(ctx context.Context, propertyID int64) error

DeletePropertyByID deletes a property

func DeletePropertyByName

func DeletePropertyByName(ctx context.Context, refType PropertyType, refID int64, name string) error

DeletePropertyByName deletes properties by name

func DeleteVersionByID

func DeleteVersionByID(ctx context.Context, versionID int64) error

DeleteVersionByID deletes a version by id

func ExistPackageBlobWithSHA added in v1.17.4

func ExistPackageBlobWithSHA(ctx context.Context, blobSha256 string) (bool, error)

ExistPackageBlobWithSHA returns if a package blob exists with the provided sha

func ExistVersion added in v1.17.4

func ExistVersion(ctx context.Context, opts *PackageSearchOptions) (bool, error)

ExistVersion checks if a version matching the search options exist

func GetDistinctPropertyValues added in v1.20.0

func GetDistinctPropertyValues(ctx context.Context, packageType Type, ownerID int64, refType PropertyType, propertyName string, dep *DistinctPropertyDependency) ([]string, error)

GetDistinctPropertyValues returns all distinct property values for a given type. Optional: Search only in dependence of another property.

func GetTotalBlobSize

func GetTotalBlobSize(ctx context.Context) (int64, error)

GetTotalBlobSize returns the total blobs size in bytes

func GetTotalUnreferencedBlobSize added in v1.19.0

func GetTotalUnreferencedBlobSize(ctx context.Context) (int64, error)

GetTotalUnreferencedBlobSize returns the total size of all unreferenced blobs in bytes

func HasOwnerCleanupRuleForPackageType added in v1.17.4

func HasOwnerCleanupRuleForPackageType(ctx context.Context, ownerID int64, packageType Type) (bool, error)

func HasOwnerPackages

func HasOwnerPackages(ctx context.Context, ownerID int64) (bool, error)

HasOwnerPackages tests if a user/org has accessible packages

func HasRepositoryPackages

func HasRepositoryPackages(ctx context.Context, repositoryID int64) (bool, error)

HasRepositoryPackages tests if a repository has packages

func HasVersionFileReferences

func HasVersionFileReferences(ctx context.Context, versionID int64) (bool, error)

HasVersionFileReferences checks if there are associated files

func IncrementDownloadCounter

func IncrementDownloadCounter(ctx context.Context, versionID int64) error

IncrementDownloadCounter increments the download counter of a version

func IsBlobAccessibleForUser added in v1.20.0

func IsBlobAccessibleForUser(ctx context.Context, blobID int64, user *user_model.User) (bool, error)

IsBlobAccessibleForUser tests if the user has access to the blob

func IterateEnabledCleanupRules added in v1.17.4

func IterateEnabledCleanupRules(ctx context.Context, callback func(context.Context, *PackageCleanupRule) error) error
func SetRepositoryLink(ctx context.Context, packageID, repoID int64) error

SetRepositoryLink sets the linked repository

func UnlinkRepositoryFromAllPackages

func UnlinkRepositoryFromAllPackages(ctx context.Context, repoID int64) error

UnlinkRepositoryFromAllPackages unlinks every package from the repository

func UpdateBlobUpload

func UpdateBlobUpload(ctx context.Context, pbu *PackageBlobUpload) error

UpdateBlobUpload updates the blob upload

func UpdateCleanupRule added in v1.17.4

func UpdateCleanupRule(ctx context.Context, pcr *PackageCleanupRule) error

func UpdateProperty added in v1.19.0

func UpdateProperty(ctx context.Context, pp *PackageProperty) error

UpdateProperty updates a property

func UpdateVersion

func UpdateVersion(ctx context.Context, pv *PackageVersion) error

UpdateVersion updates a version

Types

type DistinctPropertyDependency added in v1.20.0

type DistinctPropertyDependency struct {
	Name  string
	Value string
}

type Package

type Package struct {
	ID               int64  `xorm:"pk autoincr"`
	OwnerID          int64  `xorm:"UNIQUE(s) INDEX NOT NULL"`
	RepoID           int64  `xorm:"INDEX"`
	Type             Type   `xorm:"UNIQUE(s) INDEX NOT NULL"`
	Name             string `xorm:"NOT NULL"`
	LowerName        string `xorm:"UNIQUE(s) INDEX NOT NULL"`
	SemverCompatible bool   `xorm:"NOT NULL DEFAULT false"`
	IsInternal       bool   `xorm:"NOT NULL DEFAULT false"`
}

Package represents a package

func FindUnreferencedPackages

func FindUnreferencedPackages(ctx context.Context) ([]*Package, error)

FindUnreferencedPackages gets all packages without associated versions

func GetPackageByID

func GetPackageByID(ctx context.Context, packageID int64) (*Package, error)

GetPackageByID gets a package by id

func GetPackageByName

func GetPackageByName(ctx context.Context, ownerID int64, packageType Type, name string) (*Package, error)

GetPackageByName gets a package by name

func GetPackagesByType

func GetPackagesByType(ctx context.Context, ownerID int64, packageType Type) ([]*Package, error)

GetPackagesByType gets all packages of a specific type

func TryInsertPackage

func TryInsertPackage(ctx context.Context, p *Package) (*Package, error)

TryInsertPackage inserts a package. If a package exists already, ErrDuplicatePackage is returned

type PackageBlob

type PackageBlob struct {
	ID          int64              `xorm:"pk autoincr"`
	Size        int64              `xorm:"NOT NULL DEFAULT 0"`
	HashMD5     string             `xorm:"hash_md5 char(32) UNIQUE(md5) INDEX NOT NULL"`
	HashSHA1    string             `xorm:"hash_sha1 char(40) UNIQUE(sha1) INDEX NOT NULL"`
	HashSHA256  string             `xorm:"hash_sha256 char(64) UNIQUE(sha256) INDEX NOT NULL"`
	HashSHA512  string             `xorm:"hash_sha512 char(128) UNIQUE(sha512) INDEX NOT NULL"`
	CreatedUnix timeutil.TimeStamp `xorm:"created INDEX NOT NULL"`
}

PackageBlob represents a package blob

func FindExpiredUnreferencedBlobs

func FindExpiredUnreferencedBlobs(ctx context.Context, olderThan time.Duration) ([]*PackageBlob, error)

FindExpiredUnreferencedBlobs gets all blobs without associated files older than the specific duration

func GetBlobByID

func GetBlobByID(ctx context.Context, blobID int64) (*PackageBlob, error)

GetBlobByID gets a blob by id

func GetOrInsertBlob

func GetOrInsertBlob(ctx context.Context, pb *PackageBlob) (*PackageBlob, bool, error)

GetOrInsertBlob inserts a blob. If the blob exists already the existing blob is returned

type PackageBlobUpload

type PackageBlobUpload struct {
	ID             string             `xorm:"pk"`
	BytesReceived  int64              `xorm:"NOT NULL DEFAULT 0"`
	HashStateBytes []byte             `xorm:"BLOB"`
	CreatedUnix    timeutil.TimeStamp `xorm:"created NOT NULL"`
	UpdatedUnix    timeutil.TimeStamp `xorm:"updated INDEX NOT NULL"`
}

PackageBlobUpload represents a package blob upload

func CreateBlobUpload

func CreateBlobUpload(ctx context.Context) (*PackageBlobUpload, error)

CreateBlobUpload inserts a blob upload

func FindExpiredBlobUploads

func FindExpiredBlobUploads(ctx context.Context, olderThan time.Duration) ([]*PackageBlobUpload, error)

FindExpiredBlobUploads gets all expired blob uploads

func GetBlobUploadByID

func GetBlobUploadByID(ctx context.Context, id string) (*PackageBlobUpload, error)

GetBlobUploadByID gets a blob upload by id

type PackageCleanupRule added in v1.17.4

type PackageCleanupRule struct {
	ID                   int64              `xorm:"pk autoincr"`
	Enabled              bool               `xorm:"INDEX NOT NULL DEFAULT false"`
	OwnerID              int64              `xorm:"UNIQUE(s) INDEX NOT NULL DEFAULT 0"`
	Type                 Type               `xorm:"UNIQUE(s) INDEX NOT NULL"`
	KeepCount            int                `xorm:"NOT NULL DEFAULT 0"`
	KeepPattern          string             `xorm:"NOT NULL DEFAULT ''"`
	KeepPatternMatcher   *regexp.Regexp     `xorm:"-"`
	RemoveDays           int                `xorm:"NOT NULL DEFAULT 0"`
	RemovePattern        string             `xorm:"NOT NULL DEFAULT ''"`
	RemovePatternMatcher *regexp.Regexp     `xorm:"-"`
	MatchFullName        bool               `xorm:"NOT NULL DEFAULT false"`
	CreatedUnix          timeutil.TimeStamp `xorm:"created NOT NULL DEFAULT 0"`
	UpdatedUnix          timeutil.TimeStamp `xorm:"updated NOT NULL DEFAULT 0"`
}

PackageCleanupRule represents a rule which describes when to clean up package versions

func GetCleanupRuleByID added in v1.17.4

func GetCleanupRuleByID(ctx context.Context, id int64) (*PackageCleanupRule, error)

func GetCleanupRulesByOwner added in v1.17.4

func GetCleanupRulesByOwner(ctx context.Context, ownerID int64) ([]*PackageCleanupRule, error)

func InsertCleanupRule added in v1.17.4

func InsertCleanupRule(ctx context.Context, pcr *PackageCleanupRule) (*PackageCleanupRule, error)

func (*PackageCleanupRule) CompiledPattern added in v1.17.4

func (pcr *PackageCleanupRule) CompiledPattern() error

type PackageDescriptor

type PackageDescriptor struct {
	Package           *Package
	Owner             *user_model.User
	Repository        *repo_model.Repository
	Version           *PackageVersion
	SemVer            *version.Version
	Creator           *user_model.User
	PackageProperties PackagePropertyList
	VersionProperties PackagePropertyList
	Metadata          any
	Files             []*PackageFileDescriptor
}

PackageDescriptor describes a package

func GetPackageDescriptor

func GetPackageDescriptor(ctx context.Context, pv *PackageVersion) (*PackageDescriptor, error)

GetPackageDescriptor gets the package description for a version

func GetPackageDescriptors

func GetPackageDescriptors(ctx context.Context, pvs []*PackageVersion) ([]*PackageDescriptor, error)

GetPackageDescriptors gets the package descriptions for the versions

func (*PackageDescriptor) CalculateBlobSize

func (pd *PackageDescriptor) CalculateBlobSize() int64

CalculateBlobSize returns the total blobs size in bytes

func (pd *PackageDescriptor) FullWebLink() string

FullWebLink returns the package version web link

func (pd *PackageDescriptor) PackageWebLink() string

PackageWebLink returns the package web link

type PackageFile

type PackageFile struct {
	ID           int64              `xorm:"pk autoincr"`
	VersionID    int64              `xorm:"UNIQUE(s) INDEX NOT NULL"`
	BlobID       int64              `xorm:"INDEX NOT NULL"`
	Name         string             `xorm:"NOT NULL"`
	LowerName    string             `xorm:"UNIQUE(s) INDEX NOT NULL"`
	CompositeKey string             `xorm:"UNIQUE(s) INDEX"`
	IsLead       bool               `xorm:"NOT NULL DEFAULT false"`
	CreatedUnix  timeutil.TimeStamp `xorm:"created INDEX NOT NULL"`
}

PackageFile represents a package file

func GetFileForVersionByID

func GetFileForVersionByID(ctx context.Context, versionID, fileID int64) (*PackageFile, error)

GetFileForVersionByID gets a file of a version by id

func GetFileForVersionByName

func GetFileForVersionByName(ctx context.Context, versionID int64, name, key string) (*PackageFile, error)

GetFileForVersionByName gets a file of a version by name

func GetFilesByVersionID

func GetFilesByVersionID(ctx context.Context, versionID int64) ([]*PackageFile, error)

GetFilesByVersionID gets all files of a version

func SearchFiles

func SearchFiles(ctx context.Context, opts *PackageFileSearchOptions) ([]*PackageFile, int64, error)

SearchFiles gets all files of packages matching the search options

func TryInsertFile

func TryInsertFile(ctx context.Context, pf *PackageFile) (*PackageFile, error)

TryInsertFile inserts a file. If the file exists already ErrDuplicatePackageFile is returned

type PackageFileDescriptor

type PackageFileDescriptor struct {
	File       *PackageFile
	Blob       *PackageBlob
	Properties PackagePropertyList
}

PackageFileDescriptor describes a package file

func GetPackageFileDescriptor

func GetPackageFileDescriptor(ctx context.Context, pf *PackageFile) (*PackageFileDescriptor, error)

GetPackageFileDescriptor gets a package file descriptor for a package file

func GetPackageFileDescriptors added in v1.20.0

func GetPackageFileDescriptors(ctx context.Context, pfs []*PackageFile) ([]*PackageFileDescriptor, error)

GetPackageFileDescriptors gets the package file descriptors for the package files

type PackageFileSearchOptions

type PackageFileSearchOptions struct {
	OwnerID       int64
	PackageType   Type
	VersionID     int64
	Query         string
	CompositeKey  string
	Properties    map[string]string
	OlderThan     time.Duration
	HashAlgorithm string
	Hash          string
	db.Paginator
}

PackageFileSearchOptions are options for SearchXXX methods

type PackageProperty

type PackageProperty struct {
	ID      int64        `xorm:"pk autoincr"`
	RefType PropertyType `xorm:"INDEX NOT NULL"`
	RefID   int64        `xorm:"INDEX NOT NULL"`
	Name    string       `xorm:"INDEX NOT NULL"`
	Value   string       `xorm:"TEXT NOT NULL"`
}

PackageProperty represents a property of a package, version or file

func GetProperties

func GetProperties(ctx context.Context, refType PropertyType, refID int64) ([]*PackageProperty, error)

GetProperties gets all properties

func GetPropertiesByName

func GetPropertiesByName(ctx context.Context, refType PropertyType, refID int64, name string) ([]*PackageProperty, error)

GetPropertiesByName gets all properties with a specific name

func InsertProperty

func InsertProperty(ctx context.Context, refType PropertyType, refID int64, name, value string) (*PackageProperty, error)

InsertProperty creates a property

type PackagePropertyList

type PackagePropertyList []*PackageProperty

PackagePropertyList is a list of package properties

func (PackagePropertyList) GetByName

func (l PackagePropertyList) GetByName(name string) string

GetByName gets the first property value with the specific name

type PackageSearchOptions

type PackageSearchOptions struct {
	OwnerID         int64
	RepoID          int64
	Type            Type
	PackageID       int64
	Name            SearchValue       // only results with the specific name are found
	Version         SearchValue       // only results with the specific version are found
	Properties      map[string]string // only results are found which contain all listed version properties with the specific value
	IsInternal      util.OptionalBool
	HasFileWithName string            // only results are found which are associated with a file with the specific name
	HasFiles        util.OptionalBool // only results are found which have associated files
	Sort            VersionSort
	db.Paginator
}

PackageSearchOptions are options for SearchXXX methods All fields optional and are not used if they have their default value (nil, "", 0)

func (*PackageSearchOptions) ToConds added in v1.20.3

func (opts *PackageSearchOptions) ToConds() builder.Cond

type PackageVersion

type PackageVersion struct {
	ID            int64              `xorm:"pk autoincr"`
	PackageID     int64              `xorm:"UNIQUE(s) INDEX NOT NULL"`
	CreatorID     int64              `xorm:"NOT NULL DEFAULT 0"`
	Version       string             `xorm:"NOT NULL"`
	LowerVersion  string             `xorm:"UNIQUE(s) INDEX NOT NULL"`
	CreatedUnix   timeutil.TimeStamp `xorm:"created INDEX NOT NULL"`
	IsInternal    bool               `xorm:"INDEX NOT NULL DEFAULT false"`
	MetadataJSON  string             `xorm:"metadata_json LONGTEXT"`
	DownloadCount int64              `xorm:"NOT NULL DEFAULT 0"`
}

PackageVersion represents a package version

func GetInternalVersionByNameAndVersion

func GetInternalVersionByNameAndVersion(ctx context.Context, ownerID int64, packageType Type, name, version string) (*PackageVersion, error)

GetInternalVersionByNameAndVersion gets a version by name and version number

func GetOrInsertVersion

func GetOrInsertVersion(ctx context.Context, pv *PackageVersion) (*PackageVersion, error)

GetOrInsertVersion inserts a version. If the same version exist already ErrDuplicatePackageVersion is returned

func GetVersionByID

func GetVersionByID(ctx context.Context, versionID int64) (*PackageVersion, error)

GetVersionByID gets a version by id

func GetVersionByNameAndVersion

func GetVersionByNameAndVersion(ctx context.Context, ownerID int64, packageType Type, name, version string) (*PackageVersion, error)

GetVersionByNameAndVersion gets a version by name and version number

func GetVersionsByPackageName

func GetVersionsByPackageName(ctx context.Context, ownerID int64, packageType Type, name string) ([]*PackageVersion, error)

GetVersionsByPackageName gets all versions of a specific package

func GetVersionsByPackageType

func GetVersionsByPackageType(ctx context.Context, ownerID int64, packageType Type) ([]*PackageVersion, error)

GetVersionsByPackageType gets all versions of a specific type

func SearchLatestVersions

func SearchLatestVersions(ctx context.Context, opts *PackageSearchOptions) ([]*PackageVersion, int64, error)

SearchLatestVersions gets the latest version of every package matching the search options

func SearchVersions

func SearchVersions(ctx context.Context, opts *PackageSearchOptions) ([]*PackageVersion, int64, error)

SearchVersions gets all versions of packages matching the search options

type PropertyType

type PropertyType int64
const (
	// PropertyTypeVersion means the reference is a package version
	PropertyTypeVersion PropertyType = iota // 0
	// PropertyTypeFile means the reference is a package file
	PropertyTypeFile // 1
	// PropertyTypePackage means the reference is a package
	PropertyTypePackage // 2
)

type SearchValue

type SearchValue struct {
	Value      string
	ExactMatch bool
}

SearchValue describes a value to search If ExactMatch is true, the field must match the value otherwise a LIKE search is performed.

type Type

type Type string

Type of a package

const (
	TypeAlpine    Type = "alpine"
	TypeCargo     Type = "cargo"
	TypeChef      Type = "chef"
	TypeComposer  Type = "composer"
	TypeConan     Type = "conan"
	TypeConda     Type = "conda"
	TypeContainer Type = "container"
	TypeCran      Type = "cran"
	TypeDebian    Type = "debian"
	TypeGeneric   Type = "generic"
	TypeGo        Type = "go"
	TypeHelm      Type = "helm"
	TypeMaven     Type = "maven"
	TypeNpm       Type = "npm"
	TypeNuGet     Type = "nuget"
	TypePub       Type = "pub"
	TypePyPI      Type = "pypi"
	TypeRpm       Type = "rpm"
	TypeRubyGems  Type = "rubygems"
	TypeSwift     Type = "swift"
	TypeVagrant   Type = "vagrant"
)

List of supported packages

func (Type) Name

func (pt Type) Name() string

Name gets the name of the package type

func (Type) SVGName

func (pt Type) SVGName() string

SVGName gets the name of the package type svg image

type VersionSort added in v1.17.4

type VersionSort = string
const (
	SortNameAsc     VersionSort = "name_asc"
	SortNameDesc    VersionSort = "name_desc"
	SortVersionAsc  VersionSort = "version_asc"
	SortVersionDesc VersionSort = "version_desc"
	SortCreatedAsc  VersionSort = "created_asc"
	SortCreatedDesc VersionSort = "created_desc"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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