@@ -131,6 +131,24 @@ var (
131131 )
132132)
133133
134+ type tunnelInputModel struct {
135+ BgpRemoteAsn * int64
136+ PeeringLocalAddress * string
137+ PeeringRemoteAddress * string
138+ Phase1DhGroups []vpn.PhaseDhGroupsInner
139+ Phase1EncryptionAlgorithms []vpn.PhaseEncryptionAlgorithmsInner
140+ Phase1IntegrityAlgorithms []vpn.PhaseIntegrityAlgorithmsInner
141+ Phase1RekeyTime * int32
142+ Phase2DhGroups []vpn.PhaseDhGroupsInner
143+ Phase2EncryptionAlgorithms []vpn.PhaseEncryptionAlgorithmsInner
144+ Phase2IntegrityAlgorithms []vpn.PhaseIntegrityAlgorithmsInner
145+ Phase2RekeyTime * int32
146+ Phase2DpdAction * vpn.TunnelConfigurationPhase2AllOfDpdAction
147+ Phase2StartAction * vpn.TunnelConfigurationPhase2AllOfStartAction
148+ PreSharedKey string
149+ RemoteAddress string
150+ }
151+
134152type inputModel struct {
135153 * globalflags.GlobalFlagModel
136154 GatewayId string
@@ -142,37 +160,8 @@ type inputModel struct {
142160 RemoteSubnets []string
143161 StaticRoutes []string
144162
145- Tunnel1BgpRemoteAsn * int64
146- Tunnel1PeeringLocalAddress * string
147- Tunnel1PeeringRemoteAddress * string
148- Tunnel1Phase1DhGroups []vpn.PhaseDhGroupsInner
149- Tunnel1Phase1EncryptionAlgorithms []vpn.PhaseEncryptionAlgorithmsInner
150- Tunnel1Phase1IntegrityAlgorithms []vpn.PhaseIntegrityAlgorithmsInner
151- Tunnel1Phase1RekeyTime * int32
152- Tunnel1Phase2DhGroups []vpn.PhaseDhGroupsInner
153- Tunnel1Phase2EncryptionAlgorithms []vpn.PhaseEncryptionAlgorithmsInner
154- Tunnel1Phase2IntegrityAlgorithms []vpn.PhaseIntegrityAlgorithmsInner
155- Tunnel1Phase2RekeyTime * int32
156- Tunnel1Phase2DpdAction * vpn.TunnelConfigurationPhase2AllOfDpdAction
157- Tunnel1Phase2StartAction * vpn.TunnelConfigurationPhase2AllOfStartAction
158- Tunnel1PreSharedKey string
159- Tunnel1RemoteAddress string
160-
161- Tunnel2BgpRemoteAsn * int64
162- Tunnel2PeeringLocalAddress * string
163- Tunnel2PeeringRemoteAddress * string
164- Tunnel2Phase1DhGroups []vpn.PhaseDhGroupsInner
165- Tunnel2Phase1EncryptionAlgorithms []vpn.PhaseEncryptionAlgorithmsInner
166- Tunnel2Phase1IntegrityAlgorithms []vpn.PhaseIntegrityAlgorithmsInner
167- Tunnel2Phase1RekeyTime * int32
168- Tunnel2Phase2DhGroups []vpn.PhaseDhGroupsInner
169- Tunnel2Phase2EncryptionAlgorithms []vpn.PhaseEncryptionAlgorithmsInner
170- Tunnel2Phase2IntegrityAlgorithms []vpn.PhaseIntegrityAlgorithmsInner
171- Tunnel2Phase2RekeyTime * int32
172- Tunnel2Phase2DpdAction * vpn.TunnelConfigurationPhase2AllOfDpdAction
173- Tunnel2Phase2StartAction * vpn.TunnelConfigurationPhase2AllOfStartAction
174- Tunnel2PreSharedKey string
175- Tunnel2RemoteAddress string
163+ Tunnel1 tunnelInputModel
164+ Tunnel2 tunnelInputModel
176165}
177166
178167func NewCmd (p * types.CmdParams ) * cobra.Command {
@@ -301,43 +290,80 @@ func parseInput(p *print.Printer, cmd *cobra.Command) (*inputModel, error) {
301290 RemoteSubnets : flags .FlagToStringSliceValue (p , cmd , remoteSubnetsFlag ),
302291 StaticRoutes : flags .FlagToStringSliceValue (p , cmd , staticRoutesFlag ),
303292
304- Tunnel1BgpRemoteAsn : flags .FlagToInt64Pointer (p , cmd , tunnel1BgpRemoteAsnFlag ),
305- Tunnel1PeeringLocalAddress : flags .FlagToStringPointer (p , cmd , tunnel1PeeringLocalAddressFlag ),
306- Tunnel1PeeringRemoteAddress : flags .FlagToStringPointer (p , cmd , tunnel1PeeringRemoteAddressFlag ),
307- Tunnel1Phase1DhGroups : tunnel1Phase1DhGroupsFlag .Get (),
308- Tunnel1Phase1EncryptionAlgorithms : tunnel1Phase1EncryptionAlgorithmsFlag .Get (),
309- Tunnel1Phase1IntegrityAlgorithms : tunnel1Phase1IntegrityAlgorithmsFlag .Get (),
310- Tunnel1Phase1RekeyTime : flags .FlagToInt32Pointer (p , cmd , tunnel1Phase1RekeyTimeFlag ),
311- Tunnel1Phase2DhGroups : tunnel1Phase2DhGroupsFlag .Get (),
312- Tunnel1Phase2EncryptionAlgorithms : tunnel1Phase2EncryptionAlgorithmsFlag .Get (),
313- Tunnel1Phase2IntegrityAlgorithms : tunnel1Phase2IntegrityAlgorithmsFlag .Get (),
314- Tunnel1Phase2RekeyTime : flags .FlagToInt32Pointer (p , cmd , tunnel1Phase2RekeyTimeFlag ),
315- Tunnel1Phase2DpdAction : tunnel1Phase2DpdActionFlag .Ptr (),
316- Tunnel1Phase2StartAction : tunnel1Phase2StartActionFlag .Ptr (),
317- Tunnel1PreSharedKey : flags .FlagToStringValue (p , cmd , tunnel1PreSharedKeyFlag ),
318- Tunnel1RemoteAddress : flags .FlagToStringValue (p , cmd , tunnel1RemoteAddressFlag ),
319-
320- Tunnel2BgpRemoteAsn : flags .FlagToInt64Pointer (p , cmd , tunnel2BgpRemoteAsnFlag ),
321- Tunnel2PeeringLocalAddress : flags .FlagToStringPointer (p , cmd , tunnel2PeeringLocalAddressFlag ),
322- Tunnel2PeeringRemoteAddress : flags .FlagToStringPointer (p , cmd , tunnel2PeeringRemoteAddressFlag ),
323- Tunnel2Phase1DhGroups : tunnel2Phase1DhGroupsFlag .Get (),
324- Tunnel2Phase1EncryptionAlgorithms : tunnel2Phase1EncryptionAlgorithmsFlag .Get (),
325- Tunnel2Phase1IntegrityAlgorithms : tunnel2Phase1IntegrityAlgorithmsFlag .Get (),
326- Tunnel2Phase1RekeyTime : flags .FlagToInt32Pointer (p , cmd , tunnel2Phase1RekeyTimeFlag ),
327- Tunnel2Phase2DhGroups : tunnel2Phase2DhGroupsFlag .Get (),
328- Tunnel2Phase2EncryptionAlgorithms : tunnel2Phase2EncryptionAlgorithmsFlag .Get (),
329- Tunnel2Phase2IntegrityAlgorithms : tunnel2Phase2IntegrityAlgorithmsFlag .Get (),
330- Tunnel2Phase2RekeyTime : flags .FlagToInt32Pointer (p , cmd , tunnel2Phase2RekeyTimeFlag ),
331- Tunnel2Phase2DpdAction : tunnel2Phase2DpdActionFlag .Ptr (),
332- Tunnel2Phase2StartAction : tunnel2Phase2StartActionFlag .Ptr (),
333- Tunnel2PreSharedKey : flags .FlagToStringValue (p , cmd , tunnel2PreSharedKeyFlag ),
334- Tunnel2RemoteAddress : flags .FlagToStringValue (p , cmd , tunnel2RemoteAddressFlag ),
293+ Tunnel1 : tunnelInputModel {
294+ BgpRemoteAsn : flags .FlagToInt64Pointer (p , cmd , tunnel1BgpRemoteAsnFlag ),
295+ PeeringLocalAddress : flags .FlagToStringPointer (p , cmd , tunnel1PeeringLocalAddressFlag ),
296+ PeeringRemoteAddress : flags .FlagToStringPointer (p , cmd , tunnel1PeeringRemoteAddressFlag ),
297+ Phase1DhGroups : tunnel1Phase1DhGroupsFlag .Get (),
298+ Phase1EncryptionAlgorithms : tunnel1Phase1EncryptionAlgorithmsFlag .Get (),
299+ Phase1IntegrityAlgorithms : tunnel1Phase1IntegrityAlgorithmsFlag .Get (),
300+ Phase1RekeyTime : flags .FlagToInt32Pointer (p , cmd , tunnel1Phase1RekeyTimeFlag ),
301+ Phase2DhGroups : tunnel1Phase2DhGroupsFlag .Get (),
302+ Phase2EncryptionAlgorithms : tunnel1Phase2EncryptionAlgorithmsFlag .Get (),
303+ Phase2IntegrityAlgorithms : tunnel1Phase2IntegrityAlgorithmsFlag .Get (),
304+ Phase2RekeyTime : flags .FlagToInt32Pointer (p , cmd , tunnel1Phase2RekeyTimeFlag ),
305+ Phase2DpdAction : tunnel1Phase2DpdActionFlag .Ptr (),
306+ Phase2StartAction : tunnel1Phase2StartActionFlag .Ptr (),
307+ PreSharedKey : flags .FlagToStringValue (p , cmd , tunnel1PreSharedKeyFlag ),
308+ RemoteAddress : flags .FlagToStringValue (p , cmd , tunnel1RemoteAddressFlag ),
309+ },
310+
311+ Tunnel2 : tunnelInputModel {
312+ BgpRemoteAsn : flags .FlagToInt64Pointer (p , cmd , tunnel2BgpRemoteAsnFlag ),
313+ PeeringLocalAddress : flags .FlagToStringPointer (p , cmd , tunnel2PeeringLocalAddressFlag ),
314+ PeeringRemoteAddress : flags .FlagToStringPointer (p , cmd , tunnel2PeeringRemoteAddressFlag ),
315+ Phase1DhGroups : tunnel2Phase1DhGroupsFlag .Get (),
316+ Phase1EncryptionAlgorithms : tunnel2Phase1EncryptionAlgorithmsFlag .Get (),
317+ Phase1IntegrityAlgorithms : tunnel2Phase1IntegrityAlgorithmsFlag .Get (),
318+ Phase1RekeyTime : flags .FlagToInt32Pointer (p , cmd , tunnel2Phase1RekeyTimeFlag ),
319+ Phase2DhGroups : tunnel2Phase2DhGroupsFlag .Get (),
320+ Phase2EncryptionAlgorithms : tunnel2Phase2EncryptionAlgorithmsFlag .Get (),
321+ Phase2IntegrityAlgorithms : tunnel2Phase2IntegrityAlgorithmsFlag .Get (),
322+ Phase2RekeyTime : flags .FlagToInt32Pointer (p , cmd , tunnel2Phase2RekeyTimeFlag ),
323+ Phase2DpdAction : tunnel2Phase2DpdActionFlag .Ptr (),
324+ Phase2StartAction : tunnel2Phase2StartActionFlag .Ptr (),
325+ PreSharedKey : flags .FlagToStringValue (p , cmd , tunnel2PreSharedKeyFlag ),
326+ RemoteAddress : flags .FlagToStringValue (p , cmd , tunnel2RemoteAddressFlag ),
327+ },
335328 }
336329
337330 p .DebugInputModel (model )
338331 return & model , nil
339332}
340333
334+ func buildTunnelConfiguration (model tunnelInputModel ) vpn.TunnelConfiguration {
335+ tunnel := vpn.TunnelConfiguration {
336+ RemoteAddress : model .RemoteAddress ,
337+ }
338+ if model .BgpRemoteAsn != nil {
339+ tunnel .Bgp = & vpn.BGPTunnelConfig {
340+ RemoteAsn : * model .BgpRemoteAsn ,
341+ }
342+ }
343+ if model .PeeringLocalAddress != nil || model .PeeringRemoteAddress != nil {
344+ tunnel .Peering = & vpn.PeeringConfig {
345+ LocalAddress : model .PeeringLocalAddress ,
346+ RemoteAddress : model .PeeringRemoteAddress ,
347+ }
348+ }
349+ tunnel .Phase1 = vpn.TunnelConfigurationPhase1 {
350+ DhGroups : model .Phase1DhGroups ,
351+ EncryptionAlgorithms : model .Phase1EncryptionAlgorithms ,
352+ IntegrityAlgorithms : model .Phase1IntegrityAlgorithms ,
353+ RekeyTime : model .Phase1RekeyTime ,
354+ }
355+ tunnel .Phase2 = vpn.TunnelConfigurationPhase2 {
356+ DhGroups : model .Phase2DhGroups ,
357+ EncryptionAlgorithms : model .Phase2EncryptionAlgorithms ,
358+ IntegrityAlgorithms : model .Phase2IntegrityAlgorithms ,
359+ RekeyTime : model .Phase2RekeyTime ,
360+ DpdAction : model .Phase2DpdAction ,
361+ StartAction : model .Phase2StartAction ,
362+ }
363+ tunnel .PreSharedKey = & model .PreSharedKey
364+ return tunnel
365+ }
366+
341367func buildRequest (ctx context.Context , model * inputModel , apiClient * vpn.APIClient ) (vpn.ApiCreateGatewayConnectionRequest , error ) {
342368 req := apiClient .DefaultAPI .CreateGatewayConnection (ctx , model .ProjectId , model .Region , model .GatewayId )
343369
@@ -350,68 +376,8 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *vpn.APIClie
350376 StaticRoutes : model .StaticRoutes ,
351377 }
352378
353- tunnel1 := vpn.TunnelConfiguration {
354- RemoteAddress : model .Tunnel1RemoteAddress ,
355- }
356- if model .Tunnel1BgpRemoteAsn != nil {
357- tunnel1 .Bgp = & vpn.BGPTunnelConfig {
358- RemoteAsn : * model .Tunnel1BgpRemoteAsn ,
359- }
360- }
361- if model .Tunnel1PeeringLocalAddress != nil || model .Tunnel1PeeringRemoteAddress != nil {
362- tunnel1 .Peering = & vpn.PeeringConfig {
363- LocalAddress : model .Tunnel1PeeringLocalAddress ,
364- RemoteAddress : model .Tunnel1PeeringRemoteAddress ,
365- }
366- }
367- tunnel1 .Phase1 = vpn.TunnelConfigurationPhase1 {
368- DhGroups : model .Tunnel1Phase1DhGroups ,
369- EncryptionAlgorithms : model .Tunnel1Phase1EncryptionAlgorithms ,
370- IntegrityAlgorithms : model .Tunnel1Phase1IntegrityAlgorithms ,
371- RekeyTime : model .Tunnel1Phase1RekeyTime ,
372- }
373- tunnel1 .Phase2 = vpn.TunnelConfigurationPhase2 {
374- DhGroups : model .Tunnel1Phase2DhGroups ,
375- EncryptionAlgorithms : model .Tunnel1Phase2EncryptionAlgorithms ,
376- IntegrityAlgorithms : model .Tunnel1Phase2IntegrityAlgorithms ,
377- RekeyTime : model .Tunnel1Phase2RekeyTime ,
378- DpdAction : model .Tunnel1Phase2DpdAction ,
379- StartAction : model .Tunnel1Phase2StartAction ,
380- }
381- tunnel1 .PreSharedKey = & model .Tunnel1PreSharedKey
382- payload .Tunnel1 = tunnel1
383-
384- tunnel2 := vpn.TunnelConfiguration {
385- RemoteAddress : model .Tunnel2RemoteAddress ,
386- }
387- if model .Tunnel2BgpRemoteAsn != nil {
388- tunnel2 .Bgp = & vpn.BGPTunnelConfig {
389- RemoteAsn : * model .Tunnel2BgpRemoteAsn ,
390- }
391- }
392- if model .Tunnel2PeeringLocalAddress != nil || model .Tunnel2PeeringRemoteAddress != nil {
393- tunnel2 .Peering = & vpn.PeeringConfig {
394- LocalAddress : model .Tunnel2PeeringLocalAddress ,
395- RemoteAddress : model .Tunnel2PeeringRemoteAddress ,
396- }
397- }
398- tunnel2 .Phase1 = vpn.TunnelConfigurationPhase1 {
399- DhGroups : model .Tunnel2Phase1DhGroups ,
400- EncryptionAlgorithms : model .Tunnel2Phase1EncryptionAlgorithms ,
401- IntegrityAlgorithms : model .Tunnel2Phase1IntegrityAlgorithms ,
402- RekeyTime : model .Tunnel2Phase1RekeyTime ,
403- }
404-
405- tunnel2 .Phase2 = vpn.TunnelConfigurationPhase2 {
406- DhGroups : model .Tunnel2Phase2DhGroups ,
407- EncryptionAlgorithms : model .Tunnel2Phase2EncryptionAlgorithms ,
408- IntegrityAlgorithms : model .Tunnel2Phase2IntegrityAlgorithms ,
409- RekeyTime : model .Tunnel2Phase2RekeyTime ,
410- DpdAction : model .Tunnel2Phase2DpdAction ,
411- StartAction : model .Tunnel2Phase2StartAction ,
412- }
413- tunnel2 .PreSharedKey = & model .Tunnel2PreSharedKey
414- payload .Tunnel2 = tunnel2
379+ payload .Tunnel1 = buildTunnelConfiguration (model .Tunnel1 )
380+ payload .Tunnel2 = buildTunnelConfiguration (model .Tunnel2 )
415381
416382 return req .CreateGatewayConnectionPayload (payload ), nil
417383}
0 commit comments