-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
5c54721
commit 6c9c760
Showing
26 changed files
with
992 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package deployment_target | ||
|
||
import ( | ||
"net/http" | ||
|
||
"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/config" | ||
"github.com/porter-dev/porter/api/types" | ||
"github.com/porter-dev/porter/internal/models" | ||
"github.com/porter-dev/porter/internal/telemetry" | ||
) | ||
|
||
// ListDeploymentTargetsHandler is the handler for the /deployment-targets endpoint | ||
type ListDeploymentTargetsHandler struct { | ||
handlers.PorterHandlerReadWriter | ||
} | ||
|
||
// NewListDeploymentTargetsHandler handles GET requests to the endpoint /deployment-targets | ||
func NewListDeploymentTargetsHandler( | ||
config *config.Config, | ||
decoderValidator shared.RequestDecoderValidator, | ||
writer shared.ResultWriter, | ||
) *ListDeploymentTargetsHandler { | ||
return &ListDeploymentTargetsHandler{ | ||
PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer), | ||
} | ||
} | ||
|
||
// ListDeploymentTargetsRequest is the request object for the /deployment-targets GET endpoint | ||
type ListDeploymentTargetsRequest struct { | ||
Preview bool `json:"preview"` | ||
} | ||
|
||
// ListDeploymentTargetsResponse is the response object for the /deployment-targets GET endpoint | ||
type ListDeploymentTargetsResponse struct { | ||
DeploymentTargets []types.DeploymentTarget `json:"deployment_targets"` | ||
} | ||
|
||
func (c *ListDeploymentTargetsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
ctx, span := telemetry.NewSpan(r.Context(), "serve-list-deployment-targets") | ||
defer span.End() | ||
|
||
project, _ := ctx.Value(types.ProjectScope).(*models.Project) | ||
cluster, _ := ctx.Value(types.ClusterScope).(*models.Cluster) | ||
|
||
if !project.GetFeatureFlag(models.ValidateApplyV2, c.Config().LaunchDarklyClient) { | ||
err := telemetry.Error(ctx, span, nil, "project does not have validate apply v2 enabled") | ||
c.HandleAPIError(w, r, apierrors.NewErrForbidden(err)) | ||
return | ||
} | ||
|
||
request := &ListDeploymentTargetsRequest{} | ||
if ok := c.DecodeAndValidate(w, r, request); !ok { | ||
err := telemetry.Error(ctx, span, nil, "error decoding request") | ||
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest)) | ||
return | ||
} | ||
|
||
deploymentTargets, err := c.Repo().DeploymentTarget().List(project.ID, cluster.ID, request.Preview) | ||
if err != nil { | ||
err := telemetry.Error(ctx, span, err, "error retrieving deployment targets") | ||
c.HandleAPIError(w, r, apierrors.NewErrInternal(err)) | ||
return | ||
} | ||
|
||
response := ListDeploymentTargetsResponse{ | ||
DeploymentTargets: make([]types.DeploymentTarget, 0), | ||
} | ||
|
||
for _, dt := range deploymentTargets { | ||
if dt == nil { | ||
continue | ||
} | ||
|
||
response.DeploymentTargets = append(response.DeploymentTargets, *dt.ToDeploymentTargetType()) | ||
} | ||
|
||
c.WriteResult(w, r, response) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package types | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/google/uuid" | ||
) | ||
|
||
// DeploymentTarget is a struct that represents a unique cluster, namespace pair that a Porter app is deployed to. | ||
type DeploymentTarget struct { | ||
ID uuid.UUID `json:"id"` | ||
ProjectID uint `json:"project_id"` | ||
ClusterID uint `json:"cluster_id"` | ||
|
||
Selector string `json:"selector"` | ||
SelectorType string `json:"selector_type"` | ||
CreatedAt time.Time `json:"created_at"` | ||
UpdatedAt time.Time `json:"updated_at"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.