|
|
@@ -9,6 +9,7 @@ import (
|
|
|
"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/telemetry"
|
|
|
@@ -32,7 +33,8 @@ func NewUpdateAppBuildSettingsHandler(
|
|
|
|
|
|
// UpdateAppBuildSettingsRequest is the request object for the POST /apps/{porter_app_name}/build endpoint
|
|
|
type UpdateAppBuildSettingsRequest struct {
|
|
|
- BuildSettings BuildSettings `json:"build_settings"`
|
|
|
+ DeploymentTargetID string `json:"deployment_target_id"`
|
|
|
+ BuildSettings BuildSettings `json:"build_settings"`
|
|
|
}
|
|
|
|
|
|
// UpdateAppBuildSettingsResponse is the response object for the POST /apps/{porter_app_name}/build endpoint
|
|
|
@@ -45,6 +47,13 @@ func (c *UpdateAppBuildSettingsHandler) ServeHTTP(w http.ResponseWriter, r *http
|
|
|
|
|
|
project, _ := ctx.Value(types.ProjectScope).(*models.Project)
|
|
|
|
|
|
+ appName, reqErr := requestutils.GetURLParamString(r, types.URLParamPorterAppName)
|
|
|
+ if reqErr != nil {
|
|
|
+ e := telemetry.Error(ctx, span, reqErr, "error parsing app name from url")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(e, http.StatusBadRequest))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
// read the request object from the decoder
|
|
|
request := &UpdateAppBuildSettingsRequest{}
|
|
|
if ok := c.DecodeAndValidate(w, r, request); !ok {
|
|
|
@@ -53,8 +62,20 @@ func (c *UpdateAppBuildSettingsHandler) ServeHTTP(w http.ResponseWriter, r *http
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+ if request.DeploymentTargetID == "" {
|
|
|
+ err := telemetry.Error(ctx, span, nil, "deployment target id is empty")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if request.BuildSettings.Method == "" {
|
|
|
+ err := telemetry.Error(ctx, span, nil, "build method must be specified")
|
|
|
+ c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
updateReq := connect.NewRequest(&porterv1.UpdateAppBuildSettingsRequest{
|
|
|
ProjectId: int64(project.ID),
|
|
|
+ AppName: appName,
|
|
|
Build: &porterv1.Build{
|
|
|
Method: request.BuildSettings.Method,
|
|
|
Context: request.BuildSettings.Context,
|
|
|
@@ -63,6 +84,9 @@ func (c *UpdateAppBuildSettingsHandler) ServeHTTP(w http.ResponseWriter, r *http
|
|
|
Buildpacks: request.BuildSettings.Buildpacks,
|
|
|
CommitSha: request.BuildSettings.CommitSHA,
|
|
|
},
|
|
|
+ DeploymentTargetIdentifier: &porterv1.DeploymentTargetIdentifier{
|
|
|
+ Id: request.DeploymentTargetID,
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
ccpResp, err := c.Config().ClusterControlPlaneClient.UpdateAppBuildSettings(ctx, updateReq)
|