|
|
@@ -8,13 +8,12 @@ import (
|
|
|
"github.com/google/go-github/v41/github"
|
|
|
"github.com/porter-dev/porter/api/server/authz"
|
|
|
"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/apierrors"
|
|
|
"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/models/integrations"
|
|
|
)
|
|
|
|
|
|
type DeleteDeploymentHandler struct {
|
|
|
@@ -34,32 +33,26 @@ func NewDeleteDeploymentHandler(
|
|
|
}
|
|
|
|
|
|
func (c *DeleteDeploymentHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
- ga, _ := r.Context().Value(types.GitInstallationScope).(*integrations.GithubAppInstallation)
|
|
|
project, _ := r.Context().Value(types.ProjectScope).(*models.Project)
|
|
|
cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster)
|
|
|
|
|
|
- owner, name, ok := gitinstallation.GetOwnerAndNameParams(c, w, r)
|
|
|
+ deplID, reqErr := requestutils.GetURLParamUint(r, "deployment_id")
|
|
|
|
|
|
- if !ok {
|
|
|
+ if reqErr != nil {
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrInternal(reqErr))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- request := &types.DeleteDeploymentRequest{}
|
|
|
-
|
|
|
- if ok := c.DecodeAndValidate(w, r, request); !ok {
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // read the environment to get the environment id
|
|
|
- env, err := c.Repo().Environment().ReadEnvironment(project.ID, cluster.ID, uint(ga.InstallationID), owner, name)
|
|
|
+ // read the deployment
|
|
|
+ depl, err := c.Repo().Environment().ReadDeploymentByID(deplID)
|
|
|
|
|
|
if err != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- // read the deployment
|
|
|
- depl, err := c.Repo().Environment().ReadDeployment(env.ID, request.Namespace)
|
|
|
+ // read the environment to get the environment id
|
|
|
+ env, err := c.Repo().Environment().ReadEnvironmentByID(project.ID, cluster.ID, depl.EnvironmentID)
|
|
|
|
|
|
if err != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|