Skip to content

Commit dc370b5

Browse files
feat: Support TLS for ingress
1 parent d3163ff commit dc370b5

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 24
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fhypeman-6a8902e840cc8f443018c06b23884d3b42e45181c1ac156f5cf56cac84b717ee.yml
3-
openapi_spec_hash: d1535b5fdc9d097940928f0689c8baa1
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/kernel%2Fhypeman-5949b3d0dabd8e0b10afddb388b6f0ea66c44b0f383e28d49bcd81b22b021dee.yml
3+
openapi_spec_hash: 9e9e6964a4cafc48e3cff37d918d0889
44
config_hash: 510018ffa6ad6a17875954f66fe69598

ingress.go

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,14 @@ func (r *Ingress) UnmarshalJSON(data []byte) error {
105105
}
106106

107107
type IngressMatch struct {
108-
// Hostname to match (exact match on Host header)
108+
// Hostname to match. Can be:
109+
//
110+
// - Literal: "api.example.com" (exact match on Host header)
111+
// - Pattern: "{instance}.example.com" (dynamic routing based on subdomain)
112+
//
113+
// Pattern hostnames use named captures in curly braces (e.g., {instance}, {app})
114+
// that extract parts of the hostname for routing. The extracted values can be
115+
// referenced in the target.instance field.
109116
Hostname string `json:"hostname,required"`
110117
// Host port to listen on for this rule (default 80)
111118
Port int64 `json:"port"`
@@ -135,7 +142,14 @@ func (r IngressMatch) ToParam() IngressMatchParam {
135142

136143
// The property Hostname is required.
137144
type IngressMatchParam struct {
138-
// Hostname to match (exact match on Host header)
145+
// Hostname to match. Can be:
146+
//
147+
// - Literal: "api.example.com" (exact match on Host header)
148+
// - Pattern: "{instance}.example.com" (dynamic routing based on subdomain)
149+
//
150+
// Pattern hostnames use named captures in curly braces (e.g., {instance}, {app})
151+
// that extract parts of the hostname for routing. The extracted values can be
152+
// referenced in the target.instance field.
139153
Hostname string `json:"hostname,required"`
140154
// Host port to listen on for this rule (default 80)
141155
Port param.Opt[int64] `json:"port,omitzero"`
@@ -153,12 +167,19 @@ func (r *IngressMatchParam) UnmarshalJSON(data []byte) error {
153167
type IngressRule struct {
154168
Match IngressMatch `json:"match,required"`
155169
Target IngressTarget `json:"target,required"`
170+
// Auto-create HTTP to HTTPS redirect for this hostname (only applies when tls is
171+
// enabled)
172+
RedirectHTTP bool `json:"redirect_http"`
173+
// Enable TLS termination (certificate auto-issued via ACME).
174+
Tls bool `json:"tls"`
156175
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
157176
JSON struct {
158-
Match respjson.Field
159-
Target respjson.Field
160-
ExtraFields map[string]respjson.Field
161-
raw string
177+
Match respjson.Field
178+
Target respjson.Field
179+
RedirectHTTP respjson.Field
180+
Tls respjson.Field
181+
ExtraFields map[string]respjson.Field
182+
raw string
162183
} `json:"-"`
163184
}
164185

@@ -181,6 +202,11 @@ func (r IngressRule) ToParam() IngressRuleParam {
181202
type IngressRuleParam struct {
182203
Match IngressMatchParam `json:"match,omitzero,required"`
183204
Target IngressTargetParam `json:"target,omitzero,required"`
205+
// Auto-create HTTP to HTTPS redirect for this hostname (only applies when tls is
206+
// enabled)
207+
RedirectHTTP param.Opt[bool] `json:"redirect_http,omitzero"`
208+
// Enable TLS termination (certificate auto-issued via ACME).
209+
Tls param.Opt[bool] `json:"tls,omitzero"`
184210
paramObj
185211
}
186212

@@ -193,7 +219,14 @@ func (r *IngressRuleParam) UnmarshalJSON(data []byte) error {
193219
}
194220

195221
type IngressTarget struct {
196-
// Target instance name or ID
222+
// Target instance name, ID, or capture reference.
223+
//
224+
// - For literal hostnames: Use the instance name or ID directly (e.g., "my-api")
225+
// - For pattern hostnames: Reference a capture from the hostname (e.g.,
226+
// "{instance}")
227+
//
228+
// When using pattern hostnames, the instance is resolved dynamically at request
229+
// time.
197230
Instance string `json:"instance,required"`
198231
// Target port on the instance
199232
Port int64 `json:"port,required"`
@@ -223,7 +256,14 @@ func (r IngressTarget) ToParam() IngressTargetParam {
223256

224257
// The properties Instance, Port are required.
225258
type IngressTargetParam struct {
226-
// Target instance name or ID
259+
// Target instance name, ID, or capture reference.
260+
//
261+
// - For literal hostnames: Use the instance name or ID directly (e.g., "my-api")
262+
// - For pattern hostnames: Reference a capture from the hostname (e.g.,
263+
// "{instance}")
264+
//
265+
// When using pattern hostnames, the instance is resolved dynamically at request
266+
// time.
227267
Instance string `json:"instance,required"`
228268
// Target port on the instance
229269
Port int64 `json:"port,required"`

ingress_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ func TestIngressNew(t *testing.T) {
3030
Name: "my-api-ingress",
3131
Rules: []hypeman.IngressRuleParam{{
3232
Match: hypeman.IngressMatchParam{
33-
Hostname: "api.example.com",
33+
Hostname: "{instance}.example.com",
3434
Port: hypeman.Int(8080),
3535
},
3636
Target: hypeman.IngressTargetParam{
37-
Instance: "my-api",
37+
Instance: "{instance}",
3838
Port: 8080,
3939
},
40+
RedirectHTTP: hypeman.Bool(true),
41+
Tls: hypeman.Bool(true),
4042
}},
4143
})
4244
if err != nil {

0 commit comments

Comments
 (0)