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"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/hexops/gotextdiff"
|
"github.com/hexops/gotextdiff"
|
||||||
"github.com/hexops/gotextdiff/myers"
|
"github.com/hexops/gotextdiff/myers"
|
||||||
@@ -19,10 +24,6 @@ import (
|
|||||||
"helm.sh/helm/v3/pkg/repo"
|
"helm.sh/helm/v3/pkg/repo"
|
||||||
helmtime "helm.sh/helm/v3/pkg/time"
|
helmtime "helm.sh/helm/v3/pkg/time"
|
||||||
"k8s.io/utils/strings/slices"
|
"k8s.io/utils/strings/slices"
|
||||||
"net/http"
|
|
||||||
"sort"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type HelmHandler struct {
|
type HelmHandler struct {
|
||||||
@@ -494,7 +495,7 @@ func (h *HelmHandler) RepoAdd(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: more repo options to accept
|
// 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 {
|
if err != nil {
|
||||||
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
_ = c.AbortWithError(http.StatusInternalServerError, err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -65,11 +65,15 @@ func (r *Repositories) List() ([]Repository, error) {
|
|||||||
return res, nil
|
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 == "" {
|
if name == "" || url == "" {
|
||||||
return errors.New("Name and URL are required parameters to add the repository")
|
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
|
// copied from cmd/helm/repo_add.go
|
||||||
repoFile := r.Settings.RepositoryConfig
|
repoFile := r.Settings.RepositoryConfig
|
||||||
|
|
||||||
@@ -88,10 +92,10 @@ func (r *Repositories) Add(name string, url string) error {
|
|||||||
defer r.mx.Unlock()
|
defer r.mx.Unlock()
|
||||||
|
|
||||||
c := repo.Entry{
|
c := repo.Entry{
|
||||||
Name: name,
|
Name: name,
|
||||||
URL: url,
|
URL: url,
|
||||||
//Username: o.username,
|
Username: username,
|
||||||
//Password: o.password,
|
Password: password,
|
||||||
//PassCredentialsAll: o.passCredentialsAll,
|
//PassCredentialsAll: o.passCredentialsAll,
|
||||||
//CertFile: o.certFile,
|
//CertFile: o.certFile,
|
||||||
//KeyFile: o.keyFile,
|
//KeyFile: o.keyFile,
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func TestFlow(t *testing.T) {
|
|||||||
testRepoUrl := "https://helm.github.io/examples"
|
testRepoUrl := "https://helm.github.io/examples"
|
||||||
|
|
||||||
// add repo
|
// add repo
|
||||||
err = testRepository.Add(testRepoName, testRepoUrl)
|
err = testRepository.Add(testRepoName, testRepoUrl, "", "")
|
||||||
assert.NilError(t, err)
|
assert.NilError(t, err)
|
||||||
|
|
||||||
// get repo
|
// get repo
|
||||||
|
|||||||
@@ -362,8 +362,26 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form enctype="application/x-www-form-urlencoded">
|
<form enctype="application/x-www-form-urlencoded">
|
||||||
<label class="form-label">Name: <input class="form-control" name="name"></label>
|
<div class="row mb-4">
|
||||||
<label class="form-label">URL: <input class="form-control" name="url"></label>
|
<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>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|||||||
@@ -79,3 +79,8 @@
|
|||||||
.fs-80 {
|
.fs-80 {
|
||||||
font-size: 0.8rem!important;
|
font-size: 0.8rem!important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.required::after {
|
||||||
|
content: " *";
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user