|
|
@@ -3,13 +3,13 @@ package project_oauth
|
|
|
import (
|
|
|
"fmt"
|
|
|
"net/http"
|
|
|
+ "strconv"
|
|
|
|
|
|
"github.com/porter-dev/porter/api/server/handlers"
|
|
|
"github.com/porter-dev/porter/api/server/shared"
|
|
|
"github.com/porter-dev/porter/api/server/shared/apierrors"
|
|
|
"github.com/porter-dev/porter/api/server/shared/commonutils"
|
|
|
"github.com/porter-dev/porter/api/server/shared/config"
|
|
|
- "github.com/porter-dev/porter/api/server/shared/requestutils"
|
|
|
"github.com/porter-dev/porter/api/types"
|
|
|
"github.com/porter-dev/porter/internal/models"
|
|
|
"github.com/porter-dev/porter/internal/oauth"
|
|
|
@@ -34,14 +34,21 @@ func NewProjectOAuthGitlabHandler(
|
|
|
func (p *ProjectOAuthGitlabHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
proj, _ := r.Context().Value(types.ProjectScope).(*models.Project)
|
|
|
|
|
|
- integrationID, reqErr := requestutils.GetURLParamUint(r, "integration_id")
|
|
|
+ integrationIDStr := r.URL.Query().Get("integration_id")
|
|
|
|
|
|
- if reqErr != nil {
|
|
|
- p.HandleAPIError(w, r, reqErr)
|
|
|
+ if len(integrationIDStr) == 0 {
|
|
|
+ p.HandleAPIError(w, r, apierrors.NewErrForbidden(fmt.Errorf("required query param integration_id")))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- giIntegration, err := p.Repo().GitlabIntegration().ReadGitlabIntegration(proj.ID, integrationID)
|
|
|
+ integrationID, err := strconv.ParseUint(integrationIDStr, 10, 32)
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ p.HandleAPIError(w, r, apierrors.NewErrForbidden(err))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ giIntegration, err := p.Repo().GitlabIntegration().ReadGitlabIntegration(proj.ID, uint(integrationID))
|
|
|
|
|
|
if err != nil {
|
|
|
if err == gorm.ErrRecordNotFound {
|
|
|
@@ -57,7 +64,7 @@ func (p *ProjectOAuthGitlabHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
|
|
|
|
|
|
state := oauth.CreateRandomState()
|
|
|
|
|
|
- if err := p.PopulateOAuthSession(w, r, state, true, true, types.OAuthGitlab, integrationID); err != nil {
|
|
|
+ if err := p.PopulateOAuthSession(w, r, state, true, true, types.OAuthGitlab, uint(integrationID)); err != nil {
|
|
|
p.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
return
|
|
|
}
|