44package commands
55
66import (
7+ "context"
78 "encoding/base64"
89 "encoding/json"
910 "fmt"
@@ -166,13 +167,19 @@ func runDeployCommand(args []string, image string, fprocess string, functionName
166167 }
167168 }
168169
170+ transport := GetDefaultCLITransport (tlsInsecure , & commandTimeout )
171+ ctx := context .Background ()
172+
169173 var failedStatusCodes = make (map [string ]int )
170174 if len (services .Functions ) > 0 {
171175
172176 if len (services .Provider .Network ) == 0 {
173177 services .Provider .Network = defaultNetwork
174178 }
175179
180+ cliAuth := NewCLIAuth (token , services .Provider .GatewayURL )
181+ proxyClient := proxy .NewClient (cliAuth , services .Provider .GatewayURL , transport , & commandTimeout )
182+
176183 for k , function := range services .Functions {
177184
178185 functionSecrets := deployFlags .secrets
@@ -268,7 +275,6 @@ Error: %s`, fprocessErr.Error())
268275
269276 deploySpec := & proxy.DeployFunctionSpec {
270277 FProcess : function .FProcess ,
271- Gateway : services .Provider .GatewayURL ,
272278 FunctionName : function .Name ,
273279 Image : function .Image ,
274280 RegistryAuth : function .RegistryAuth ,
@@ -288,12 +294,10 @@ Error: %s`, fprocessErr.Error())
288294 Namespace : function .Namespace ,
289295 }
290296
291- if msg := checkTLSInsecure (deploySpec . Gateway , deploySpec .TLSInsecure ); len (msg ) > 0 {
297+ if msg := checkTLSInsecure (services . Provider . GatewayURL , deploySpec .TLSInsecure ); len (msg ) > 0 {
292298 fmt .Println (msg )
293299 }
294-
295- statusCode := proxy .DeployFunction (deploySpec )
296-
300+ statusCode := proxyClient .DeployFunction (ctx , deploySpec )
297301 if badStatusCode (statusCode ) {
298302 failedStatusCodes [k ] = statusCode
299303 }
@@ -303,6 +307,8 @@ Error: %s`, fprocessErr.Error())
303307 return fmt .Errorf ("To deploy a function give --yaml/-f or a --image and --name flag" )
304308 }
305309 gateway = getGatewayURL (gateway , defaultGateway , "" , os .Getenv (openFaaSURLEnvironment ))
310+ cliAuth := NewCLIAuth (token , gateway )
311+ proxyClient := proxy .NewClient (cliAuth , gateway , transport , & commandTimeout )
306312
307313 var registryAuth string
308314 if deployFlags .sendRegistryAuth {
@@ -317,7 +323,7 @@ Error: %s`, fprocessErr.Error())
317323 // default to a readable filesystem until we get more input about the expected behavior
318324 // and if we want to add another flag for this case
319325 defaultReadOnlyRFS := false
320- statusCode , err := deployImage (image , fprocess , functionName , registryAuth , deployFlags ,
326+ statusCode , err := deployImage (ctx , proxyClient , image , fprocess , functionName , registryAuth , deployFlags ,
321327 tlsInsecure , defaultReadOnlyRFS , token , functionNamespace )
322328 if err != nil {
323329 return err
@@ -337,6 +343,8 @@ Error: %s`, fprocessErr.Error())
337343
338344// deployImage deploys a function with the given image
339345func deployImage (
346+ ctx context.Context ,
347+ client * proxy.Client ,
340348 image string ,
341349 fprocess string ,
342350 functionName string ,
@@ -370,7 +378,6 @@ func deployImage(
370378
371379 deploySpec := & proxy.DeployFunctionSpec {
372380 FProcess : fprocess ,
373- Gateway : gateway ,
374381 FunctionName : functionName ,
375382 Image : image ,
376383 RegistryAuth : registryAuth ,
@@ -390,11 +397,11 @@ func deployImage(
390397 Namespace : namespace ,
391398 }
392399
393- if msg := checkTLSInsecure (deploySpec . Gateway , deploySpec .TLSInsecure ); len (msg ) > 0 {
400+ if msg := checkTLSInsecure (gateway , deploySpec .TLSInsecure ); len (msg ) > 0 {
394401 fmt .Println (msg )
395402 }
396403
397- statusCode = proxy .DeployFunction (deploySpec )
404+ statusCode = client .DeployFunction (ctx , deploySpec )
398405
399406 return statusCode , nil
400407}
0 commit comments