11package tunnel
22
33import (
4+ "crypto/tls"
45 "fmt"
56 "io/ioutil"
67 "os"
@@ -160,27 +161,27 @@ func prepareTunnelConfig(
160161 transportLogger logger.Service ,
161162 namedTunnel * connection.NamedTunnelConfig ,
162163 uiIsEnabled bool ,
163- ) (* origin.TunnelConfig , error ) {
164+ ) (* origin.TunnelConfig , ingress. Ingress , error ) {
164165 isNamedTunnel := namedTunnel != nil
165166
166167 hostname , err := validation .ValidateHostname (c .String ("hostname" ))
167168 if err != nil {
168169 logger .Errorf ("Invalid hostname: %s" , err )
169- return nil , errors .Wrap (err , "Invalid hostname" )
170+ return nil , ingress. Ingress {}, errors .Wrap (err , "Invalid hostname" )
170171 }
171172 isFreeTunnel := hostname == ""
172173 clientID := c .String ("id" )
173174 if ! c .IsSet ("id" ) {
174175 clientID , err = generateRandomClientID (logger )
175176 if err != nil {
176- return nil , err
177+ return nil , ingress. Ingress {}, err
177178 }
178179 }
179180
180181 tags , err := NewTagSliceFromCLI (c .StringSlice ("tag" ))
181182 if err != nil {
182183 logger .Errorf ("Tag parse failure: %s" , err )
183- return nil , errors .Wrap (err , "Tag parse failure" )
184+ return nil , ingress. Ingress {}, errors .Wrap (err , "Tag parse failure" )
184185 }
185186
186187 tags = append (tags , tunnelpogs.Tag {Name : "ID" , Value : clientID })
@@ -189,7 +190,7 @@ func prepareTunnelConfig(
189190 if ! isFreeTunnel {
190191 originCert , err = getOriginCert (c , logger )
191192 if err != nil {
192- return nil , errors .Wrap (err , "Error getting origin cert" )
193+ return nil , ingress. Ingress {}, errors .Wrap (err , "Error getting origin cert" )
193194 }
194195 }
195196
@@ -200,7 +201,7 @@ func prepareTunnelConfig(
200201 if isNamedTunnel {
201202 clientUUID , err := uuid .NewRandom ()
202203 if err != nil {
203- return nil , errors .Wrap (err , "can't generate clientUUID" )
204+ return nil , ingress. Ingress {}, errors .Wrap (err , "can't generate clientUUID" )
204205 }
205206 namedTunnel .Client = tunnelpogs.ClientInfo {
206207 ClientID : clientUUID [:],
@@ -210,10 +211,10 @@ func prepareTunnelConfig(
210211 }
211212 ingressRules , err = ingress .ParseIngress (config .GetConfiguration ())
212213 if err != nil && err != ingress .ErrNoIngressRules {
213- return nil , err
214+ return nil , ingress. Ingress {}, err
214215 }
215216 if ! ingressRules .IsEmpty () && c .IsSet ("url" ) {
216- return nil , ingress .ErrURLIncompatibleWithIngress
217+ return nil , ingress.Ingress {}, ingress . ErrURLIncompatibleWithIngress
217218 }
218219 } else {
219220 classicTunnel = & connection.ClassicTunnelConfig {
@@ -226,36 +227,28 @@ func prepareTunnelConfig(
226227
227228 // Convert single-origin configuration into multi-origin configuration.
228229 if ingressRules .IsEmpty () {
229- ingressRules , err = ingress .NewSingleOrigin (c , compatibilityMode , logger )
230+ ingressRules , err = ingress .NewSingleOrigin (c , ! isNamedTunnel , logger )
230231 if err != nil {
231- return nil , err
232+ return nil , ingress. Ingress {}, err
232233 }
233234 }
234235
235236 protocolSelector , err := connection .NewProtocolSelector (c .String ("protocol" ), namedTunnel , edgediscovery .HTTP2Percentage , origin .ResolveTTL , logger )
236237 if err != nil {
237- return nil , err
238+ return nil , ingress. Ingress {}, err
238239 }
239240 logger .Infof ("Initial protocol %s" , protocolSelector .Current ())
240241
241242 edgeTLSConfigs := make (map [connection.Protocol ]* tls.Config , len (connection .ProtocolList ))
242243 for _ , p := range connection .ProtocolList {
243244 edgeTLSConfig , err := tlsconfig .CreateTunnelConfig (c , p .ServerName ())
244245 if err != nil {
245- return nil , errors .Wrap (err , "unable to create TLS config to connect with edge" )
246+ return nil , ingress. Ingress {}, errors .Wrap (err , "unable to create TLS config to connect with edge" )
246247 }
247248 edgeTLSConfigs [p ] = edgeTLSConfig
248249 }
249250
250- proxyConfig := & origin.ProxyConfig {
251- Client : httpTransport ,
252- URL : originURL ,
253- TLSConfig : httpTransport .TLSClientConfig ,
254- HostHeader : c .String ("http-host-header" ),
255- NoChunkedEncoding : c .Bool ("no-chunked-encoding" ),
256- Tags : tags ,
257- }
258- originClient := origin .NewClient (proxyConfig , logger )
251+ originClient := origin .NewClient (ingressRules , tags , logger )
259252 connectionConfig := & connection.Config {
260253 OriginClient : originClient ,
261254 GracePeriod : c .Duration ("grace-period" ),
@@ -275,7 +268,6 @@ func prepareTunnelConfig(
275268
276269 return & origin.TunnelConfig {
277270 ConnectionConfig : connectionConfig ,
278- ProxyConfig : proxyConfig ,
279271 BuildInfo : buildInfo ,
280272 ClientID : clientID ,
281273 EdgeAddrs : c .StringSlice ("edge" ),
@@ -284,6 +276,7 @@ func prepareTunnelConfig(
284276 IsAutoupdated : c .Bool ("is-autoupdated" ),
285277 IsFreeTunnel : isFreeTunnel ,
286278 LBPool : c .String ("lb-pool" ),
279+ Tags : tags ,
287280 Logger : logger ,
288281 Observer : connection .NewObserver (transportLogger , tunnelEventChan ),
289282 ReportedVersion : version ,
@@ -293,10 +286,9 @@ func prepareTunnelConfig(
293286 ClassicTunnel : classicTunnel ,
294287 MuxerConfig : muxerConfig ,
295288 TunnelEventChan : tunnelEventChan ,
296- IngressRules : ingressRules ,
297289 ProtocolSelector : protocolSelector ,
298290 EdgeTLSConfigs : edgeTLSConfigs ,
299- }, nil
291+ }, ingressRules , nil
300292}
301293
302294func isRunningFromTerminal () bool {
0 commit comments