utils

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArtifactorySymlink   = "symlink.dest"
	SymlinkSha1          = "symlink.destsha1"
	LatestBuildNumberKey = "LATEST"
)

Variables

This section is empty.

Functions

func AddAuthHeaders

func AddAuthHeaders(headers map[string]string, artifactoryDetails auth.ServiceDetails)

func AddChecksumHeaders

func AddChecksumHeaders(headers map[string]string, fileDetails *fileutils.FileDetails)

func AddHeader

func AddHeader(headerName, headerValue string, headers *map[string]string)

func BuildArtifactoryUrl

func BuildArtifactoryUrl(baseUrl, path string, params map[string]string) (string, error)

Builds a URL for Artifactory requests. Pay attention: semicolons are escaped!

func BuildQueryFromSpecFile

func BuildQueryFromSpecFile(specFile *CommonParams, requiredArtifactProps RequiredArtifactProps) string

Creates an aql query from a spec file.

func ConvertArtifactsDetailsToBuildInfoArtifacts

func ConvertArtifactsDetailsToBuildInfoArtifacts(artifactsDetailsReader *content.ContentReader) ([]buildinfo.Artifact, error)

func ConvertArtifactsDetailsToBuildInfoDependencies

func ConvertArtifactsDetailsToBuildInfoDependencies(artifactsDetailsReader *content.ContentReader) ([]buildinfo.Dependency, error)

func CreateAqlBodyForSpecWithPattern

func CreateAqlBodyForSpecWithPattern(params *CommonParams) (string, error)

Returns an AQL body string to search file in Artifactory by pattern, according the specified arguments requirements.

func CreateAqlQueryForLatestCreated

func CreateAqlQueryForLatestCreated(repo, path string) string

func CreateAqlQueryForPypi

func CreateAqlQueryForPypi(repo, file string) string

func CreateAqlQueryForYarn

func CreateAqlQueryForYarn(npmName, npmVersion string) string

noinspection GoUnusedExportedFunction

func DisableAccelBuffering

func DisableAccelBuffering(headers *map[string]string)

func DisableTransitiveSearchIfNotAllowed

func DisableTransitiveSearchIfNotAllowed(params *CommonParams, artifactoryVersion *version.Version)

func ExecAql

func ExecAql(aqlQuery string, flags CommonConf) (io.ReadCloser, error)

func ExecAqlSaveToFile

func ExecAqlSaveToFile(aqlQuery string, flags CommonConf) (reader *content.ContentReader, err error)

func FilterBottomChainResults

func FilterBottomChainResults(readerRecord SearchBasedContentItem, reader *content.ContentReader) (*content.ContentReader, error)

func FilterCandidateToBeDeleted

func FilterCandidateToBeDeleted(deleteCandidates *content.ContentReader, resultWriter *content.ContentWriter, candidateType string) ([]*content.ContentReader, error)

func FilterResultsByBuild

func FilterResultsByBuild(specFile *CommonParams, flags CommonConf, requiredArtifactProps RequiredArtifactProps, reader *content.ContentReader) (*content.ContentReader, error)

Filter the results by build, if no build found or items to filter, nil will be returned.

func FilterTopChainResults

func FilterTopChainResults(readerRecord SearchBasedContentItem, reader *content.ContentReader) (*content.ContentReader, error)

Reduce the amount of items by saving only the shortest item path for each unique path e.g.: a | a/b | c | e/f -> a | c | e/f

func GetBuildInfo

func GetBuildInfo(buildName, buildNumber, projectKey string, flags CommonConf) (pbi *buildinfo.PublishedBuildInfo, found bool, err error)

func GetBuildNameAndNumberFromArtifactory

func GetBuildNameAndNumberFromArtifactory(buildName, buildNumber, projectKey string, flags CommonConf) (string, string, error)

func GetProjectQueryParam

func GetProjectQueryParam(projectKey string) string

func GetTestResourcesPath

func GetTestResourcesPath() string

func IsSubPath

func IsSubPath(paths []string, index int, separator string) bool

paths - Sorted array. index - Index of the current path which we want to check if it a prefix of any of the other previous paths. separator - File separator. Returns true paths[index] is a prefix of any of the paths[i] where i<index, otherwise returns false.

