Skip to content

Commit 03aa35b

Browse files
committed
fix: init command ensures valid chart repo URL, and adds https:// if not given
1 parent e816a5f commit 03aa35b

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

pkg/devspace/configure/deployment.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"errors"
66
"fmt"
77
"net/http"
8+
"net/url"
89
"os"
910
"path"
1011
"path/filepath"
@@ -152,15 +153,23 @@ func (m *manager) AddHelmDeployment(deploymentName string) error {
152153
requestURL := ""
153154

154155
if chartLocation == chartRepo {
155-
helmConfig.Chart.RepoURL, err = m.log.Question(&survey.QuestionOptions{
156-
Question: "Please specify the full URL of the chart repo (e.g. https://charts.org.tld/)",
157-
ValidationRegexPattern: "^http(s)?://.*",
156+
tempChartRepoURL, err := m.log.Question(&survey.QuestionOptions{
157+
Question: "Please specify the full URL of the chart repo (e.g. https://charts.org.tld/)",
158+
ValidationFunc: func(value string) error {
159+
_, err := url.ParseRequestURI(chartRepoURL(value))
160+
if err != nil {
161+
return err
162+
}
163+
return nil
164+
},
158165
})
159166
if err != nil {
160167
return err
161168
}
162169

163-
requestURL = helmConfig.Chart.RepoURL + "/index.yaml"
170+
helmConfig.Chart.RepoURL = chartRepoURL(tempChartRepoURL)
171+
172+
requestURL = strings.TrimRight(helmConfig.Chart.RepoURL, "/") + "/index.yaml"
164173

165174
helmConfig.Chart.Name, err = m.log.Question(&survey.QuestionOptions{
166175
Question: "Please specify the name of the chart within your chart repository (e.g. payment-service)",
@@ -354,3 +363,11 @@ func (m *manager) AddComponentDeployment(deploymentName, image string, servicePo
354363

355364
return nil
356365
}
366+
367+
func chartRepoURL(url string) string {
368+
repoURL := url
369+
if !(strings.HasPrefix(url, "https://") || strings.HasPrefix(url, "http://")) {
370+
repoURL = "https://" + url
371+
}
372+
return repoURL
373+
}

0 commit comments

Comments
 (0)