From 41f03638ee74f924d160328b3291aae61740cbdd Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Wed, 19 Oct 2022 15:02:13 +0000 Subject: [PATCH] Implement producer to handle appliation/zip Fixed implementation for downloading chart by handling producer for type appliation/zip. Signed-off-by: subhash kumar singh Change-Id: I271a45e6fbbe15867518555f919dd0d3970b7bdf --- api/ric-dms-api-2.0.yaml | 4 +--- pkg/charts/chart_manager.go | 2 +- pkg/restful/restful.go | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/api/ric-dms-api-2.0.yaml b/api/ric-dms-api-2.0.yaml index ff55bf9..2243a42 100644 --- a/api/ric-dms-api-2.0.yaml +++ b/api/ric-dms-api-2.0.yaml @@ -49,7 +49,6 @@ paths: get: produces: - application/zip - - text/json parameters: - in: path name: xApp_name @@ -63,8 +62,7 @@ paths: '200': description: Download helm chart OK schema: - format: binary - type: string + type: file '500': description: Get helm chart values.yaml failed schema: diff --git a/pkg/charts/chart_manager.go b/pkg/charts/chart_manager.go index 6a3fc8e..858323a 100644 --- a/pkg/charts/chart_manager.go +++ b/pkg/charts/chart_manager.go @@ -82,7 +82,7 @@ func (c *ChartMgr) DownloadChart(chartName string, version string) (io.ReadClose return nil, err } - return resp.Request.Body, nil + return resp.Body, nil } func (c *ChartMgr) GetChartsByName(name string) ([]map[string]interface{}, error) { diff --git a/pkg/restful/restful.go b/pkg/restful/restful.go index 9c9e861..9b784a1 100644 --- a/pkg/restful/restful.go +++ b/pkg/restful/restful.go @@ -20,6 +20,9 @@ package restful import ( + "fmt" + "io" + "io/ioutil" "log" "os" @@ -34,6 +37,7 @@ import ( "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/resthooks" "gerrit.o-ran-sc.org/r/ric-plt/ricdms/pkg/ricdms" "github.com/go-openapi/loads" + "github.com/go-openapi/runtime" "github.com/go-openapi/runtime/middleware" ) @@ -93,6 +97,25 @@ func (r *Restful) setupHandler() { return resp }) + api.ApplicationZipProducer = runtime.ProducerFunc(func(w io.Writer, data interface{}) error { + if zp, ok := data.(io.ReadCloser); ok { + defer zp.Close() + b, err := ioutil.ReadAll(zp) + + if err != nil { + ricdms.Logger.Error("error: %v", err) + return err + } + _, err = w.Write(b) + + if err != nil { + ricdms.Logger.Error("error: %v", err) + return err + } + return nil + } + return fmt.Errorf("not support") + }) r.api = api } -- 2.16.6