Skip to content

Commit 195f5ed

Browse files
authored
move parse yaml back to update endpoint (#4422)
1 parent 155350f commit 195f5ed

File tree

3 files changed

+14
-30
lines changed

3 files changed

+14
-30
lines changed

api/client/porter_app.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ type UpdateAppInput struct {
221221
Variables map[string]string
222222
Secrets map[string]string
223223
Deletions porter_app.Deletions
224+
PatchOperations []v2.PatchOperation
224225
}
225226

226227
// UpdateApp updates a porter app
@@ -246,6 +247,7 @@ func (c *Client) UpdateApp(
246247
Variables: inp.Variables,
247248
Secrets: inp.Secrets,
248249
Deletions: inp.Deletions,
250+
PatchOperations: inp.PatchOperations,
249251
}
250252

251253
err := c.postRequest(

api/server/handlers/porter_app/update_app.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/porter-dev/porter/api/types"
1717
"github.com/porter-dev/porter/internal/models"
1818
"github.com/porter-dev/porter/internal/porter_app"
19+
v2 "github.com/porter-dev/porter/internal/porter_app/v2"
1920
"github.com/porter-dev/porter/internal/telemetry"
2021
)
2122

@@ -91,6 +92,8 @@ type UpdateAppRequest struct {
9192
Base64AddonProtos []string `json:"b64_addon_protos"`
9293
// Base64PorterYAML is a base64 encoded porter yaml to apply representing a potentially partial porter app contract
9394
Base64PorterYAML string `json:"b64_porter_yaml"`
95+
// PatchOperations is a set of patch operations to apply to the porter.yaml if specified
96+
PatchOperations []v2.PatchOperation `json:"patch_operations"`
9497
// IsEnvOverride is used to remove any variables that are not specified in the request. If false, the request will only update the variables specified in the request,
9598
// and leave all other variables untouched.
9699
IsEnvOverride bool `json:"is_env_override"`
@@ -209,7 +212,13 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
209212
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
210213
return
211214
}
212-
appProto = appFromYaml.AppProto
215+
216+
appProto, err = v2.PatchApp(ctx, appFromYaml.AppProto, request.PatchOperations)
217+
if err != nil {
218+
err := telemetry.Error(ctx, span, err, "error patching app proto")
219+
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
220+
return
221+
}
213222

214223
// only public variables can be defined in porter.yaml
215224
envVariables = mergeEnvVariables(request.Variables, appFromYaml.EnvVariables)

cli/cmd/v2/apply.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import (
1515

1616
"github.com/fatih/color"
1717
app_api "github.com/porter-dev/porter/api/server/handlers/porter_app"
18-
"github.com/porter-dev/porter/internal/porter_app"
1918
v2 "github.com/porter-dev/porter/internal/porter_app/v2"
20-
"gopkg.in/yaml.v3"
2119

2220
"github.com/porter-dev/porter/api/types"
2321
"github.com/porter-dev/porter/internal/models"
@@ -121,36 +119,12 @@ func Apply(ctx context.Context, inp ApplyInput) error {
121119
color.New(color.FgGreen).Printf("Using Porter YAML at path: %s\n", inp.PorterYamlPath) // nolint:errcheck,gosec
122120
}
123121

124-
if b64YAML == "" {
125-
color.New(color.FgGreen).Printf("No Porter YAML found, using default configuration...\n") // nolint:errcheck,gosec
126-
if inp.AppName == "" {
127-
return errors.New("no porter yaml found and app name not specified")
128-
}
129-
130-
app := v2.PorterApp{
131-
Version: string(porter_app.PorterYamlVersion_V2),
132-
Name: inp.AppName,
133-
}
134-
135-
by, err := yaml.Marshal(app)
136-
if err != nil {
137-
return fmt.Errorf("error marshaling default porter yaml: %w", err)
138-
}
139-
140-
b64YAML = base64.StdEncoding.EncodeToString(by)
141-
}
142-
143122
commitSHA := commitSHAFromEnv()
144123
gitSource, err := gitSourceFromEnv()
145124
if err != nil {
146125
return fmt.Errorf("error getting git source from env: %w", err)
147126
}
148127

149-
parseRes, err := client.ParseYAML(ctx, cliConf.Project, cliConf.Cluster, b64YAML, inp.AppName, inp.PatchOperations)
150-
if err != nil {
151-
return fmt.Errorf("error parsing porter yaml: %w", err)
152-
}
153-
154128
updateInput := api.UpdateAppInput{
155129
ProjectID: cliConf.Project,
156130
ClusterID: cliConf.Cluster,
@@ -159,11 +133,10 @@ func Apply(ctx context.Context, inp ApplyInput) error {
159133
GitSource: gitSource,
160134
DeploymentTargetId: deploymentTargetID,
161135
CommitSHA: commitSHA,
162-
Base64AppProto: parseRes.B64AppProto,
163-
Variables: parseRes.EnvVariables,
164-
Secrets: parseRes.EnvSecrets,
136+
Base64PorterYAML: b64YAML,
165137
WithPredeploy: inp.WithPredeploy,
166138
Exact: inp.Exact,
139+
PatchOperations: inp.PatchOperations,
167140
}
168141

169142
updateResp, err := client.UpdateApp(ctx, updateInput)

0 commit comments

Comments
 (0)