Skip to content

Commit 80374d7

Browse files
committed
Fix: Separate into functions to reduce cyclomatic complexity
1 parent a595e0c commit 80374d7

File tree

1 file changed

+28
-36
lines changed

1 file changed

+28
-36
lines changed

pkg/clients/helm/client.go

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -271,42 +271,9 @@ func (hc *client) login(spec *v1beta1.ChartSpec, creds *RepoCreds, insecure bool
271271
}
272272

273273
func (hc *client) PullAndLoadChart(spec *v1beta1.ChartSpec, creds *RepoCreds) (*chart.Chart, error) {
274-
var chartFilePath string
275-
var err error
276-
277-
switch {
278-
case spec.URL == "" && (spec.Version == "" || spec.Version == devel):
279-
chartFilePath, err = hc.pullLatestChartVersion(spec, creds)
280-
if err != nil {
281-
return nil, err
282-
}
283-
case registry.IsOCI(spec.URL):
284-
_, v, err := resolveOCIChartVersion(spec.URL)
285-
if err != nil {
286-
return nil, err
287-
}
288-
289-
if v == "" {
290-
chartFilePath, err = hc.pullLatestChartVersion(spec, creds)
291-
if err != nil {
292-
return nil, err
293-
}
294-
} else {
295-
chartFilePath, err = hc.pullChart(spec, creds, chartCache)
296-
if err != nil {
297-
return nil, err
298-
}
299-
}
300-
case spec.URL != "":
301-
chartFilePath, err = hc.pullChart(spec, creds, chartCache)
302-
if err != nil {
303-
return nil, err
304-
}
305-
default:
306-
chartFilePath, err = hc.pullChart(spec, creds, chartCache)
307-
if err != nil {
308-
return nil, err
309-
}
274+
chartFilePath, err := hc.resolveChartFilePath(spec, creds)
275+
if err != nil {
276+
return nil, err
310277
}
311278

312279
if _, err := os.Stat(chartFilePath); os.IsNotExist(err) {
@@ -382,3 +349,28 @@ func resolveOCIChartVersion(chartURL string) (*url.URL, string, error) {
382349
func resolveOCIChartRef(repository string, name string) string {
383350
return strings.Join([]string{strings.TrimSuffix(repository, "/"), name}, "/")
384351
}
352+
353+
func (hc *client) resolveChartFilePath(spec *v1beta1.ChartSpec, creds *RepoCreds) (string, error) {
354+
switch {
355+
case spec.URL == "" && (spec.Version == "" || spec.Version == devel):
356+
return hc.pullLatestChartVersion(spec, creds)
357+
case registry.IsOCI(spec.URL):
358+
return hc.resolveOCIChart(spec, creds)
359+
case spec.URL != "":
360+
return hc.pullChart(spec, creds, chartCache)
361+
default:
362+
return hc.pullChart(spec, creds, chartCache)
363+
}
364+
}
365+
366+
func (hc *client) resolveOCIChart(spec *v1beta1.ChartSpec, creds *RepoCreds) (string, error) {
367+
_, v, err := resolveOCIChartVersion(spec.URL)
368+
if err != nil {
369+
return "", err
370+
}
371+
372+
if v == "" {
373+
return hc.pullLatestChartVersion(spec, creds)
374+
}
375+
return hc.pullChart(spec, creds, chartCache)
376+
}

0 commit comments

Comments
 (0)