delete_gitlab.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package project_integration
  2. import (
  3. "fmt"
  4. "net/http"
  5. ints "github.com/porter-dev/porter/internal/models/integrations"
  6. "github.com/porter-dev/porter/api/server/handlers"
  7. "github.com/porter-dev/porter/api/server/shared"
  8. "github.com/porter-dev/porter/api/server/shared/apierrors"
  9. "github.com/porter-dev/porter/api/server/shared/config"
  10. "github.com/porter-dev/porter/api/types"
  11. )
  12. type DeleteGitlabIntegration struct {
  13. handlers.PorterHandlerReadWriter
  14. }
  15. func NewDeleteGitlabIntegrationHandler(
  16. config *config.Config,
  17. decoderValidator shared.RequestDecoderValidator,
  18. writer shared.ResultWriter,
  19. ) *DeleteGitlabIntegration {
  20. return &DeleteGitlabIntegration{
  21. PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer),
  22. }
  23. }
  24. func (p *DeleteGitlabIntegration) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  25. gi, _ := r.Context().Value(types.GitlabIntegrationScope).(*ints.GitlabIntegration)
  26. metadata := p.Config().Metadata
  27. if !metadata.Gitlab {
  28. p.HandleAPIError(w, r, apierrors.NewErrForbidden(fmt.Errorf("gitlab integration endpoints are not enabled")))
  29. return
  30. }
  31. err := p.Repo().GitlabIntegration().DeleteGitlabIntegrationByID(gi.ProjectID, gi.ID)
  32. if err != nil {
  33. p.HandleAPIError(w, r, apierrors.NewErrInternal(fmt.Errorf("error deleting gitlab integration: %w", err)))
  34. return
  35. }
  36. return
  37. }