utils

package
v1.34.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2021 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Development = "development"
	Agent       = "jfrog-client-go"
	Version     = "0.25.0"
)
View Source
const CredentialsInUrlRegexp = `(http|https|git)://.+@`
View Source
const MAX_ENTRIES = 10000

Variables

View Source
var MaxBufferSize = 50000

In order to limit the number of items loaded from a reader into the memory, we use a buffers with this size limit.

Functions

func AddProps

func AddProps(oldProps, additionalProps string) string

func AddTrailingSlashIfNeeded

func AddTrailingSlashIfNeeded(url string) string

func Bool2Int

func Bool2Int(b bool) int

func BuildTargetPath

func BuildTargetPath(pattern, path, target string, ignoreRepo bool) (string, bool, error)

Replaces matched regular expression from path to corresponding placeholder {i} at target. Example 1:

pattern = "repoA/1(.*)234" ; path = "repoA/1hello234" ; target = "{1}" ; ignoreRepo = false
returns "hello"

Example 2:

pattern = "repoA/1(.*)234" ; path = "repoB/1hello234" ; target = "{1}" ; ignoreRepo = true
returns "hello"

return (parsed target, placeholders replaced in target, error)

func CheckErrorWithMessage

func CheckErrorWithMessage(err error, message string) error

func ConvertLocalPatternToRegexp

func ConvertLocalPatternToRegexp(localPath string, patternType PatternType) string

func ConvertSliceToMap

func ConvertSliceToMap(slice []string) map[string]bool

func CopyMap

func CopyMap(src map[string]string) (dst map[string]string)

func ExtractArchive

func ExtractArchive(localPath, localFileName, originFileName, logMsgPrefix string) error

localPath - The path of the downloaded archive file. localFileName - name of the archive file. originFileName - name of the archive file in Artifactory. logMsgPrefix - prefix log message. Extract an archive file to the 'localPath'.

func ExtractSha256FromResponseBody

func ExtractSha256FromResponseBody(body []byte) (string, error)

Extract sha256 of the uploaded file (calculated by artifactory) from the response's body. In case of uploading archive with "--explode" the response body will be empty and sha256 won't be shown at the detailed summary.

func GetBoolEnvValue

func GetBoolEnvValue(flagName string, defValue bool) (bool, error)

func GetLogMsgPrefix

func GetLogMsgPrefix(threadId int, dryRun bool) string

func GetRegExp

func GetRegExp(regex string) (*regexp.Regexp, error)

func GetRootPath

func GetRootPath(path string, patternType PatternType, parentheses ParenthesesSlice) string

Get the local root path, from which to start collecting artifacts to be used for: 1. Uploaded to Artifactory, 2. Adding to the local build-info, to be later published to Artifactory.

func GetUserAgent

func GetUserAgent() string

func GetUserHomeDir

func GetUserHomeDir() string

func IndentJson

func IndentJson(jsonStr []byte) string

func IndentJsonArray

func IndentJsonArray(jsonStr []byte) string

func IsSlashPrecedeAsterisk

func IsSlashPrecedeAsterisk(asteriskIndex, slashIndex int) bool

func IsWindows

func IsWindows() bool

func MergeMaps

func MergeMaps(src map[string]string, dst map[string]string)

func NewGitManager

func NewGitManager(path string) *manager

func PlaceholdersUserd

func PlaceholdersUserd(pattern, target string) bool

Return true if at least one of the {i} in 'target' has corresponding parentheses in 'pattern'.

func RemoveCredentials

func RemoveCredentials(line, credentialsPart string) string

Remove credentials from the URL contained in the input line. The credentials are built as 'user:password' or 'token' For example: line = 'This is a line http://user:password@127.0.0.1:8081/artifactory/path/to/repo' credentialsPart = 'http://user:password@' Returned value: 'This is a line http://127.0.0.1:8081/artifactory/path/to/repo'

line = 'This is a line http://token@127.0.0.1:8081/artifactory/path/to/repo' credentialsPart = 'http://token@' Returned value: 'This is a line http://127.0.0.1:8081/artifactory/path/to/repo'

func RemovePlaceholderParentheses

func RemovePlaceholderParentheses(pattern, target string) string

func ReplacePlaceHolders

func ReplacePlaceHolders(groups []string, toReplace string) (string, bool)

group - regular expression matched group to replace with placeholders toReplace - target pattern to replace Return - (parsed placeholders string, placeholders were replaced)

func ReplaceTildeWithUserHome

func ReplaceTildeWithUserHome(path string) string

func SaveFileTransferDetailsInFile

func SaveFileTransferDetailsInFile(filePath string, details *[]FileTransferDetails) error

func SaveFileTransferDetailsInTempFile

func SaveFileTransferDetailsInTempFile(filesDetails *[]FileTransferDetails) (string, error)