func IsWildcardPattern

func IsWildcardPattern(pattern string) bool

func LogSearchResults

func LogSearchResults(numOfArtifacts int)

func ParseNameAndVersion

func ParseNameAndVersion(identifier string, useLatestPolicy bool) (string, string, error)

For builds (useLatestPolicy = true) - Parse build name and number. The build number can be LATEST if absent. For release bundles - Parse bundle name and version. For module - Parse module name and number.

func ReduceBottomChainDirResult

func ReduceBottomChainDirResult(readerRecord SearchBasedContentItem, searchResults *content.ContentReader) (*content.ContentReader, error)

func ReduceDirResult

func ReduceDirResult(readerRecord SearchBasedContentItem, searchResults *content.ContentReader, ascendingOrder bool, resultsFilter AqlSearchResultItemFilter) (*content.ContentReader, error)

Reduce Dir results by using the resultsFilter.

func ReduceTopChainDirResult

func ReduceTopChainDirResult(readerRecord SearchBasedContentItem, searchResults *content.ContentReader) (*content.ContentReader, error)

func SearchBySpecWithAql

func SearchBySpecWithAql(specFile *CommonParams, flags CommonConf, requiredArtifactProps RequiredArtifactProps) (*content.ContentReader, error)

Use this function when running Aql with pattern

func SearchBySpecWithBuild

func SearchBySpecWithBuild(specFile *CommonParams, flags CommonConf) (*content.ContentReader, error)

Use this function when searching by build without pattern or aql. Collect build artifacts and build dependencies separately, then merge the results into one reader.

func SearchBySpecWithPattern

func SearchBySpecWithPattern(specFile *CommonParams, flags CommonConf, requiredArtifactProps RequiredArtifactProps) (*content.ContentReader, error)

Perform search by pattern.

func SetContentType

func SetContentType(contentType string, headers *map[string]string)

func SumIntArray

func SumIntArray(arr []int) int

func UploadFile

func UploadFile(localPath, url, logMsgPrefix string, artifactoryDetails *auth.ServiceDetails, details *fileutils.FileDetails,
	httpClientsDetails httputils.HttpClientDetails, client *jfroghttpclient.JfrogHttpClient, includeChecksums bool,
	progress clientio.ProgressMgr) (*http.Response, []byte, error)

func UploadFileFromReader

func UploadFileFromReader(reader io.Reader, url string, artifactoryDetails *auth.ServiceDetails, details *fileutils.FileDetails,
	httpClientsDetails httputils.HttpClientDetails, client *jfroghttpclient.JfrogHttpClient) (*http.Response, []byte, error)

func WildcardToDirsPath

func WildcardToDirsPath(deletePattern, searchResult string) (string, error)

func WriteCandidateDirsToBeDeleted

func WriteCandidateDirsToBeDeleted(candidateDirsReaders []*content.ContentReader, filesNotToBeDeleteReader *content.ContentReader, resultWriter *content.ContentWriter) (err error)

Write all the dirs to be deleted into 'resultWriter'. However, skip dirs with files(s) that should not be deleted. In order to accomplish this, we check if the dirs are a prefix of any artifact, witch means the folder contains the artifact and should not be deleted. Optimization: In order not to scan for each dir the entire artifact reader and see if it is a prefix or not, we rely on the fact that the dirs and artifacts are sorted. We have two sorted readers in ascending order, we will start scanning from the beginning of the lists and compare whether the folder is a prefix of the current artifact, in case this is true the dir should not be deleted and we can move on to the next dir, otherwise we have to continue to the next dir or artifact. To know this, we will choose to move on with the lexicographic largest between the two.

candidateDirsReaders - Sorted list of dirs to be deleted. filesNotToBeDeleteReader - Sorted files that should not be deleted. resultWriter - The filtered list of dirs to be deleted.

Types

type Aql

type Aql struct {
	ItemsFind string `json:"items.find"`
}

func (*Aql) UnmarshalJSON

func (aql *Aql) UnmarshalJSON(value []byte) error

type AqlSearchResult

type AqlSearchResult struct {
	Results []ResultItem
}

type ArtifactDetails

