github.com/cobalt77/jfrog-client-go@v0.14.5/utils/regexputils.go (about)

     1  package utils
     2  
     3  import (
     4  	"regexp"
     5  	"strings"
     6  
     7  	"github.com/cobalt77/jfrog-client-go/utils/errorutils"
     8  )
     9  
    10  const CredentialsInUrlRegexp = `((http|https):\/\/.+:.*@)`
    11  
    12  func GetRegExp(regex string) (*regexp.Regexp, error) {
    13  	regExp, err := regexp.Compile(regex)
    14  	if errorutils.CheckError(err) != nil {
    15  		return nil, err
    16  	}
    17  	return regExp, nil
    18  }
    19  
    20  // Mask the credentials information from the line, contained in credentialsPart.
    21  // The credentials are built as user:password
    22  // For example:
    23  // line = 'This is a line http://user:password@127.0.0.1:8081/artifactory/path/to/repo'
    24  // credentialsPart = 'http://user:password@'
    25  // Returned value: 'This is a line http://***:***@127.0.0.1:8081/artifactory/path/to/repo'
    26  func MaskCredentials(line, credentialsPart string) string {
    27  	splitResult := strings.Split(credentialsPart, "//")
    28  	return strings.Replace(line, credentialsPart, splitResult[0]+"//***.***@", 1)
    29  }