@@ -36,11 +36,11 @@ impl VpcExpose {
36
36
self . not_as . insert ( prefix) ;
37
37
self
38
38
}
39
- fn fixup ( mut self ) -> Result < Self , ApiError > {
39
+ fn fixup ( mut self ) -> Result < Self , ConfigError > {
40
40
// Add a root prefix to the list of private prefixes if the list is empty
41
41
if self . ips . is_empty ( ) {
42
42
if self . nots . is_empty ( ) {
43
- return Err ( ApiError :: EmptyExpose ) ;
43
+ return Err ( ConfigError :: EmptyExpose ) ;
44
44
}
45
45
let mut added_v4 = false ;
46
46
let mut added_v6 = false ;
@@ -198,7 +198,7 @@ impl VpcManifest {
198
198
..Default :: default ( )
199
199
}
200
200
}
201
- fn validate_expose_addition ( & self , expose : & VpcExpose ) -> ApiResult {
201
+ fn validate_expose_addition ( & self , expose : & VpcExpose ) -> ConfigResult {
202
202
// Check that prefixes in the expose don't overlap with prefixes in other exposes
203
203
for other_expose in & self . exposes {
204
204
validate_overlapping (
@@ -216,11 +216,11 @@ impl VpcManifest {
216
216
}
217
217
Ok ( ( ) )
218
218
}
219
- pub fn add_expose ( & mut self , new_expose : VpcExpose ) -> ApiResult {
219
+ pub fn add_expose ( & mut self , new_expose : VpcExpose ) -> ConfigResult {
220
220
let mut expose = new_expose;
221
221
match expose. validate ( ) {
222
222
Ok ( _) => { }
223
- Err ( ApiError :: EmptyExpose ) => {
223
+ Err ( ConfigError :: EmptyExpose ) => {
224
224
// Fix up empty expose and give another try at validation
225
225
expose = expose. clone ( ) ;
226
226
expose = expose. fixup ( ) ?;
@@ -232,6 +232,15 @@ impl VpcManifest {
232
232
self . exposes . push ( expose) ;
233
233
Ok ( ( ) )
234
234
}
235
+ pub fn validate ( & self ) -> ConfigResult {
236
+ if self . name . is_empty ( ) {
237
+ return Err ( ConfigError :: MissingIdentifier ( "Manifest name" ) ) ;
238
+ }
239
+ if self . exposes . is_empty ( ) {
240
+ return Err ( ConfigError :: IncompleteConfig ( "Empty manifest" . to_string ( ) ) ) ;
241
+ }
242
+ Ok ( ( ) )
243
+ }
235
244
}
236
245
237
246
#[ derive( Clone , Debug ) ]
@@ -252,6 +261,8 @@ impl VpcPeering {
252
261
if self . name . is_empty ( ) {
253
262
return Err ( ConfigError :: MissingIdentifier ( "Peering name" ) ) ;
254
263
}
264
+ self . left . validate ( ) ?;
265
+ self . right . validate ( ) ?;
255
266
Ok ( ( ) )
256
267
}
257
268
/// Given a peering fetch the manifests, orderly depending on the provided vpc name
@@ -280,13 +291,13 @@ impl VpcPeeringTable {
280
291
self . 0 . is_empty ( )
281
292
}
282
293
283
- fn validate_peering_addition ( & self , new_peering : & VpcPeering ) -> ApiResult {
294
+ fn validate_peering_addition ( & self , new_peering : & VpcPeering ) -> ConfigResult {
284
295
// Check that exposes in the new peering do not collide with any of the exposes in the
285
296
// existing peerings in the table, for the same VPCs
286
297
for vpc in [ & new_peering. left . name , & new_peering. right . name ] {
287
- let ( new_local, _) = new_peering. get_peers ( vpc) ;
298
+ let ( new_local, _) = new_peering. get_peering_manifests ( vpc) ;
288
299
for peering in self . peerings_vpc ( vpc) {
289
- let ( local, _) = peering. get_peers ( vpc) ;
300
+ let ( local, _) = peering. get_peering_manifests ( vpc) ;
290
301
for new_expose in & new_local. exposes {
291
302
for expose in & local. exposes {
292
303
validate_overlapping (
@@ -314,7 +325,7 @@ impl VpcPeeringTable {
314
325
315
326
// First look for an existing entry, to avoid inserting a duplicate peering
316
327
if self . 0 . contains_key ( & peering. name ) {
317
- return Err ( ApiError :: DuplicateVpcPeeringId ( peering. name . clone ( ) ) ) ;
328
+ return Err ( ConfigError :: DuplicateVpcPeeringId ( peering. name . clone ( ) ) ) ;
318
329
}
319
330
320
331
if let Some ( peering) = self . 0 . insert ( peering. name . to_owned ( ) , peering) {
@@ -341,7 +352,7 @@ fn validate_overlapping(
341
352
excludes_left : & BTreeSet < Prefix > ,
342
353
prefixes_right : & BTreeSet < Prefix > ,
343
354
excludes_right : & BTreeSet < Prefix > ,
344
- ) -> Result < ( ) , ApiError > {
355
+ ) -> Result < ( ) , ConfigError > {
345
356
// Find colliding prefixes
346
357
let mut colliding = Vec :: new ( ) ;
347
358
for prefix_left in prefixes_left. iter ( ) {
@@ -448,7 +459,7 @@ fn validate_overlapping(
448
459
// Some addresses at the intersection of both prefixes are not covered by the union of
449
460
// all exclusion prefixes, in other words, they are available from both prefixes. This
450
461
// is an error.
451
- return Err ( ApiError :: OverlappingPrefixes ( prefix_left, prefix_right) ) ;
462
+ return Err ( ConfigError :: OverlappingPrefixes ( prefix_left, prefix_right) ) ;
452
463
}
453
464
}
454
465
Ok ( ( ) )
@@ -753,7 +764,7 @@ mod tests {
753
764
let peering2 = VpcPeering :: new ( "test_peering2" , manifest1. clone ( ) , manifest2. clone ( ) ) ;
754
765
assert_eq ! (
755
766
table. add( peering2) ,
756
- Err ( ApiError :: OverlappingPrefixes (
767
+ Err ( ConfigError :: OverlappingPrefixes (
757
768
prefix_v4( "10.0.0.0/16" ) ,
758
769
prefix_v4( "10.0.0.0/16" )
759
770
) )
0 commit comments