type ArtifactDetails struct {
	// Path of the artifact in Artifactory
	ArtifactoryPath string             `json:"artifactoryPath,omitempty"`
	Checksums       buildinfo.Checksum `json:"checksums,omitempty"`
}

func (*ArtifactDetails) ToBuildInfoArtifact

func (ad *ArtifactDetails) ToBuildInfoArtifact() buildinfo.Artifact

func (*ArtifactDetails) ToBuildInfoDependency

func (ad *ArtifactDetails) ToBuildInfoDependency() buildinfo.Dependency

type Build

type Build struct {
	BuildName   string `json:"buildName"`
	BuildNumber string `json:"buildNumber"`
}

type BundleReleaseNotes

type BundleReleaseNotes struct {
	Content string `json:"content"`
	Syntax  string `json:"syntax"`
}

type CommonConf

type CommonConf interface {
	GetArtifactoryDetails() auth.ServiceDetails
	GetJfrogHttpClient() *jfroghttpclient.JfrogHttpClient
}

func NewCommonConfImpl

func NewCommonConfImpl(artDetails auth.ServiceDetails) (CommonConf, error)

type CommonConfImpl

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

func (*CommonConfImpl) GetArtifactoryDetails

func (flags *CommonConfImpl) GetArtifactoryDetails() auth.ServiceDetails

func (*CommonConfImpl) GetJfrogHttpClient

func (flags *CommonConfImpl) GetJfrogHttpClient() *jfroghttpclient.JfrogHttpClient

type CommonParams

type CommonParams struct {
	Aql              Aql
	Pattern          string
	Exclusions       []string
	Target           string
	Props            string
	TargetProps      *Properties
	ExcludeProps     string
	SortOrder        string
	SortBy           []string
	Offset           int
	Limit            int
	Build            string
	Project          string
	ExcludeArtifacts bool
	IncludeDeps      bool
	Bundle           string
	Recursive        bool
	IncludeDirs      bool
	Regexp           bool
	Ant              bool
	ArchiveEntries   string
	Transitive       bool
}

func (*CommonParams) GetAql

func (params *CommonParams) GetAql() Aql

func (CommonParams) GetArchiveEntries

func (params CommonParams) GetArchiveEntries() string

func (*CommonParams) GetBuild

func (params *CommonParams) GetBuild() string

func (*CommonParams) GetBundle

func (params *CommonParams) GetBundle() string

func (*CommonParams) GetExcludeProps

func (params *CommonParams) GetExcludeProps() string

func (*CommonParams) GetExclusions

func (params *CommonParams) GetExclusions() []string

func (*CommonParams) GetLimit

func (params *CommonParams) GetLimit() int

func (*CommonParams) GetOffset

func (params *CommonParams) GetOffset() int

func (*CommonParams) GetPattern

func (params *CommonParams) GetPattern() string

func (*CommonParams) GetPatternType

func (params *CommonParams) GetPatternType() clientutils.PatternType

func (*CommonParams) GetProject

func (params *CommonParams) GetProject() string

func (*CommonParams) GetProps

func (params *CommonParams) GetProps() string

func (*CommonParams) GetSortBy

func (params *CommonParams) GetSortBy() []string

func (*CommonParams) GetSortOrder

func (params *CommonParams) GetSortOrder() string

func (CommonParams) GetSpecType

func (params CommonParams) GetSpecType() (specType SpecType)

func (*CommonParams) GetTarget

func (params *CommonParams) GetTarget() string

func (*CommonParams) GetTargetProps

func (params *CommonParams) GetTargetProps() *Properties

func (*CommonParams) IsExplode

func (params *CommonParams) IsExplode() bool

func (CommonParams) IsIncludeDirs

func (params CommonParams) IsIncludeDirs() bool

func (*CommonParams) IsRecursive

func (params *CommonParams) IsRecursive() bool

func (*CommonParams) SetArchiveEntries

func (params *CommonParams) SetArchiveEntries(archiveEntries string)

func (*CommonParams) SetExcludeProps

func (params *CommonParams) SetExcludeProps(excludeProps string)

func (*CommonParams) SetPattern

func (params *CommonParams) SetPattern(pattern string)

func (*CommonParams) SetProps

func (params *CommonParams) SetProps(props string)

