'200':
description: Get helm chart package OK
schema:
- type: object
+ type: file
'500':
description: Get helm chart package failed
schema:
log-level: debug
onborder-url: "http://127.0.0.1:9191"
mock-server: "127.0.0.1:9191"
-getCharts-url: "http://127.0.0.1:9191"
\ No newline at end of file
+getCharts-url: "http://127.0.0.1:9191"
+download-charts-url-format: "http://127.0.0.1:9191/helmrepo/charts/%s-%s.tgz"
\ No newline at end of file
#
log-level: debug
onborder-url: "http://service-ricplt-xapp-onboarder-http.ricplt:8888/api/v1/onboard"
-getCharts-url: "http://service-ricplt-xapp-onboarder-http.ricplt:8080/api/charts"
\ No newline at end of file
+getCharts-url: "http://service-ricplt-xapp-onboarder-http.ricplt:8080/api/charts"
+download-charts-url-format: "http://service-ricplt-xapp-onboarder-http.ricplt:8080/charts/%s-%s.tgz"
\ No newline at end of file
package charts
import (
+ "fmt"
+ "io"
"io/ioutil"
"net/http"
type IChartMgr interface {
GetCharts() (string, error)
+ DownloadChart(string, string) (io.ReadCloser, error)
}
func NewChartmgr() IChartMgr {
ricdms.Logger.Debug("response : %+v", string(respByte))
return string(respByte), nil
}
+
+func (c *ChartMgr) DownloadChart(chartName string, version string) (io.ReadCloser, error) {
+ ricdms.Logger.Debug("Download Charts invoked")
+
+ if chartName == "" || version == "" {
+ return nil, fmt.Errorf("chartname or version is empty")
+ }
+
+ ChartURL := fmt.Sprintf(ricdms.Config.DownloadChartURLFormat, chartName, version)
+
+ resp, err := http.Get(ChartURL)
+ if err != nil {
+ return nil, err
+ }
+
+ return resp.Request.Body, nil
+}
)
type Conf struct {
- LogLevel string `yaml:"log-level"`
- OnboardURL string `yaml:"onborder-url"`
- GetChartsURL string `yaml:"getCharts-url"`
- MockServer string `yaml:"mock-server"`
+ LogLevel string `yaml:"log-level"`
+ OnboardURL string `yaml:"onborder-url"`
+ GetChartsURL string `yaml:"getCharts-url"`
+ DownloadChartURLFormat string `yaml:"download-charts-url-format"`
+ MockServer string `yaml:"mock-server"`
}
func ReadConfiguration(configFile string) (c *Conf, err error) {
return resp
})
+ api.ChartsDownloadHelmChartHandler = charts.DownloadHelmChartHandlerFunc(func(param charts.DownloadHelmChartParams) middleware.Responder {
+ ricdms.Logger.Debug("==> Download helm chart")
+ resp := r.rh.DownloadChart(param.XAppName, param.Version)
+ return resp
+ })
+
r.api = api
}
}
return charts.NewGetChartsListOK().WithPayload(chartList)
}
+
+func (rh *Resthook) DownloadChart(chartname, version string) (resp middleware.Responder) {
+ ricdms.Logger.Debug("DownloadCharts: invoked")
+ reader, err := rh.ChartMgr.DownloadChart(chartname, version)
+
+ if err != nil {
+ ricdms.Logger.Error("Error : %v", err)
+ return charts.NewDownloadHelmChartInternalServerError()
+ }
+
+ return charts.NewDownloadHelmChartOK().WithPayload(reader)
+}
import (
"encoding/json"
"fmt"
+ "io"
"io/ioutil"
"net"
"net/http"
"net/http/httptest"
"os"
+ "strings"
"testing"
ch "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/charts"
assert.Equal(t, "SAMPLE_RESPONSE", successResp.Payload)
}
+func TestDownloadChart(t *testing.T) {
+ svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ ricdms.Logger.Debug("request received by mock to download chart")
+ reader := strings.NewReader("SAMPLE_RESPONSE")
+ data, _ := io.ReadAll(reader)
+ ricdms.Logger.Debug("writing : %+v", data)
+ w.Write(data)
+ }))
+ svr.Listener.Close()
+ svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer)
+
+ svr.Start()
+ defer svr.Close()
+
+ resp := rh.DownloadChart("CHART_NAME", "VERSION")
+ assert.IsType(t, &charts.DownloadHelmChartOK{}, resp, "response did not match type")
+}
+
type HealthCheckerMock struct {
mock.Mock
}