Browse Source

Merge pull request #2682 from porter-dev/nafees/delete-basic-auth-helm-repo-update

[hotfix] Delete basic auth for existing helm repo during update
Mohammed Nafees 3 years ago
parent
commit
baf8734729
1 changed files with 20 additions and 0 deletions
  1. 20 0
      api/server/handlers/helmrepo/update.go

+ 20 - 0
api/server/handlers/helmrepo/update.go

@@ -59,6 +59,26 @@ func (p *HelmRepoUpdateHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
 		return
 	}
 
+	if request.BasicIntegrationID != 0 &&
+		helmRepo.BasicAuthIntegrationID != 0 &&
+		request.BasicIntegrationID != helmRepo.BasicAuthIntegrationID {
+		bi, err := p.Repo().BasicIntegration().ReadBasicIntegration(proj.ID, helmRepo.BasicAuthIntegrationID)
+
+		if err != nil {
+			if !errors.Is(err, gorm.ErrRecordNotFound) {
+				p.HandleAPIError(w, r, apierrors.NewErrInternal(err))
+				return
+			}
+		} else {
+			_, err = p.Repo().BasicIntegration().DeleteBasicIntegration(bi)
+
+			if err != nil {
+				p.HandleAPIError(w, r, apierrors.NewErrInternal(err))
+				return
+			}
+		}
+	}
+
 	// if a basic integration is specified, verify that it exists in the project
 	if request.BasicIntegrationID != 0 {
 		_, err := p.Repo().BasicIntegration().ReadBasicIntegration(proj.ID, request.BasicIntegrationID)