Skip to content

Commit

Permalink
Merge branch 'master' into dgtown/add-gcp-instance
Browse files Browse the repository at this point in the history
  • Loading branch information
portersupport authored May 22, 2024
2 parents 855ca8b + 19f85ef commit 5049ba4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
5 changes: 3 additions & 2 deletions api/client/deployment_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"

"github.com/google/uuid"
"github.com/porter-dev/porter/api/types"
)

Expand Down Expand Up @@ -49,10 +50,10 @@ func (c *Client) ListDeploymentTargets(
func (c *Client) DeleteDeploymentTarget(
ctx context.Context,
projectId uint,
deploymentTargetName string,
deploymentTargetID uuid.UUID,
) error {
return c.deleteRequest(
fmt.Sprintf("/projects/%d/targets/%s", projectId, deploymentTargetName),
fmt.Sprintf("/projects/%d/targets/%s", projectId, deploymentTargetID.String()),
nil,
nil,
)
Expand Down
20 changes: 19 additions & 1 deletion cli/cmd/commands/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"text/tabwriter"

"github.com/fatih/color"
"github.com/google/uuid"
api "github.com/porter-dev/porter/api/client"
"github.com/porter-dev/porter/api/types"
"github.com/porter-dev/porter/cli/cmd/config"
Expand Down Expand Up @@ -171,7 +172,24 @@ func deleteTarget(ctx context.Context, _ *types.GetAuthenticatedUserResponse, cl
return nil
}

err = client.DeleteDeploymentTarget(ctx, cliConf.Project, name)
// assume deletion will be for preview environments only for now
dts, err := client.ListDeploymentTargets(ctx, cliConf.Project, true)
if err != nil {
return fmt.Errorf("error listing targets: %w", err)
}

var targetID uuid.UUID
for _, dt := range dts.DeploymentTargets {
if dt.Name == name {
targetID = dt.ID
break
}
}
if targetID == uuid.Nil {
return fmt.Errorf("target '%s' not found", name)
}

err = client.DeleteDeploymentTarget(ctx, cliConf.Project, targetID)
if err != nil {
return fmt.Errorf("error deleting target: %w", err)
}
Expand Down

0 comments on commit 5049ba4

Please sign in to comment.