|
@@ -10,7 +10,6 @@ import (
|
|
|
"github.com/google/go-github/v41/github"
|
|
"github.com/google/go-github/v41/github"
|
|
|
"github.com/porter-dev/porter/api/server/authz"
|
|
"github.com/porter-dev/porter/api/server/authz"
|
|
|
"github.com/porter-dev/porter/api/server/handlers"
|
|
"github.com/porter-dev/porter/api/server/handlers"
|
|
|
- "github.com/porter-dev/porter/api/server/handlers/gitinstallation"
|
|
|
|
|
"github.com/porter-dev/porter/api/server/shared"
|
|
"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/apierrors"
|
|
|
"github.com/porter-dev/porter/api/server/shared/config"
|
|
"github.com/porter-dev/porter/api/server/shared/config"
|
|
@@ -40,33 +39,7 @@ func (c *DeleteDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
project, _ := r.Context().Value(types.ProjectScope).(*models.Project)
|
|
project, _ := r.Context().Value(types.ProjectScope).(*models.Project)
|
|
|
cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
|
|
cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
|
|
|
|
|
|
|
|
- envID, reqErr := requestutils.GetURLParamUint(r, "environment_id")
|
|
|
|
|
-
|
|
|
|
|
- if reqErr != nil {
|
|
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(reqErr))
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // check that the environment belongs to the project and cluster IDs
|
|
|
|
|
- env, err := c.Repo().Environment().ReadEnvironmentByID(project.ID, cluster.ID, envID)
|
|
|
|
|
-
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrForbidden(fmt.Errorf("environment id not found in cluster and project")))
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrInternal(reqErr))
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- owner, name, ok := gitinstallation.GetOwnerAndNameParams(c, w, r)
|
|
|
|
|
-
|
|
|
|
|
- if !ok {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- prNumber, reqErr := requestutils.GetURLParamUint(r, "pr_number")
|
|
|
|
|
|
|
+ deplID, reqErr := requestutils.GetURLParamUint(r, "deployment_id")
|
|
|
|
|
|
|
|
if reqErr != nil {
|
|
if reqErr != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(reqErr))
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(reqErr))
|
|
@@ -74,7 +47,7 @@ func (c *DeleteDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// read the deployment
|
|
// read the deployment
|
|
|
- depl, err := c.Repo().Environment().ReadDeploymentByGitDetails(envID, owner, name, prNumber)
|
|
|
|
|
|
|
+ depl, err := c.Repo().Environment().ReadDeploymentByID(project.ID, cluster.ID, deplID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
@@ -99,6 +72,19 @@ func (c *DeleteDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Reque
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ // check that the environment belongs to the project and cluster IDs
|
|
|
|
|
+ env, err := c.Repo().Environment().ReadEnvironmentByID(project.ID, cluster.ID, depl.EnvironmentID)
|
|
|
|
|
+
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrForbidden(fmt.Errorf("environment id not found in cluster and project")))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(reqErr))
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
client, err := getGithubClientFromEnvironment(c.Config(), env)
|
|
client, err := getGithubClientFromEnvironment(c.Config(), env)
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|