create_integration.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package saml
  2. import (
  3. "errors"
  4. "net/http"
  5. "github.com/porter-dev/porter/api/server/handlers"
  6. "github.com/porter-dev/porter/api/server/shared"
  7. "github.com/porter-dev/porter/api/server/shared/apierrors"
  8. "github.com/porter-dev/porter/api/server/shared/config"
  9. "github.com/porter-dev/porter/api/types"
  10. "github.com/porter-dev/porter/internal/models"
  11. )
  12. type CreateSAMLIntegrationHandler struct {
  13. handlers.PorterHandlerReadWriter
  14. }
  15. func NewCreateSAMLIntegrationHandler(
  16. config *config.Config,
  17. decoderValidator shared.RequestDecoderValidator,
  18. writer shared.ResultWriter,
  19. ) *CreateSAMLIntegrationHandler {
  20. return &CreateSAMLIntegrationHandler{
  21. PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer),
  22. }
  23. }
  24. func (h *CreateSAMLIntegrationHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
  25. project, _ := r.Context().Value(types.ProjectScope).(*models.Project)
  26. if !project.SAMLSSOEnabled {
  27. h.HandleAPIError(w, r, apierrors.NewErrForbidden(errors.New("SAML SSO is not enabled for this project")))
  28. return
  29. }
  30. // FIXME: check if user has necessary permissions to make this request with RBAC
  31. }