func SetUserAgent

func SetUserAgent(newUserAgent string)

func SplitWithEscape

func SplitWithEscape(str string, separator rune) []string

Split str by the provided separator, escaping the separator if it is prefixed by a back-slash.

func StringToBool

func StringToBool(boolVal string, defaultValue bool) (bool, error)

func TrimPath

func TrimPath(path string) string

func WildcardPathToRegExp

func WildcardPathToRegExp(localPath string) string

Types

type Artifact

type Artifact struct {
	LocalPath  string
	TargetPath string
	Symlink    string
}

type ChecksumDetails

type ChecksumDetails struct {
	Md5    string
	Sha1   string
	Sha256 string
}

type DeployableArtifactDetails

type DeployableArtifactDetails struct {
	SourcePath      string `json:"sourcePath,omitempty"`
	ArtifactDest    string `json:"artifactDest,omitempty"`
	Sha256          string `json:"sha256,omitempty"`
	DeploySucceeded bool   `json:"deploySucceeded,omitempty"`
}

Represent deployed artifact's details returned from build-info project for maven and gradle.

func (*DeployableArtifactDetails) CreateFileTransferDetails

func (detailes *DeployableArtifactDetails) CreateFileTransferDetails() FileTransferDetails

type ErrorsQueue

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

func NewErrorsQueue

func NewErrorsQueue(size int) *ErrorsQueue

func (*ErrorsQueue) AddError

func (errQueue *ErrorsQueue) AddError(err error)

func (*ErrorsQueue) GetError

func (errQueue *ErrorsQueue) GetError() error

type ExecutionHandlerFunc

type ExecutionHandlerFunc func() (bool, error)

type FileTransferDetails

type FileTransferDetails struct {
	SourcePath string `json:"sourcePath,omitempty"`
	TargetPath string `json:"targetPath,omitempty"`
	Sha256     string `json:"sha256,omitempty"`
}

Represents a file transfer from SourcePath to TargetPath. Each of the paths can be on the local machine (full or relative) or in Artifactory (full URL). The file's Sha256 is calculated by Artifactory during the upload. we read the sha256 from the HTTP's response body.

type Parentheses

type Parentheses struct {
	OpenIndex  int
	CloseIndex int
}

This struct represents the parentheses used for defining Placeholders (Placeholders is a feature supported by File Specs).

type ParenthesesSlice

type ParenthesesSlice struct {
	Parentheses []Parentheses
}

func NewParenthesesSlice

func NewParenthesesSlice(pattern, target string) ParenthesesSlice

func (*ParenthesesSlice) IsPresent

func (p *ParenthesesSlice) IsPresent(index int) bool

type PatternType

type PatternType string
const (
	WildCardPattern PatternType = "wildcard"
	RegExp          PatternType = "regexp"
	AntPattern      PatternType = "ant"
)

func GetPatternType

func GetPatternType(patternTypes PatternTypes) PatternType

type PatternTypes

type PatternTypes struct {
	RegExp bool
	Ant    bool
}

type RetryExecutor

type RetryExecutor struct {
	// The amount of retries to perform.
	MaxRetries int

	// Number of seconds to sleep between retries.
	RetriesInterval int

	// Message to display when retrying.
	ErrorMessage string

	// Prefix to print at the beginning of each log.
	LogMsgPrefix string

	// ExecutionHandler is the operation to run with retries.
	ExecutionHandler ExecutionHandlerFunc
}

func (*RetryExecutor) Execute

func (runner *RetryExecutor) Execute() error

type Sha256Summary

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

func NewSha256Summary

func NewSha256Summary() *Sha256Summary

func (*Sha256Summary) GetSha256

func (bps *Sha256Summary) GetSha256() string

func (*Sha256Summary) IsSucceeded

func (bps *Sha256Summary) IsSucceeded() bool

func (*Sha256Summary) SetSha256

func (bps *Sha256Summary) SetSha256(sha256 string) *Sha256Summary

func (*Sha256Summary) SetSucceeded

func (bps *Sha256Summary) SetSucceeded(succeeded bool) *Sha256Summary

type UploadResponseBody

type UploadResponseBody struct {
	Checksums ChecksumDetails `json:"checksums,omitempty"`
}

type VcsCache

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

func NewVcsDetals

func NewVcsDetals() *VcsCache

func (*VcsCache) GetVcsDetails

func (this *VcsCache) GetVcsDetails(path string) (revision, refUrl, branch string, err error)

Search for '.git' directory inside 'path', incase there is one, extract the details and add a new entry to the cache(key:path in the file system ,value: git revision & url). otherwise, search in the parent folder and try: 1. search for .git, and save the details for the current dir and all subpath 2. .git not found, go to parent dir and repeat 3. not found on the root directory, add all subpath to cache with nil as a value

Jump to

Keyboard shortcuts

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