Skip to content

Commit d876300

Browse files
committed
refactor: consolidate handling of maskRequestHost logic
1 parent 8d740e0 commit d876300

File tree

5 files changed

+83
-87
lines changed

5 files changed

+83
-87
lines changed

packages/api/internal/api/spec.gen.go

Lines changed: 61 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api/internal/api/types.gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api/internal/handlers/sandbox_create.go

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -159,33 +159,29 @@ func (a *APIStore) PostSandboxes(c *gin.Context) {
159159
envdAccessToken = &accessToken
160160
}
161161

162-
var maskRequestHost *string = nil
163-
if body.Network != nil && body.Network.MaskRequestHost != nil {
164-
host := *body.Network.MaskRequestHost
165-
166-
hostname, _, err := splitHostPortOptional(host)
167-
if err != nil {
168-
telemetry.ReportError(ctx, "error when splitting mask request host", err, telemetry.WithSandboxID(sandboxID))
169-
a.sendAPIStoreError(c, http.StatusBadRequest, fmt.Sprintf("Invalid mask request host: %s", err))
170-
171-
return
172-
}
173-
174-
_, err = idna.Display.ToUnicode(hostname)
175-
if err != nil {
176-
telemetry.ReportError(ctx, "error when parsing mask request host", err, telemetry.WithSandboxID(sandboxID))
177-
a.sendAPIStoreError(c, http.StatusBadRequest, fmt.Sprintf("Invalid mask request host: %s", err))
178-
179-
return
180-
}
181-
182-
maskRequestHost = &host
183-
}
184-
185162
allowInternetAccess := body.AllowInternetAccess
186163

187164
var network *types.SandboxNetworkConfig
188165
if body.Network != nil {
166+
maskRequestHost := body.Network.MaskRequestHost
167+
if maskRequestHost != nil {
168+
hostname, _, err := splitHostPortOptional(*maskRequestHost)
169+
if err != nil {
170+
telemetry.ReportError(ctx, "error when splitting mask request host", err, telemetry.WithSandboxID(sandboxID))
171+
a.sendAPIStoreError(c, http.StatusBadRequest, fmt.Sprintf("Invalid mask request host: %s", err))
172+
173+
return
174+
}
175+
176+
_, err = idna.Display.ToUnicode(hostname)
177+
if err != nil {
178+
telemetry.ReportError(ctx, "error when parsing mask request host", err, telemetry.WithSandboxID(sandboxID))
179+
a.sendAPIStoreError(c, http.StatusBadRequest, fmt.Sprintf("Invalid mask request host: %s", err))
180+
181+
return
182+
}
183+
}
184+
189185
network = &types.SandboxNetworkConfig{
190186
Ingress: &types.SandboxNetworkIngressConfig{
191187
AllowPublicAccess: sharedUtils.DerefOrDefault(body.Network.AllowPublicTraffic, true),

spec/openapi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ components:
236236
type: string
237237
maskRequestHost:
238238
type: string
239-
description: Specify all sandbox requests host mask.
239+
description: Specify host mask which will be used for all sandbox requests
240240

241241
SandboxLog:
242242
description: Log entry with timestamp and line

tests/integration/internal/api/models.gen.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)