|
|
@@ -1,7 +1,6 @@
|
|
|
package porter_app
|
|
|
|
|
|
import (
|
|
|
- "errors"
|
|
|
"net/http"
|
|
|
|
|
|
"github.com/porter-dev/porter/api/server/authz"
|
|
|
@@ -12,8 +11,6 @@ import (
|
|
|
"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/telemetry"
|
|
|
- "gorm.io/gorm"
|
|
|
)
|
|
|
|
|
|
type GetPorterAppHandler struct {
|
|
|
@@ -31,30 +28,16 @@ func NewGetPorterAppHandler(
|
|
|
}
|
|
|
|
|
|
func (c *GetPorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|
|
- ctx, span := telemetry.NewSpan(r.Context(), "serve-get-porter-app")
|
|
|
-
|
|
|
+ ctx := r.Context()
|
|
|
cluster, _ := ctx.Value(types.ClusterScope).(*models.Cluster)
|
|
|
-
|
|
|
stackName, reqErr := requestutils.GetURLParamString(r, types.URLParamStackName)
|
|
|
if reqErr != nil {
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(reqErr, http.StatusBadRequest))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- telemetry.WithAttributes(span,
|
|
|
- telemetry.AttributeKV{Key: "cluster_id", Value: cluster.ID},
|
|
|
- telemetry.AttributeKV{Key: "project_id", Value: cluster.ProjectID},
|
|
|
- telemetry.AttributeKV{Key: "stack_name", Value: stackName},
|
|
|
- )
|
|
|
-
|
|
|
app, err := c.Repo().PorterApp().ReadPorterAppByName(cluster.ID, stackName)
|
|
|
if err != nil {
|
|
|
- if errors.Is(err, gorm.ErrRecordNotFound) {
|
|
|
- err = telemetry.Error(ctx, span, err, "porter app not found")
|
|
|
- c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusNotFound))
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
c.HandleAPIError(w, r, apierrors.NewErrInternal(err))
|
|
|
return
|
|
|
}
|