github.com/argoproj/argo-cd@v1.8.7/test/e2e/fixture/repos/repos.go (about)

     1  package repos
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/argoproj/argo-cd/test/e2e/fixture"
     7  	"github.com/argoproj/argo-cd/util/errors"
     8  )
     9  
    10  var (
    11  	CertPath    = mustToAbsPath("../fixture/certs/argocd-test-client.crt")
    12  	CertKeyPath = mustToAbsPath("../fixture/certs/argocd-test-client.key")
    13  )
    14  
    15  func mustToAbsPath(relativePath string) string {
    16  	res, err := filepath.Abs(relativePath)
    17  	errors.CheckError(err)
    18  	return res
    19  }
    20  
    21  // sets the current repo as the default SSH test repo
    22  func AddSSHRepo(insecure bool, credentials bool, repoURLType fixture.RepoURLType) {
    23  	keyPath, err := filepath.Abs("../fixture/testrepos/id_rsa")
    24  	errors.CheckError(err)
    25  	args := []string{"repo", "add", fixture.RepoURL(repoURLType)}
    26  	if credentials {
    27  		args = append(args, "--ssh-private-key-path", keyPath)
    28  	}
    29  	if insecure {
    30  		args = append(args, "--insecure-ignore-host-key")
    31  	}
    32  	errors.FailOnErr(fixture.RunCli(args...))
    33  }
    34  
    35  // sets the current repo as the default HTTPS test repo
    36  func AddHTTPSRepo(insecure bool, credentials bool, repoURLType fixture.RepoURLType) {
    37  	// This construct is somewhat necessary to satisfy the compiler
    38  	args := []string{"repo", "add", fixture.RepoURL(repoURLType)}
    39  	if credentials {
    40  		args = append(args, "--username", fixture.GitUsername, "--password", fixture.GitPassword)
    41  	}
    42  	if insecure {
    43  		args = append(args, "--insecure-skip-server-verification")
    44  	}
    45  	errors.FailOnErr(fixture.RunCli(args...))
    46  }
    47  
    48  // sets a HTTPS repo using TLS client certificate authentication
    49  func AddHTTPSRepoClientCert(insecure bool) {
    50  	args := []string{
    51  		"repo",
    52  		"add",
    53  		fixture.RepoURL(fixture.RepoURLTypeHTTPSClientCert),
    54  		"--username", fixture.GitUsername,
    55  		"--password", fixture.GitPassword,
    56  		"--tls-client-cert-path", CertPath,
    57  		"--tls-client-cert-key-path", CertKeyPath,
    58  	}
    59  	if insecure {
    60  		args = append(args, "--insecure-skip-server-verification")
    61  	}
    62  	errors.FailOnErr(fixture.RunCli(args...))
    63  }
    64  
    65  func AddHelmRepo(name string) {
    66  	args := []string{
    67  		"repo",
    68  		"add",
    69  		fixture.RepoURL(fixture.RepoURLTypeHelm),
    70  		"--username", fixture.GitUsername,
    71  		"--password", fixture.GitPassword,
    72  		"--tls-client-cert-path", CertPath,
    73  		"--tls-client-cert-key-path", CertKeyPath,
    74  		"--type", "helm",
    75  		"--name", name,
    76  	}
    77  	errors.FailOnErr(fixture.RunCli(args...))
    78  }
    79  
    80  // AddHTTPSRepoCredentialsUserPass adds E2E username/password credentials for HTTPS repos to context
    81  func AddHTTPSCredentialsUserPass() {
    82  	var repoURLType fixture.RepoURLType = fixture.RepoURLTypeHTTPS
    83  	args := []string{"repocreds", "add", fixture.RepoURL(repoURLType), "--username", fixture.GitUsername, "--password", fixture.GitPassword}
    84  	errors.FailOnErr(fixture.RunCli(args...))
    85  }
    86  
    87  // AddHTTPSRepoCredentialsTLSClientCert adds E2E  for HTTPS repos to context
    88  func AddHTTPSCredentialsTLSClientCert() {
    89  	certPath, err := filepath.Abs("../fixture/certs/argocd-test-client.crt")
    90  	errors.CheckError(err)
    91  	keyPath, err := filepath.Abs("../fixture/certs/argocd-test-client.key")
    92  	errors.CheckError(err)
    93  	args := []string{
    94  		"repocreds",
    95  		"add",
    96  		fixture.RepoBaseURL(fixture.RepoURLTypeHTTPSClientCert),
    97  		"--username", fixture.GitUsername,
    98  		"--password", fixture.GitPassword,
    99  		"--tls-client-cert-path", certPath,
   100  		"--tls-client-cert-key-path", keyPath,
   101  	}
   102  	errors.FailOnErr(fixture.RunCli(args...))
   103  }
   104  
   105  // AddSSHRepoCredentials adds E2E fixture credentials for SSH repos to context
   106  func AddSSHCredentials() {
   107  	keyPath, err := filepath.Abs("../fixture/testrepos/id_rsa")
   108  	errors.CheckError(err)
   109  	var repoURLType fixture.RepoURLType = fixture.RepoURLTypeSSH
   110  	args := []string{"repocreds", "add", fixture.RepoBaseURL(repoURLType), "--ssh-private-key-path", keyPath}
   111  	errors.FailOnErr(fixture.RunCli(args...))
   112  }