Skip to content

Commit 73535ff

Browse files
authored
App update with addons (#4041)
1 parent 35c4979 commit 73535ff

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

api/server/handlers/porter_app/update_app.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ type UpdateAppRequest struct {
6060
// Only one of Base64AppProto or Base64PorterYAML should be specified
6161
// Base64AppProto is a ful base64 encoded porter app contract to apply
6262
Base64AppProto string `json:"b64_app_proto"`
63+
// Base64AddonProtos is a list of base64 encoded addon contracts to apply along with the app
64+
Base64AddonProtos []string `json:"b64_addon_protos"`
6365
// Base64PorterYAML is a base64 encoded porter yaml to apply representing a potentially partial porter app contract
6466
Base64PorterYAML string `json:"b64_porter_yaml"`
6567
// 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,
@@ -109,6 +111,7 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
109111
telemetry.AttributeKV{Key: "is-env-override", Value: request.IsEnvOverride},
110112
)
111113

114+
var addons []*porterv1.Addon
112115
var overrides *porterv1.PorterApp
113116
appProto := &porterv1.PorterApp{}
114117

@@ -131,6 +134,25 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
131134
}
132135
}
133136

137+
for _, b64AddonProto := range request.Base64AddonProtos {
138+
decoded, err := base64.StdEncoding.DecodeString(b64AddonProto)
139+
if err != nil {
140+
err := telemetry.Error(ctx, span, err, "error decoding base yaml")
141+
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
142+
return
143+
}
144+
145+
addon := &porterv1.Addon{}
146+
err = helpers.UnmarshalContractObject(decoded, addon)
147+
if err != nil {
148+
err := telemetry.Error(ctx, span, err, "error unmarshalling addon proto")
149+
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
150+
return
151+
}
152+
153+
addons = append(addons, addon)
154+
}
155+
134156
if request.Base64PorterYAML != "" {
135157
decoded, err := base64.StdEncoding.DecodeString(request.Base64PorterYAML)
136158
if err != nil {
@@ -154,6 +176,8 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
154176
overrides = appFromYaml.PreviewApp.AppProto
155177
envVariables = mergeEnvVariables(envVariables, appFromYaml.PreviewApp.EnvVariables)
156178
}
179+
180+
addons = appFromYaml.Addons
157181
}
158182

159183
if appProto.Name == "" {
@@ -223,6 +247,7 @@ func (c *UpdateAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
223247
AppOverrides: overrides,
224248
CommitSha: request.CommitSHA,
225249
IsEnvOverride: request.IsEnvOverride,
250+
Addons: addons,
226251
})
227252

228253
ccpResp, err := c.Config().ClusterControlPlaneClient.UpdateApp(ctx, updateReq)

0 commit comments

Comments
 (0)