Add region validation to region setting in NestedPropertyProcessor

This commit is contained in:
Ethan Katnic 2024-08-21 10:44:18 -07:00
parent e6402773d6
commit 4edccf42f0
2 changed files with 9 additions and 6 deletions

View file

@ -15,6 +15,7 @@
package software.amazon.kinesis.multilang;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.common.base.CaseFormat;
@ -73,8 +74,13 @@ public enum NestedPropertyKey {
* @see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html#concepts-regions">Available Regions</a>
*/
ENDPOINT_REGION {
void visit(final NestedPropertyProcessor processor, final String region) {
processor.acceptEndpointRegion(Region.of(region));
void visit(final NestedPropertyProcessor processor, final String regionName) {
List<Region> validRegions = Region.regions();
Region region = Region.of(regionName);
if (!validRegions.contains(region)) {
throw new IllegalArgumentException("Invalid region name: " + regionName);
}
processor.acceptEndpointRegion(region);
}
},

View file

@ -70,10 +70,7 @@ public class NestedPropertyKeyTest {
verify(mockProcessor).acceptEndpointRegion(expectedRegion);
}
// Region.of(), which is invoked in this test, no longer throws an IllegalArgumentException when given an invalid
// region
// We would need to implement our own region validation to maintain this test
// @Test(expected = IllegalArgumentException.class)
@Test(expected = IllegalArgumentException.class)
public void testInvalidEndpointRegion() {
parse(mockProcessor, createKey(ENDPOINT_REGION, "snuffleupagus"));
}