utils

package
v0.25.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2021 License: Apache-2.0 Imports: 27 Imported by: 88

Documentation

Index

Constants

View Source
const (
	ARTIFACTORY_SYMLINK = "symlink.dest"
	SYMLINK_SHA1        = "symlink.destsha1"
	Latest              = "LATEST"
	LastRelease         = "LAST_RELEASE"
)

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 added in v0.9.0

func BuildQueryFromSpecFile(specFile *ArtifactoryCommonParams, requiredArtifactProps RequiredArtifactProps) string

Creates an aql query from a spec file.

func ConvertArtifactsDetailsToBuildInfoArtifacts added in v0.20.1

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

func ConvertArtifactsDetailsToBuildInfoDependencies added in v0.20.1

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

func CreateAqlBodyForSpecWithPattern added in v0.9.0

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

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

func CreateAqlQueryForNpm

func CreateAqlQueryForNpm(npmName, npmVersion string) string

noinspection GoUnusedExportedFunction

func CreateAqlQueryForPypi added in v0.5.3

func CreateAqlQueryForPypi(repo, file string) string

func DisableAccelBuffering added in v0.5.6

func DisableAccelBuffering(headers *map[string]string)

func DisableTransitiveSearchIfNotAllowed added in v0.21.3

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

func ExecAql

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

func ExecAqlSaveToFile added in v0.13.0

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

func FilterBottomChainResults

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

func FilterCandidateToBeDeleted added in v0.13.0

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

func FilterResultsByBuild added in v0.13.0