func (*CommonParams) SetTarget

func (params *CommonParams) SetTarget(target string)

func (*CommonParams) SetTargetProps

func (params *CommonParams) SetTargetProps(targetProps *Properties)

type FileGetter

type FileGetter interface {
	GetAql() Aql
	GetPattern() string
	SetPattern(pattern string)
	GetExclusions() []string
	GetTarget() string
	SetTarget(target string)
	IsExplode() bool
	GetProps() string
	GetSortOrder() string
	GetSortBy() []string
	GetOffset() int
	GetLimit() int
	GetBuild() string
	GetProject() string
	GetBundle() string
	GetSpecType() (specType SpecType)
	IsRecursive() bool
	IsIncludeDirs() bool
	GetArchiveEntries() string
	SetArchiveEntries(archiveEntries string)
	GetPatternType() clientutils.PatternType
}

type GetReplicationBody

type GetReplicationBody struct {
	ProxyRef string `json:"proxyRef"`
	// contains filtered or unexported fields
}

type OperationSummary

type OperationSummary struct {
	// A ContentReader of FileTransferDetails structs
	TransferDetailsReader *content.ContentReader
	// A ContentReader of ArtifactDetails structs
	ArtifactsDetailsReader *content.ContentReader
	TotalSucceeded         int
	TotalFailed            int
}

func (*OperationSummary) Close

func (cs *OperationSummary) Close() error

type Properties

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

func MergeProperties

func MergeProperties(properties []*Properties) *Properties

Merges multiple Properties structs into one and removes duplicate values

func NewProperties

func NewProperties() *Properties

func ParseProperties

func ParseProperties(propStr string) (*Properties, error)

Parsing properties string to Properties struct.

func (*Properties) AddProperty

func (props *Properties) AddProperty(key, value string)

func (*Properties) KeysLen

func (props *Properties) KeysLen() int

func (*Properties) ParseAndAddProperties

func (props *Properties) ParseAndAddProperties(propStr string) error

func (*Properties) ToEncodedString

func (props *Properties) ToEncodedString(concatValues bool) string

Creates a string of the properties, ready to use in a URL. If concatValues is true, then the values of each property are concatenated together separated by a comma. For example: key=val1,val2,... Otherwise, each value of the property will be written with its key separately. For example: key=val1;key=val2;...

func (*Properties) ToHeadersMap

func (props *Properties) ToHeadersMap() map[string]string

func (*Properties) ToMap

func (props *Properties) ToMap() map[string][]string

Convert properties from Slice to map

type Property

type Property struct {
	Key   string
	Value string
}

type RbGpgValidator

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

func NewRbGpgValidator

func NewRbGpgValidator() *RbGpgValidator

func (*RbGpgValidator) ArtifactsMap

func (r *RbGpgValidator) ArtifactsMap() map[string]string

func (*RbGpgValidator) SetAtrifactoryDetails

func (r *RbGpgValidator) SetAtrifactoryDetails(artDetails *auth.ServiceDetails) *RbGpgValidator

func (*RbGpgValidator) SetClient

func (*RbGpgValidator) SetPublicKey

func (r *RbGpgValidator) SetPublicKey(path string) *RbGpgValidator

func (*RbGpgValidator) SetRbName

func (r *RbGpgValidator) SetRbName(rbName string) *RbGpgValidator

func (*RbGpgValidator) SetRbVersion

func (r *RbGpgValidator) SetRbVersion(rbVersion string) *RbGpgValidator

func (*RbGpgValidator) Validate

func (r *RbGpgValidator) Validate() error

Validate gets a signed release bundle from Artifactory, validates the signature with the public gpg key and saves the release bundle's artifacts in a map

func (*RbGpgValidator) VerifyArtifact

func (r *RbGpgValidator) VerifyArtifact(artifactPath, sha256 string) error

type ReleaseArtifact

type ReleaseArtifact struct {
	RepoPath      string `json:"repo_path"`
	Checksum      string `json:"checksum"`
	DownloadToken string `json:"download_token"`
}

type ReleaseBundleModel

