'200':
description: Get helm chart
schema:
- type: object
+ type: array
+ items:
+ type: object
'500':
description: Get helm chart failed
schema:
onborder-url: "http://127.0.0.1:9191"
mock-server: "127.0.0.1:9191"
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
+download-charts-url-format: "http://127.0.0.1:9191/helmrepo/charts/%s-%s.tgz"
+getCharts-by-name-url: "http://127.0.0.1:9191/helmrepo/api/charts/%s"
\ 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"
-download-charts-url-format: "http://service-ricplt-xapp-onboarder-http.ricplt:8080/charts/%s-%s.tgz"
\ No newline at end of file
+download-charts-url-format: "http://service-ricplt-xapp-onboarder-http.ricplt:8080/charts/%s-%s.tgz"
+getCharts-by-name-url: "http://172.17.0.1:9100/helmrepo/api/charts/%s"
\ No newline at end of file
package charts
import (
+ "encoding/json"
"fmt"
"io"
"io/ioutil"
type IChartMgr interface {
GetCharts() (string, error)
DownloadChart(string, string) (io.ReadCloser, error)
+ GetChartsByName(name string) ([]map[string]interface{}, error)
}
func NewChartmgr() IChartMgr {
return resp.Request.Body, nil
}
+
+func (c *ChartMgr) GetChartsByName(name string) ([]map[string]interface{}, error) {
+ ricdms.Logger.Debug("Get Chart by xApp name is invoked")
+
+ if name == "" {
+ return make([]map[string]interface{}, 0), fmt.Errorf("xAppname is empty")
+ }
+
+ URL := fmt.Sprintf(ricdms.Config.GetChartsByxAppNameURL, name)
+
+ response, err := http.Get(URL)
+ if err != nil {
+ ricdms.Logger.Error("error: %v", err)
+ return make([]map[string]interface{}, 0), err
+ }
+
+ defer response.Body.Close()
+ data, err := ioutil.ReadAll(response.Body)
+
+ if err != nil {
+ ricdms.Logger.Debug("Reading response failed with err : %v", err)
+ return make([]map[string]interface{}, 0), err
+ }
+
+ v := make([]map[string]interface{}, 0)
+ err = json.Unmarshal(data, &v)
+ if err != nil {
+ ricdms.Logger.Debug("Error while parsing res: %v", err)
+ return make([]map[string]interface{}, 0), err
+ }
+ return v, nil
+}
LogLevel string `yaml:"log-level"`
OnboardURL string `yaml:"onborder-url"`
GetChartsURL string `yaml:"getCharts-url"`
+ GetChartsByxAppNameURL string `yaml:"getCharts-by-name-url"`
DownloadChartURLFormat string `yaml:"download-charts-url-format"`
MockServer string `yaml:"mock-server"`
}
return resp
})
+ api.ChartsGetChartHandler = charts.GetChartHandlerFunc(func(param charts.GetChartParams) middleware.Responder {
+ ricdms.Logger.Debug("==> Get Charts by name is invoked")
+ resp := r.rh.GetChartsByName(param.XAppName)
+ return resp
+ })
+
r.api = api
}
--- /dev/null
+[
+ {
+ "name": "hw-go",
+ "version": "1.0.0",
+ "description": "Standard xApp Helm Chart",
+ "apiVersion": "v1",
+ "appVersion": "1.0",
+ "urls": [
+ "charts/hw-go-1.0.0.tgz"
+ ],
+ "created": "2022-09-19T08:12:55.54057053Z",
+ "digest": "f155d6c356bdcd1e3bcc1dd3df080e25a62b6e8ee32c289c5f20dec1af9c96de"
+ }
+]
\ No newline at end of file
return charts.NewDownloadHelmChartOK().WithPayload(reader)
}
+
+func (rh *Resthook) GetChartsByName(name string) middleware.Responder {
+ ricdms.Logger.Debug("GetChartByName: invoked")
+ res, err := rh.ChartMgr.GetChartsByName(name)
+
+ if err != nil {
+ ricdms.Logger.Error("error: %v", err)
+ return charts.NewGetChartInternalServerError()
+ }
+
+ response := make([]interface{}, 0)
+ for _, item := range res {
+ response = append(response, item)
+ }
+
+ return charts.NewGetChartOK().WithPayload(response)
+}
"net/http"
"net/http/httptest"
"os"
+ "path/filepath"
"strings"
"testing"
assert.IsType(t, &charts.DownloadHelmChartOK{}, resp, "response did not match type")
}
+func TestGetChartsByName(t *testing.T) {
+ svr := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ ricdms.Logger.Debug("request received by mock to get chart by name")
+ path, _ := filepath.Abs("./mocks/resp-get-charts-by-name.json")
+ file, err := os.Open(path)
+
+ if err != nil {
+ ricdms.Logger.Error("error in reading file: %v", err)
+ }
+
+ jsonData, err := io.ReadAll(file)
+ if err != nil {
+ ricdms.Logger.Error("Error in rading file: %v", err)
+ }
+ w.Write(jsonData)
+ }))
+
+ svr.Listener.Close()
+ svr.Listener, _ = net.Listen("tcp", ricdms.Config.MockServer)
+
+ svr.Start()
+ defer svr.Close()
+
+ resp := rh.GetChartsByName("TEST_NAME")
+ ricdms.Logger.Debug("resp Data: %s", resp.(*charts.GetChartOK).Payload...)
+ assert.IsType(t, &charts.GetChartOK{}, resp, "response did not match type")
+}
+
type HealthCheckerMock struct {
mock.Mock
}