Add username and password support to Repo add feature (#228)

* Add username and password support to Repo add in UI

* Add support for Username and Passowrd in Add Repo API
This commit is contained in:
Harshit Mehta
2023-03-09 19:04:05 +05:30
committed by GitHub
parent 0ac8eec368
commit 47dae4d35a
5 changed files with 41 additions and 13 deletions

View File

@@ -65,11 +65,15 @@ func (r *Repositories) List() ([]Repository, error) {
return res, nil
}
func (r *Repositories) Add(name string, url string) error {
func (r *Repositories) Add(name string, url string, username string, password string) error {
if name == "" || url == "" {
return errors.New("Name and URL are required parameters to add the repository")
}
if (username != "" && password == "") || (username == "" && password != "") {
return errors.New("Username and Password, both are required parameters to add the repository with authentication")
}
// copied from cmd/helm/repo_add.go
repoFile := r.Settings.RepositoryConfig
@@ -88,10 +92,10 @@ func (r *Repositories) Add(name string, url string) error {
defer r.mx.Unlock()
c := repo.Entry{
Name: name,
URL: url,
//Username: o.username,
//Password: o.password,
Name: name,
URL: url,
Username: username,
Password: password,
//PassCredentialsAll: o.passCredentialsAll,
//CertFile: o.certFile,
//KeyFile: o.keyFile,

View File

@@ -75,7 +75,7 @@ func TestFlow(t *testing.T) {
testRepoUrl := "https://helm.github.io/examples"
// add repo
err = testRepository.Add(testRepoName, testRepoUrl)
err = testRepository.Add(testRepoName, testRepoUrl, "", "")
assert.NilError(t, err)
// get repo