github.com/jfrog/jfrog-client-go@v1.40.2/utils/regexputils.go (about)

     1  package utils
     2  
     3  import (
     4  	"github.com/jfrog/jfrog-client-go/utils/errorutils"
     5  	"regexp"
     6  	"strings"
     7  )
     8  
     9  // #nosec G101 -- False positive - no hardcoded credentials.
    10  const CredentialsInUrlRegexp = `(http|https|git)://.+@`
    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  // Remove credentials from the URL contained in the input line.
    21  // The credentials are built as 'user:password' or 'token'
    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  //
    27  // line = 'This is a line http://token@127.0.0.1:8081/artifactory/path/to/repo'
    28  // credentialsPart = 'http://token@'
    29  // Returned value: 'This is a line http://127.0.0.1:8081/artifactory/path/to/repo'
    30  func RemoveCredentials(line, credentialsPart string) string {
    31  	splitResult := strings.Split(credentialsPart, "//")
    32  	return strings.Replace(line, credentialsPart, splitResult[0]+"//", 1)
    33  }