Implement producer to handle appliation/zip 33/9333/1
authorsubhash kumar singh <subh.singh@samsung.com>
Wed, 19 Oct 2022 15:02:13 +0000 (15:02 +0000)
committersubhash kumar singh <subh.singh@samsung.com>
Wed, 19 Oct 2022 15:02:13 +0000 (15:02 +0000)
Fixed implementation for downloading chart by handling producer
for type appliation/zip.

Signed-off-by: subhash kumar singh <subh.singh@samsung.com>
Change-Id: I271a45e6fbbe15867518555f919dd0d3970b7bdf

api/ric-dms-api-2.0.yaml
pkg/charts/chart_manager.go
pkg/restful/restful.go

index ff55bf9..2243a42 100644 (file)
@@ -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:
index 6a3fc8e..858323a 100644 (file)
@@ -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) {
index 9c9e861..9b784a1 100644 (file)
@@ -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
 }