func FilterResultsByBuild(specFile *ArtifactoryCommonParams, 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 added in v0.20.1

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

func GetBuildNameAndNumberFromArtifactory added in v0.3.1

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

func GetProjectQueryParam added in v0.20.1

func GetProjectQueryParam(projectKey string) 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 ReduceBottomChainDirResult added in v0.13.0

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 added in v0.13.0

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

func SearchBySpecWithAql added in v0.2.0

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

Use this function when running Aql with pattern

func SearchBySpecWithBuild added in v0.2.0

func SearchBySpecWithBuild(specFile *ArtifactoryCommonParams, 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 added in v0.2.0

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

Perform search by pattern.

func SetContentType

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

func SumIntArray added in v0.9.0

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,
	progress clientio.ProgressMgr) (*http.Response, []byte, error)

func UploadFileFromReader added in v0.20.1

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 added in v0.13.0

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 added in v0.20.1

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

func (*ArtifactDetails) ToBuildInfoArtifact added in v0.20.1

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

func (*ArtifactDetails) ToBuildInfoDependency added in v0.20.1

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

type ArtifactoryCommonParams

type ArtifactoryCommonParams struct {
	Aql     Aql
	Pattern string
	// Deprecated, use Exclusions instead
	ExcludePatterns  []string
	Exclusions       []string
	Target           string
	Props            string
	TargetProps      *Properties
	ExcludeProps     string
	SortOrder        string
	SortBy           []string
	Offset           int
	Limit            int
	Build            string
	ExcludeArtifacts bool
	IncludeDeps      bool
	Bundle           string
	Recursive        bool
	IncludeDirs      bool
	Regexp           bool
	Ant              bool
	ArchiveEntries   string
	Transitive       bool
}

func (*ArtifactoryCommonParams) GetAql

func (params *ArtifactoryCommonParams) GetAql() Aql

func (ArtifactoryCommonParams) GetArchiveEntries

func (params ArtifactoryCommonParams) GetArchiveEntries() string

func (*ArtifactoryCommonParams) GetBuild

func (params *ArtifactoryCommonParams) GetBuild() string

func (*ArtifactoryCommonParams) GetBundle added in v0.8.0

func (params *ArtifactoryCommonParams) GetBundle() string

func (*ArtifactoryCommonParams) GetExcludePatterns

func (params *ArtifactoryCommonParams) GetExcludePatterns() []string

func (*ArtifactoryCommonParams) GetExcludeProps added in v0.5.0

func (params *ArtifactoryCommonParams) GetExcludeProps() string

func (*ArtifactoryCommonParams) GetExclusions added in v0.8.0

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

func (*ArtifactoryCommonParams) GetLimit

func (params *ArtifactoryCommonParams) GetLimit() int

func (*ArtifactoryCommonParams) GetOffset

func (params *ArtifactoryCommonParams) GetOffset() int

func (*ArtifactoryCommonParams) GetPattern

func (params *ArtifactoryCommonParams) GetPattern() string

func (*ArtifactoryCommonParams) GetPatternType added in v0.20.1

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

func (*ArtifactoryCommonParams) GetProps

func (params *ArtifactoryCommonParams) GetProps() string

func (*ArtifactoryCommonParams) GetSortBy

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

func (*ArtifactoryCommonParams) GetSortOrder

func (params *ArtifactoryCommonParams) GetSortOrder() string

func (ArtifactoryCommonParams) GetSpecType

func (params ArtifactoryCommonParams) GetSpecType() (specType SpecType)

func (*ArtifactoryCommonParams) GetTarget

func (params *ArtifactoryCommonParams) GetTarget() string

func (*ArtifactoryCommonParams) GetTargetProps added in v0.19.0

func (params *ArtifactoryCommonParams) GetTargetProps() *Properties

func (*ArtifactoryCommonParams) IsExplode

func (params *ArtifactoryCommonParams) IsExplode() bool

func (ArtifactoryCommonParams) IsIncludeDirs

func (params ArtifactoryCommonParams) IsIncludeDirs() bool

func (*ArtifactoryCommonParams) IsRecursive

func (params *ArtifactoryCommonParams) IsRecursive() bool

func (*ArtifactoryCommonParams) SetArchiveEntries

func (params *ArtifactoryCommonParams) SetArchiveEntries(archiveEntries string)

func (*ArtifactoryCommonParams) SetExcludeProps added in v0.5.0

func (params *ArtifactoryCommonParams) SetExcludeProps(excludeProps string)

func (*ArtifactoryCommonParams) SetPattern

func (params *ArtifactoryCommonParams) SetPattern(pattern string)

func (*ArtifactoryCommonParams) SetProps

func (params *ArtifactoryCommonParams) SetProps(props string)

func (*ArtifactoryCommonParams) SetTarget

func (params *ArtifactoryCommonParams) SetTarget(target string)

func (*ArtifactoryCommonParams) SetTargetProps added in v0.19.0

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

type Build added in v0.20.1

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

type Checksums added in v0.20.1

type Checksums struct {
	Sha256 string `json:"sha256,omitempty"`
	Sha1   string `json:"sha1,omitempty"`
	Md5    string `json:"md5,omitempty"`
}

type CommonConf

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

func NewCommonConfImpl added in v0.21.0

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 FileGetter

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

type OperationSummary added in v0.20.1

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 added in v0.20.1

func (cs *OperationSummary) Close()

type Properties

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

func MergeProperties added in v0.20.2

func MergeProperties(properties []*Properties) *Properties

Merges multiple Properties structs into one and removes duplicate values

func NewProperties added in v0.20.2

func NewProperties() *Properties

func ParseProperties

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

Parsing properties string to Properties struct.

func (*Properties) AddProperty added in v0.20.2

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

func (*Properties) KeysLen added in v0.20.2

func (props *Properties) KeysLen() int

func (*Properties) ParseAndAddProperties added in v0.20.2

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 added in v0.19.0

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

Convert properties from Slice to map

type Property

type Property struct {
	Key   string
	Value string
}

type ReplicationBody added in v0.9.0

type ReplicationBody struct {
	Username               string `json:"username"`
	Password               string `json:"password"`
	URL                    string `json:"url"`
	CronExp                string `json:"cronExp"`
	RepoKey                string `json:"repoKey"`
	EnableEventReplication bool   `json:"enableEventReplication"`
	SocketTimeoutMillis    int    `json:"socketTimeoutMillis"`
	Enabled                bool   `json:"enabled"`
	SyncDeletes            bool   `json:"syncDeletes"`
	SyncProperties         bool   `json:"syncProperties"`
	SyncStatistics         bool   `json:"syncStatistics"`
	PathPrefix             string `json:"pathPrefix"`
}

func CreateReplicationBody added in v0.9.0

func CreateReplicationBody(params ReplicationParams) *ReplicationBody

type ReplicationParams added in v0.9.0

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

type RepoPathFile added in v0.5.0

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 added in v0.9.0

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

func NewResult added in v0.9.0

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"`
	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 added in v0.13.2

func (item ResultItem) GetItemRelativeLocation() string

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

func (ResultItem) GetItemRelativePath

func (item ResultItem) GetItemRelativePath() string

func (ResultItem) GetName added in v0.17.0

func (item ResultItem) GetName() string

func (*ResultItem) GetProperty added in v0.17.5

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

func (ResultItem) GetSortKey added in v0.17.0

func (item ResultItem) GetSortKey() string

func (ResultItem) GetType added in v0.17.0

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 added in v0.17.0

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"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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