Skip to content

Commit 476537e

Browse files
committed
skipping validation for username, password and url
1 parent 367c07e commit 476537e

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

api/chartRepo/ChartRepositoryRestHandler.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,7 @@ func (handler *ChartRepositoryRestHandlerImpl) UpdateChartRepo(w http.ResponseWr
208208
common.WriteJsonResp(w, err, nil, http.StatusBadRequest)
209209
return
210210
}
211-
err = handler.chartRepositoryService.ValidateDeploymentCount(request)
212-
if err != nil {
213-
handler.Logger.Errorw("error updating, UpdateChartRepo", "err", err, "payload", request)
214-
common.WriteJsonResp(w, err, nil, http.StatusInternalServerError)
215-
return
216-
}
211+
217212
token := r.Header.Get("token")
218213
if ok := handler.enforcer.Enforce(token, casbin.ResourceGlobal, casbin.ActionUpdate, "*"); !ok {
219214
common.WriteJsonResp(w, errors.New("unauthorized"), nil, http.StatusForbidden)

pkg/chartRepo/ChartRepositoryService.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ type ChartRepositoryService interface {
7070
GetChartRepoByName(name string) (*ChartRepoDto, error)
7171
GetChartRepoList() ([]*ChartRepoWithIsEditableDto, error)
7272
GetChartRepoListMin() ([]*ChartRepoDto, error)
73-
ValidateDeploymentCount(request *ChartRepoDto) error
7473
ValidateChartRepo(request *ChartRepoDto) *DetailedErrorHelmRepoValidation
7574
ValidateAndCreateChartRepo(request *ChartRepoDto) (*chartRepoRepository.ChartRepo, error, *DetailedErrorHelmRepoValidation)
7675
ValidateAndUpdateChartRepo(request *ChartRepoDto) (*chartRepoRepository.ChartRepo, error, *DetailedErrorHelmRepoValidation)
@@ -225,17 +224,13 @@ func (impl *ChartRepositoryServiceImpl) CreateChartRepo(request *ChartRepoDto) (
225224
return chartRepo, nil
226225
}
227226

228-
func (impl *ChartRepositoryServiceImpl) ValidateDeploymentCount(request *ChartRepoDto) error {
229-
activeDeploymentCount, err := impl.repoRepository.FindDeploymentCountByChartRepoId(request.Id)
227+
func (impl *ChartRepositoryServiceImpl) getCountOfDeployedCharts(chartRepoId int) (int, error) {
228+
activeDeploymentCount, err := impl.repoRepository.FindDeploymentCountByChartRepoId(chartRepoId)
230229
if err != nil {
231-
impl.logger.Errorw("error in getting deployment count, CheckDeploymentCount", "err", err, "payload", request)
232-
return err
233-
}
234-
if activeDeploymentCount > 0 {
235-
err = &util.ApiError{Code: "400", HttpStatusCode: 400, UserMessage: "cannot update, found charts deployed using this repo"}
236-
return err
230+
impl.logger.Errorw("error in getting deployment count, CheckDeploymentCount", "chartRepoId", chartRepoId, "err", err)
231+
return 0, err
237232
}
238-
return err
233+
return activeDeploymentCount, nil
239234
}
240235

241236
func (impl *ChartRepositoryServiceImpl) UpdateData(request *ChartRepoDto) (*chartRepoRepository.ChartRepo, error) {
@@ -256,6 +251,18 @@ func (impl *ChartRepositoryServiceImpl) UpdateData(request *ChartRepoDto) (*char
256251
if request.Name != previousName && strings.ToLower(request.Name) != request.Name {
257252
return nil, errors.New("invalid repo name: please use lowercase")
258253
}
254+
255+
deployedChartCount, err := impl.getCountOfDeployedCharts(request.Id)
256+
if err != nil {
257+
impl.logger.Errorw("error in getting charts deployed via chart repo", "chartRepoId", request.Id, "err", err)
258+
return nil, err
259+
}
260+
261+
if deployedChartCount > 0 && (request.Name != previousName || request.Url != previousUrl) {
262+
err = &util.ApiError{Code: "400", HttpStatusCode: 400, UserMessage: "cannot update, found charts deployed using this repo"}
263+
return nil, err
264+
}
265+
259266
chartRepo.Url = request.Url
260267
chartRepo.Name = request.Name
261268
chartRepo.AuthMode = request.AuthMode

0 commit comments

Comments
 (0)