4
4
use gateway_config:: config as gateway_config;
5
5
use std:: convert:: TryFrom ;
6
6
7
- use crate :: external:: overlay:: vpcpeering:: VpcExpose ;
7
+ use crate :: external:: overlay:: vpcpeering:: {
8
+ VpcExpose , VpcExposeNatConfig , VpcExposeStatefulNat , VpcExposeStatelessNat ,
9
+ } ;
8
10
use lpm:: prefix:: { Prefix , PrefixString } ;
9
11
10
12
impl TryFrom < & gateway_config:: Expose > for VpcExpose {
@@ -54,6 +56,34 @@ impl TryFrom<&gateway_config::Expose> for VpcExpose {
54
56
}
55
57
}
56
58
59
+ if !expose. r#as . is_empty ( ) {
60
+ vpc_expose = vpc_expose. make_nat ( ) ;
61
+ if let ( Some ( grpc_nat) , Some ( nat) ) = ( expose. nat . as_ref ( ) , vpc_expose. nat . as_mut ( ) ) {
62
+ #[ allow( clippy:: default_constructed_unit_structs) ]
63
+ match grpc_nat {
64
+ gateway_config:: expose:: Nat :: Stateless ( _) => {
65
+ nat. config =
66
+ VpcExposeNatConfig :: Stateless ( VpcExposeStatelessNat :: default ( ) ) ;
67
+ }
68
+ gateway_config:: expose:: Nat :: Stateful ( grpc_s) => {
69
+ if let Some ( nat) = vpc_expose. nat . as_mut ( ) {
70
+ nat. config = VpcExposeNatConfig :: Stateful ( VpcExposeStatefulNat {
71
+ idle_timeout : grpc_s
72
+ . idle_timeout
73
+ . ok_or (
74
+ "stateful nat requires idle_timeout, got None" . to_string ( ) ,
75
+ )
76
+ . and_then ( |t| {
77
+ std:: time:: Duration :: try_from ( t)
78
+ . map_err ( |e| format ! ( "Invalid duration: {e}" ) )
79
+ } ) ?,
80
+ } ) ;
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+
57
87
Ok ( vpc_expose)
58
88
}
59
89
}
@@ -77,7 +107,7 @@ impl TryFrom<&VpcExpose> for gateway_config::Expose {
77
107
ips. push ( gateway_config:: PeeringIPs { rule : Some ( rule) } ) ;
78
108
}
79
109
80
- if let Some ( nat) = expose. nat . as_ref ( ) {
110
+ let nat = if let Some ( nat) = expose. nat . as_ref ( ) {
81
111
// Convert AS inclusion rules
82
112
for prefix in & nat. as_range {
83
113
let rule = gateway_config:: peering_as:: Rule :: Cidr ( prefix. to_string ( ) ) ;
@@ -89,10 +119,29 @@ impl TryFrom<&VpcExpose> for gateway_config::Expose {
89
119
let rule = gateway_config:: peering_as:: Rule :: Not ( prefix. to_string ( ) ) ;
90
120
as_rules. push ( gateway_config:: PeeringAs { rule : Some ( rule) } ) ;
91
121
}
92
- }
122
+
123
+ match nat. config {
124
+ VpcExposeNatConfig :: Stateful ( config) => {
125
+ let idle_timeout =
126
+ gateway_config:: google:: protobuf:: Duration :: try_from ( config. idle_timeout )
127
+ . map_err ( |e| {
128
+ format ! ( "Unable to convert stateful nat idle timeout: {}" , e)
129
+ } ) ?;
130
+ Some ( gateway_config:: expose:: Nat :: Stateful (
131
+ gateway_config:: PeeringStatefulNat { idle_timeout } ,
132
+ ) )
133
+ }
134
+ VpcExposeNatConfig :: Stateless ( config) => Some (
135
+ gateway_config:: expose:: Nat :: Stateless ( gateway_config:: PeeringStatelessNat { } ) ,
136
+ ) ,
137
+ }
138
+ } else {
139
+ None
140
+ } ;
93
141
Ok ( gateway_config:: Expose {
94
142
ips,
95
143
r#as : as_rules,
144
+ nat,
96
145
} )
97
146
}
98
147
}
0 commit comments