@@ -3,6 +3,8 @@ package deployment
33import (
44 "encoding/json"
55 "fmt"
6+ "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef"
7+ "github.com/devtron-labs/devtron/pkg/deployment/manifest/deploymentTemplate/chartRef/bean"
68 "io/ioutil"
79 "net/http"
810 "os"
@@ -15,12 +17,10 @@ import (
1517 "github.com/devtron-labs/devtron/pkg/auth/authorisation/casbin"
1618 "github.com/devtron-labs/devtron/pkg/auth/user"
1719 "github.com/devtron-labs/devtron/pkg/chart"
18- chartRepoRepository "github.com/devtron-labs/devtron/pkg/chartRepo/repository"
1920 "github.com/devtron-labs/devtron/pkg/sql"
2021 "github.com/gorilla/mux"
2122 "github.com/juju/errors"
2223 "go.uber.org/zap"
23- "gopkg.in/go-playground/validator.v9"
2424)
2525
2626type DeploymentConfigRestHandler interface {
@@ -31,13 +31,11 @@ type DeploymentConfigRestHandler interface {
3131}
3232
3333type DeploymentConfigRestHandlerImpl struct {
34- Logger * zap.SugaredLogger
35- userAuthService user.UserService
36- enforcer casbin.Enforcer
37- validator * validator.Validate
38- refChartDir chartRepoRepository.RefChartDir
39- chartService chart.ChartService
40- chartRefRepository chartRepoRepository.ChartRefRepository
34+ Logger * zap.SugaredLogger
35+ userAuthService user.UserService
36+ enforcer casbin.Enforcer
37+ chartService chart.ChartService
38+ chartRefService chartRef.ChartRefService
4139}
4240
4341type DeploymentChartInfo struct {
@@ -49,16 +47,14 @@ type DeploymentChartInfo struct {
4947 Message string `json:"message"`
5048}
5149
52- func NewDeploymentConfigRestHandlerImpl (Logger * zap.SugaredLogger , userAuthService user.UserService , enforcer casbin.Enforcer , validator * validator. Validate ,
53- refChartDir chartRepoRepository. RefChartDir , chartService chart.ChartService , chartRefRepository chartRepoRepository. ChartRefRepository ) * DeploymentConfigRestHandlerImpl {
50+ func NewDeploymentConfigRestHandlerImpl (Logger * zap.SugaredLogger , userAuthService user.UserService , enforcer casbin.Enforcer ,
51+ chartService chart.ChartService , chartRefService chartRef. ChartRefService ) * DeploymentConfigRestHandlerImpl {
5452 return & DeploymentConfigRestHandlerImpl {
55- Logger : Logger ,
56- userAuthService : userAuthService ,
57- enforcer : enforcer ,
58- validator : validator ,
59- refChartDir : refChartDir ,
60- chartService : chartService ,
61- chartRefRepository : chartRefRepository ,
53+ Logger : Logger ,
54+ userAuthService : userAuthService ,
55+ enforcer : enforcer ,
56+ chartService : chartService ,
57+ chartRefService : chartRefService ,
6258 }
6359}
6460
@@ -88,7 +84,7 @@ func (handler *DeploymentConfigRestHandlerImpl) CreateChartFromFile(w http.Respo
8884 return
8985 }
9086
91- err = handler .chartService . ValidateUploadedFileFormat (fileHeader .Filename )
87+ err = handler .chartRefService . ValidateCustomChartUploadedFileFormat (fileHeader .Filename )
9288 if err != nil {
9389 handler .Logger .Errorw ("request err, Unsupported format" , "err" , err , "payload" , file )
9490 common .WriteJsonResp (w , errors .New ("Unsupported format file is uploaded, please upload file with .tgz extension" ), nil , http .StatusBadRequest )
@@ -102,7 +98,7 @@ func (handler *DeploymentConfigRestHandlerImpl) CreateChartFromFile(w http.Respo
10298 return
10399 }
104100
105- chartInfo , err := handler .chartService .ExtractChartIfMissing (fileBytes , string ( handler . refChartDir ) , "" )
101+ chartInfo , err := handler .chartRefService .ExtractChartIfMissing (fileBytes , bean . RefChartDirPath , "" )
106102
107103 if err != nil {
108104 if chartInfo != nil && chartInfo .TemporaryFolder != "" {
@@ -111,15 +107,15 @@ func (handler *DeploymentConfigRestHandlerImpl) CreateChartFromFile(w http.Respo
111107 handler .Logger .Errorw ("error in deleting temp dir " , "err" , err1 )
112108 }
113109 }
114- if err .Error () == chart . CHART_ALREADY_EXISTS_INTERNAL_ERROR || err .Error () == chart . CHART_NAME_RESERVED_INTERNAL_ERROR {
110+ if err .Error () == bean . ChartAlreadyExistsInternalError || err .Error () == bean . ChartNameReservedInternalError {
115111 common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
116112 return
117113 }
118114 common .WriteJsonResp (w , fmt .Errorf (err .Error ()), nil , http .StatusBadRequest )
119115 return
120116 }
121117
122- chartRefs := & chartRepoRepository. ChartRef {
118+ chartRefs := & bean. CustomChartRefDto {
123119 Name : chartInfo .ChartName ,
124120 Version : chartInfo .ChartVersion ,
125121 Location : chartInfo .ChartLocation ,
@@ -178,25 +174,25 @@ func (handler *DeploymentConfigRestHandlerImpl) SaveChart(w http.ResponseWriter,
178174 return
179175 }
180176
181- location := filepath .Join (string ( handler . refChartDir ) , request .FileId )
177+ location := filepath .Join (bean . RefChartDirPath , request .FileId )
182178 if request .Action == "Save" {
183179 file , err := ioutil .ReadFile (filepath .Join (location , "output.json" ))
184180 if err != nil {
185181 handler .Logger .Errorw ("Error reading output.json" , "err" , err )
186182 common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
187183 return
188184 }
189- chartRefs := & chartRepoRepository. ChartRef {}
190- err = json .Unmarshal (file , & chartRefs )
185+ customChartRefDto := & bean. CustomChartRefDto {}
186+ err = json .Unmarshal (file , & customChartRefDto )
191187 if err != nil {
192188 handler .Logger .Errorw ("unmarshall err" , "err" , err )
193189 common .WriteJsonResp (w , err , nil , http .StatusBadRequest )
194190 return
195191 }
196- chartRefs .ChartDescription = request .Description
197- err = handler .chartRefRepository . Save ( chartRefs )
192+ customChartRefDto .ChartDescription = request .Description
193+ err = handler .chartRefService . SaveCustomChart ( customChartRefDto )
198194 if err != nil {
199- handler .Logger .Errorw ("error in saving Chart" , "err" , err )
195+ handler .Logger .Errorw ("error in saving Chart" , "err" , err , "request" , customChartRefDto )
200196 common .WriteJsonResp (w , err , "Chart couldn't be saved" , http .StatusInternalServerError )
201197 return
202198 }
@@ -234,7 +230,7 @@ func (handler *DeploymentConfigRestHandlerImpl) DownloadChart(w http.ResponseWri
234230 common .WriteJsonResp (w , fmt .Errorf ("error in parsing chartRefId : %s must be integer" , chartRefId ), nil , http .StatusBadRequest )
235231 return
236232 }
237- manifestByteArr , err := handler .chartService . GetCustomChartInBytes (chartRefId )
233+ manifestByteArr , err := handler .chartRefService . GetChartInBytes (chartRefId )
238234 if err != nil {
239235 handler .Logger .Errorw ("error in converting chart to bytes" , "err" , err )
240236 common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
@@ -258,7 +254,7 @@ func (handler *DeploymentConfigRestHandlerImpl) GetUploadedCharts(w http.Respons
258254 return
259255 }
260256
261- charts , err := handler .chartService .FetchCustomChartsInfo ()
257+ charts , err := handler .chartRefService .FetchCustomChartsInfo ()
262258 if err != nil {
263259 common .WriteJsonResp (w , err , nil , http .StatusInternalServerError )
264260 return
0 commit comments