mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48:04 +00:00
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:
@@ -4,6 +4,11 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/hexops/gotextdiff"
|
||||
"github.com/hexops/gotextdiff/myers"
|
||||
@@ -19,10 +24,6 @@ import (
|
||||
"helm.sh/helm/v3/pkg/repo"
|
||||
helmtime "helm.sh/helm/v3/pkg/time"
|
||||
"k8s.io/utils/strings/slices"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type HelmHandler struct {
|
||||
@@ -494,7 +495,7 @@ func (h *HelmHandler) RepoAdd(c *gin.Context) {
|
||||
}
|
||||
|
||||
// TODO: more repo options to accept
|
||||
err := app.Repositories.Add(c.PostForm("name"), c.PostForm("url"))
|
||||
err := app.Repositories.Add(c.PostForm("name"), c.PostForm("url"), c.PostForm("username"), c.PostForm("password"))
|
||||
if err != nil {
|
||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||
return
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -90,8 +94,8 @@ func (r *Repositories) Add(name string, url string) error {
|
||||
c := repo.Entry{
|
||||
Name: name,
|
||||
URL: url,
|
||||
//Username: o.username,
|
||||
//Password: o.password,
|
||||
Username: username,
|
||||
Password: password,
|
||||
//PassCredentialsAll: o.passCredentialsAll,
|
||||
//CertFile: o.certFile,
|
||||
//KeyFile: o.keyFile,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -362,8 +362,26 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<form enctype="application/x-www-form-urlencoded">
|
||||
<label class="form-label">Name: <input class="form-control" name="name"></label>
|
||||
<label class="form-label">URL: <input class="form-control" name="url"></label>
|
||||
<div class="row mb-4">
|
||||
<div class="col">
|
||||
<label class="form-label required">Name</label>
|
||||
<input class="form-control" type="text" name="name" placeholder="Komodorio">
|
||||
</div>
|
||||
<div class="col">
|
||||
<label class="form-label required">URL</label>
|
||||
<input class="form-control" type="text" name="url" placeholder="https://helm-charts.komodor.io">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<label class="form-label">Username</label>
|
||||
<input class="form-control" type="text" name="username">
|
||||
</div>
|
||||
<div class="col">
|
||||
<label class="form-label">Password</label>
|
||||
<input class="form-control" type="password" name="password">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
|
||||
@@ -79,3 +79,8 @@
|
||||
.fs-80 {
|
||||
font-size: 0.8rem!important;
|
||||
}
|
||||
|
||||
.required::after {
|
||||
content: " *";
|
||||
color: red;
|
||||
}
|
||||
Reference in New Issue
Block a user