@@ -2,7 +2,6 @@ package cmd
22
33import (
44 "context"
5- "encoding/json"
65 "fmt"
76 "os"
87 "strings"
@@ -84,29 +83,6 @@ var ingressDeleteCmd = cli.Command{
8483 HideHelpCommand : true ,
8584}
8685
87- // ingressRule is a custom type to include TLS fields not yet in the SDK
88- type ingressRule struct {
89- Match ingressMatch `json:"match"`
90- Target ingressTarget `json:"target"`
91- TLS bool `json:"tls,omitempty"`
92- RedirectHTTP bool `json:"redirect_http,omitempty"`
93- }
94-
95- type ingressMatch struct {
96- Hostname string `json:"hostname"`
97- Port int64 `json:"port,omitempty"`
98- }
99-
100- type ingressTarget struct {
101- Instance string `json:"instance"`
102- Port int64 `json:"port"`
103- }
104-
105- type ingressCreateRequest struct {
106- Name string `json:"name"`
107- Rules []ingressRule `json:"rules"`
108- }
109-
11086func handleIngressCreate (ctx context.Context , cmd * cli.Command ) error {
11187 args := cmd .Args ().Slice ()
11288 if len (args ) < 1 {
@@ -133,35 +109,27 @@ func handleIngressCreate(ctx context.Context, cmd *cli.Command) error {
133109 opts = append (opts , debugMiddlewareOption )
134110 }
135111
136- // Build custom request body to include TLS fields
137- reqBody := ingressCreateRequest {
112+ params := hypeman.IngressNewParams {
138113 Name : name ,
139- Rules : []ingressRule {
114+ Rules : []hypeman. IngressRuleParam {
140115 {
141- Match : ingressMatch {
116+ Match : hypeman. IngressMatchParam {
142117 Hostname : hostname ,
143- Port : int64 (hostPort ),
118+ Port : hypeman . Int ( int64 (hostPort ) ),
144119 },
145- Target : ingressTarget {
120+ Target : hypeman. IngressTargetParam {
146121 Instance : instance ,
147122 Port : int64 (port ),
148123 },
149- TLS : tls ,
150- RedirectHTTP : redirectHTTP ,
124+ Tls : hypeman . Bool ( tls ) ,
125+ RedirectHTTP : hypeman . Bool ( redirectHTTP ) ,
151126 },
152127 },
153128 }
154129
155- bodyBytes , err := json .Marshal (reqBody )
156- if err != nil {
157- return fmt .Errorf ("failed to marshal request: %w" , err )
158- }
159-
160- opts = append (opts , option .WithRequestBody ("application/json" , bodyBytes ))
161-
162130 fmt .Fprintf (os .Stderr , "Creating ingress %s...\n " , name )
163131
164- result , err := client .Ingresses .New (ctx , hypeman. IngressNewParams {} , opts ... )
132+ result , err := client .Ingresses .New (ctx , params , opts ... )
165133 if err != nil {
166134 return err
167135 }
@@ -207,6 +175,11 @@ func handleIngressList(ctx context.Context, cmd *cli.Command) error {
207175 rule := ing .Rules [0 ]
208176 hostname = rule .Match .Hostname
209177 target = fmt .Sprintf ("%s:%d" , rule .Target .Instance , rule .Target .Port )
178+ if rule .Tls {
179+ tlsEnabled = "yes"
180+ } else {
181+ tlsEnabled = "no"
182+ }
210183 }
211184
212185 table .AddRow (
@@ -249,10 +222,22 @@ func handleIngressDelete(ctx context.Context, cmd *cli.Command) error {
249222
250223// generateIngressName generates an ingress name from hostname
251224func generateIngressName (hostname string ) string {
252- // Replace dots with dashes, remove invalid chars
225+ // Replace dots with dashes
253226 name := strings .ReplaceAll (hostname , "." , "-" )
254227 name = strings .ToLower (name )
255228
229+ // Remove invalid characters (only allow a-z, 0-9, and -)
230+ var cleaned strings.Builder
231+ for _ , r := range name {
232+ if (r >= 'a' && r <= 'z' ) || (r >= '0' && r <= '9' ) || r == '-' {
233+ cleaned .WriteRune (r )
234+ }
235+ }
236+ name = cleaned .String ()
237+
238+ // Trim leading/trailing dashes
239+ name = strings .Trim (name , "-" )
240+
256241 // Add random suffix
257242 suffix := randomSuffix (4 )
258243 return fmt .Sprintf ("%s-%s" , name , suffix )
0 commit comments