github.com/argoproj/argo-cd/v3@v3.2.1/cmd/util/common.go (about)

     1  package util
     2  
     3  import (
     4  	stderrors "errors"
     5  )
     6  
     7  var (
     8  	LogFormat string
     9  	LogLevel  string
    10  )
    11  
    12  func ValidateBearerTokenForHTTPSRepoOnly(bearerToken string, isHTTPS bool) error {
    13  	// Bearer token is only valid for HTTPS repositories
    14  	if bearerToken != "" {
    15  		if !isHTTPS {
    16  			err := stderrors.New("--bearer-token is only supported for HTTPS repositories")
    17  			return err
    18  		}
    19  	}
    20  	return nil
    21  }
    22  
    23  func ValidateBearerTokenForGitOnly(bearerToken string, repoType string) error {
    24  	// Bearer token is only valid for Git repositories
    25  	if bearerToken != "" && repoType != "git" {
    26  		err := stderrors.New("--bearer-token is only supported for Git repositories")
    27  		return err
    28  	}
    29  	return nil
    30  }
    31  
    32  func ValidateBearerTokenAndPasswordCombo(bearerToken string, password string) error {
    33  	// Either the password or the bearer token must be set, but not both
    34  	if bearerToken != "" && password != "" {
    35  		err := stderrors.New("only --bearer-token or --password is allowed, not both")
    36  		return err
    37  	}
    38  	return nil
    39  }