Skip to content

Commit e2b9ddf

Browse files
authored
relax aspire binding validation to support other schemas (#6180)
1 parent 5e71100 commit e2b9ddf

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

cli/azd/pkg/apphost/aca_ingress.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ const (
5353
acaIngressSchemaHttp string = "http"
5454
acaIngressSchemaHttps string = "https"
5555
acaIngressTransportHttp2 string = "http2"
56-
acaIngressTransportHttp string = "http"
5756
acaDefaultHttpPort string = "80"
5857
acaDefaultHttpsPort string = "443"
5958
// a target port that is resolved at deployment time
@@ -70,15 +69,13 @@ func validateBindings(bindings custommaps.WithOrder[Binding]) error {
7069
return fmt.Errorf("binding %q is empty", name)
7170
}
7271

73-
switch binding.Scheme {
74-
case acaIngressSchemaTcp:
72+
// TCP scheme requires a target port to be specified
73+
// Note: We check for TCP specifically since other schemes (http, https, redis, postgres, etc.)
74+
// can work without explicit target ports in some scenarios
75+
if binding.Scheme == acaIngressSchemaTcp {
7576
if binding.TargetPort == nil {
7677
return fmt.Errorf("binding %q has scheme %q but no container port", name, binding.Scheme)
7778
}
78-
case acaIngressSchemaHttp:
79-
case acaIngressSchemaHttps:
80-
default:
81-
return fmt.Errorf("binding %q has invalid scheme %q", name, binding.Scheme)
8279
}
8380
}
8481

cli/azd/pkg/apphost/aca_ingress_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func TestBuildAcaIngress(t *testing.T) {
134134
assert.Equal(t, []string{"http"}, ingressBinding)
135135
})
136136

137-
t.Run("invalid schema", func(t *testing.T) {
137+
t.Run("invalid_schema", func(t *testing.T) {
138138
bindingsManifest := `{
139139
"http": {
140140
"scheme": "invalid",
@@ -145,11 +145,14 @@ func TestBuildAcaIngress(t *testing.T) {
145145
err := json.Unmarshal([]byte(bindingsManifest), &bindings)
146146
assert.NoError(t, err)
147147

148+
// Custom schemes are now allowed (e.g., redis, postgres, etc.)
149+
// The scheme should be treated as non-HTTP and use TCP transport
148150
ingress, ingressBinding, err := buildAcaIngress(bindings, 8080)
149-
assert.Error(t, err)
150-
assert.EqualError(t, err, `binding "http" has invalid scheme "invalid"`)
151-
assert.Nil(t, ingress)
152-
assert.Equal(t, []string(nil), ingressBinding)
151+
assert.NoError(t, err)
152+
assert.NotNil(t, ingress)
153+
assert.Equal(t, "tcp", ingress.Transport)
154+
assert.Equal(t, 33, ingress.TargetPort)
155+
assert.Equal(t, []string{"http"}, ingressBinding)
153156
})
154157

155158
t.Run("additional ports", func(t *testing.T) {

0 commit comments

Comments
 (0)