type ReleaseBundleModel struct {
	Id           string              `json:"id"`
	Name         string              `json:"name"`
	Version      string              `json:"version"`
	Created      string              `json:"created"`
	Description  string              `json:"description"`
	Artifacts    []*ReleaseArtifact  `json:"artifacts"`
	ReleaseNotes *BundleReleaseNotes `json:"release_notes"`
	Signature    string              `json:"signature"`
	Type         string              `json:"type"`
}

func (*ReleaseBundleModel) GetOrCalculateId

func (rbm *ReleaseBundleModel) GetOrCalculateId() string

func (*ReleaseBundleModel) Valid

func (rbm *ReleaseBundleModel) Valid() error

type ReplicationParams

type ReplicationParams struct {
	Username string
	Password string
	Url      string
	CronExp  string
	// Source replication repository.
	RepoKey                string
	Proxy                  string
	EnableEventReplication bool
	SocketTimeoutMillis    int
	Enabled                bool
	SyncDeletes            bool
	SyncProperties         bool
	SyncStatistics         bool
	// Deprecated
	PathPrefix               string
	IncludePathPrefixPattern string
}

func CreateReplicationParams

func CreateReplicationParams(body GetReplicationBody) *ReplicationParams

type RepoPathFile

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

We need to translate the provided download pattern to an AQL query. In Artifactory, for each artifact the name and path of the artifact are saved separately. We therefore need to build an AQL query that covers all possible repositories, paths and names the provided pattern can include. For example, the pattern repo/a/* can include the two following file: repo/a/file1.tgz and also repo/a/b/file2.tgz To achieve that, this function parses the pattern by splitting it by its * characters. The end result is a list of RepoPathFile structs. Each struct represent a possible repository, path and file name triple to be included in AQL query with an "or" relationship.

type RequiredArtifactProps

type RequiredArtifactProps int
const (
	ALL RequiredArtifactProps = iota
	SYMLINK
	NONE
)

This enum defines which properties are required in the result of the aql. For example, when performing a copy/move command - the props are not needed, so we set RequiredArtifactProps to NONE.

type Result

type Result struct {
	SuccessCount []int
	TotalCount   []int
}

func NewResult

func NewResult(threads int) *Result

type ResultItem

type ResultItem struct {
	Repo        string     `json:"repo,omitempty"`
	Path        string     `json:"path,omitempty"`
	Name        string     `json:"name,omitempty"`
	Actual_Md5  string     `json:"actual_md5,omitempty"`
	Actual_Sha1 string     `json:"actual_sha1,omitempty"`
	Sha256      string     `json:"sha256,omitempty"`
	Size        int64      `json:"size,omitempty"`
	Created     string     `json:"created,omitempty"`
	Modified    string     `json:"modified,omitempty"`
	Properties  []Property `json:"properties,omitempty"`
	Type        string     `json:"type,omitempty"`
}

func (ResultItem) GetItemRelativeLocation

func (item ResultItem) GetItemRelativeLocation() string

Returns "item.Repo/item.Path/" lowercased.

func (ResultItem) GetItemRelativePath

func (item ResultItem) GetItemRelativePath() string

func (ResultItem) GetName

func (item ResultItem) GetName() string

func (*ResultItem) GetProperty

func (item *ResultItem) GetProperty(key string) string

func (ResultItem) GetSortKey

func (item ResultItem) GetSortKey() string

func (ResultItem) GetType

func (item ResultItem) GetType() string

func (*ResultItem) ToArtifact

func (item *ResultItem) ToArtifact() buildinfo.Artifact

func (*ResultItem) ToDependency

func (item *ResultItem) ToDependency() buildinfo.Dependency

type SearchBasedContentItem

type SearchBasedContentItem interface {
	content.SortableContentItem
	GetItemRelativePath() string
	GetName() string
	GetType() string
}

Implement this interface to allow creating 'content.ContentReader' items which can be used with 'searchutils' functions.

type SpecType

type SpecType string
const (
	WILDCARD SpecType = "wildcard"
	AQL      SpecType = "aql"
	BUILD    SpecType = "build"
)

type UpdateReplicationBody

type UpdateReplicationBody struct {
	Proxy string `json:"proxy"`
	// contains filtered or unexported fields
}

func CreateUpdateReplicationBody

func CreateUpdateReplicationBody(params ReplicationParams) *UpdateReplicationBody

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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