Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add partition mapping for iso-e and iso-f #36

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion source/endpoints_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ bool aws_is_ipv6(struct aws_byte_cursor host, bool is_uri_encoded) {
return has_double_colon ? group_count < 7 : group_count == 8;
}

static char s_known_countries[][3] = {{"us"}, {"eu"}, {"ap"}, {"sa"}, {"ca"}, {"me"}, {"af"}};
static char s_known_countries[][3] = {{"us"}, {"eu"}, {"ap"}, {"sa"}, {"ca"}, {"me"}, {"af"}, {"il"}};

struct aws_byte_cursor aws_map_region_to_partition(struct aws_byte_cursor region) {
if (region.len > AWS_REGION_LEN - 1) {
Expand Down Expand Up @@ -180,6 +180,18 @@ struct aws_byte_cursor aws_map_region_to_partition(struct aws_byte_cursor region
}
}

if (2 == sscanf(copy, "eu-isoe-%30[^-]-%03" SCNu8, location, &num)) {
if (location[0] != 0 && num > 0) {
return aws_byte_cursor_from_c_str("aws-iso-e");
}
}

if (2 == sscanf(copy, "us-isof-%30[^-]-%03" SCNu8, location, &num)) {
if (location[0] != 0 && num > 0) {
return aws_byte_cursor_from_c_str("aws-iso-f");
}
}

return aws_byte_cursor_from_c_str("");
}

Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ add_test_case(test_endpoints_substring)
add_test_case(test_endpoints_uri_encode)
add_test_case(test_endpoints_valid_hostlabel)
add_test_case(test_endpoints_condition_mem_clean_up)
add_test_case(test_endpoints_custom)

add_test_case(endpoints_eval_util_is_ipv4)
add_test_case(endpoints_eval_util_is_ipv6)
Expand Down
10 changes: 10 additions & 0 deletions tests/endpoints_rule_engine_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ static int eval_expected(struct aws_allocator *allocator, struct aws_byte_cursor
aws_json_value_get_from_object(endpoint, aws_byte_cursor_from_c_str("url"));
struct aws_byte_cursor expected_url;
aws_json_value_get_string(expected_url_node, &expected_url);
AWS_LOGF_DEBUG(0, PRInSTR " " PRInSTR, AWS_BYTE_CURSOR_PRI(url), AWS_BYTE_CURSOR_PRI(expected_url));
ASSERT_TRUE(aws_byte_cursor_eq(&url, &expected_url));

struct aws_byte_cursor properties;
Expand Down Expand Up @@ -475,3 +476,12 @@ static int s_test_condition_mem_clean_up(struct aws_allocator *allocator, void *

return AWS_OP_SUCCESS;
}

AWS_TEST_CASE(test_endpoints_custom, s_test_endpoints_custom)
static int s_test_endpoints_custom(struct aws_allocator *allocator, void *ctx) {
(void)ctx;

ASSERT_SUCCESS(eval_expected(allocator, aws_byte_cursor_from_c_str("custom_partition.json")));

return AWS_OP_SUCCESS;
}
310 changes: 211 additions & 99 deletions tests/resources/partitions.json
Original file line number Diff line number Diff line change
@@ -1,101 +1,213 @@
{
"version": "1.1",
"partitions": [
{
"id": "aws",
"regionRegex": "^(us|eu|ap|sa|ca|me|af)-\\w+-\\d+$",
"regions": {
"af-south-1": {},
"af-east-1": {},
"ap-northeast-1": {},
"ap-northeast-2": {},
"ap-northeast-3": {},
"ap-south-1": {},
"ap-southeast-1": {},
"ap-southeast-2": {},
"ap-southeast-3": {},
"ca-central-1": {},
"eu-central-1": {},
"eu-north-1": {},
"eu-south-1": {},
"eu-west-1": {},
"eu-west-2": {},
"eu-west-3": {},
"me-south-1": {},
"sa-east-1": {},
"us-east-1": {},
"us-east-2": {},
"us-west-1": {},
"us-west-2": {},
"aws-global": {}
},
"outputs": {
"name": "aws",
"dnsSuffix": "amazonaws.com",
"dualStackDnsSuffix": "api.aws",
"supportsFIPS": true,
"supportsDualStack": true
}
},
{
"id": "aws-us-gov",
"regionRegex": "^us\\-gov\\-\\w+\\-\\d+$",
"regions": {
"us-gov-west-1": {},
"us-gov-east-1": {},
"aws-us-gov-global": {}
},
"outputs": {
"name": "aws-us-gov",
"dnsSuffix": "amazonaws.com",
"dualStackDnsSuffix": "api.aws",
"supportsFIPS": true,
"supportsDualStack": true
}
},
{
"id": "aws-cn",
"regionRegex": "^cn\\-\\w+\\-\\d+$",
"regions": {
"cn-north-1": {},
"cn-northwest-1": {},
"aws-cn-global": {}
},
"outputs": {
"name": "aws-cn",
"dnsSuffix": "amazonaws.com.cn",
"dualStackDnsSuffix": "api.amazonwebservices.com.cn",
"supportsFIPS": true,
"supportsDualStack": true
}
},
{
"id": "aws-iso",
"regionRegex": "^us\\-iso\\-\\w+\\-\\d+$",
"outputs": {
"name": "aws-iso",
"dnsSuffix": "c2s.ic.gov",
"supportsFIPS": true,
"supportsDualStack": false,
"dualStackDnsSuffix": "c2s.ic.gov"
},
"regions": {
"aws-iso-global": {}
}
},
{
"id": "aws-iso-b",
"regionRegex": "^us\\-isob\\-\\w+\\-\\d+$",
"outputs": {
"name": "aws-iso-b",
"dnsSuffix": "sc2s.sgov.gov",
"supportsFIPS": true,
"supportsDualStack": false,
"dualStackDnsSuffix": "sc2s.sgov.gov"
},
"regions": {
"aws-iso-b-global": {}
}
"partitions" : [ {
"id" : "aws",
"outputs" : {
"dnsSuffix" : "amazonaws.com",
"dualStackDnsSuffix" : "api.aws",
"implicitGlobalRegion" : "us-east-1",
"name" : "aws",
"supportsDualStack" : true,
"supportsFIPS" : true
},
"regionRegex" : "^(us|eu|ap|sa|ca|me|af|il)\\-\\w+\\-\\d+$",
"regions" : {
"af-south-1" : {
"description" : "Africa (Cape Town)"
},
"ap-east-1" : {
"description" : "Asia Pacific (Hong Kong)"
},
"ap-northeast-1" : {
"description" : "Asia Pacific (Tokyo)"
},
"ap-northeast-2" : {
"description" : "Asia Pacific (Seoul)"
},
"ap-northeast-3" : {
"description" : "Asia Pacific (Osaka)"
},
"ap-south-1" : {
"description" : "Asia Pacific (Mumbai)"
},
"ap-south-2" : {
"description" : "Asia Pacific (Hyderabad)"
},
"ap-southeast-1" : {
"description" : "Asia Pacific (Singapore)"
},
"ap-southeast-2" : {
"description" : "Asia Pacific (Sydney)"
},
"ap-southeast-3" : {
"description" : "Asia Pacific (Jakarta)"
},
"ap-southeast-4" : {
"description" : "Asia Pacific (Melbourne)"
},
"aws-global" : {
"description" : "AWS Standard global region"
},
"ca-central-1" : {
"description" : "Canada (Central)"
},
"eu-central-1" : {
"description" : "Europe (Frankfurt)"
},
"eu-central-2" : {
"description" : "Europe (Zurich)"
},
"eu-north-1" : {
"description" : "Europe (Stockholm)"
},
"eu-south-1" : {
"description" : "Europe (Milan)"
},
"eu-south-2" : {
"description" : "Europe (Spain)"
},
"eu-west-1" : {
"description" : "Europe (Ireland)"
},
"eu-west-2" : {
"description" : "Europe (London)"
},
"eu-west-3" : {
"description" : "Europe (Paris)"
},
"il-central-1" : {
"description" : "Israel (Tel Aviv)"
},
"me-central-1" : {
"description" : "Middle East (UAE)"
},
"me-south-1" : {
"description" : "Middle East (Bahrain)"
},
"sa-east-1" : {
"description" : "South America (Sao Paulo)"
},
"us-east-1" : {
"description" : "US East (N. Virginia)"
},
"us-east-2" : {
"description" : "US East (Ohio)"
},
"us-west-1" : {
"description" : "US West (N. California)"
},
"us-west-2" : {
"description" : "US West (Oregon)"
}
}
}, {
"id" : "aws-cn",
"outputs" : {
"dnsSuffix" : "amazonaws.com.cn",
"dualStackDnsSuffix" : "api.amazonwebservices.com.cn",
"implicitGlobalRegion" : "cn-northwest-1",
"name" : "aws-cn",
"supportsDualStack" : true,
"supportsFIPS" : true
},
"regionRegex" : "^cn\\-\\w+\\-\\d+$",
"regions" : {
"aws-cn-global" : {
"description" : "AWS China global region"
},
"cn-north-1" : {
"description" : "China (Beijing)"
},
"cn-northwest-1" : {
"description" : "China (Ningxia)"
}
}
}, {
"id" : "aws-us-gov",
"outputs" : {
"dnsSuffix" : "amazonaws.com",
"dualStackDnsSuffix" : "api.aws",
"implicitGlobalRegion" : "us-gov-west-1",
"name" : "aws-us-gov",
"supportsDualStack" : true,
"supportsFIPS" : true
},
"regionRegex" : "^us\\-gov\\-\\w+\\-\\d+$",
"regions" : {
"aws-us-gov-global" : {
"description" : "AWS GovCloud (US) global region"
},
"us-gov-east-1" : {
"description" : "AWS GovCloud (US-East)"
},
"us-gov-west-1" : {
"description" : "AWS GovCloud (US-West)"
}
}
}, {
"id" : "aws-iso",
"outputs" : {
"dnsSuffix" : "c2s.ic.gov",
"dualStackDnsSuffix" : "c2s.ic.gov",
"implicitGlobalRegion" : "us-iso-east-1",
"name" : "aws-iso",
"supportsDualStack" : false,
"supportsFIPS" : true
},
"regionRegex" : "^us\\-iso\\-\\w+\\-\\d+$",
"regions" : {
"aws-iso-global" : {
"description" : "AWS ISO (US) global region"
},
"us-iso-east-1" : {
"description" : "US ISO East"
},
"us-iso-west-1" : {
"description" : "US ISO WEST"
}
}
}, {
"id" : "aws-iso-b",
"outputs" : {
"dnsSuffix" : "sc2s.sgov.gov",
"dualStackDnsSuffix" : "sc2s.sgov.gov",
"implicitGlobalRegion" : "us-isob-east-1",
"name" : "aws-iso-b",
"supportsDualStack" : false,
"supportsFIPS" : true
},
"regionRegex" : "^us\\-isob\\-\\w+\\-\\d+$",
"regions" : {
"aws-iso-b-global" : {
"description" : "AWS ISOB (US) global region"
},
"us-isob-east-1" : {
"description" : "US ISOB East (Ohio)"
}
]
}
}
}, {
"id" : "aws-iso-e",
"outputs" : {
"dnsSuffix" : "cloud.adc-e.uk",
"dualStackDnsSuffix" : "cloud.adc-e.uk",
"implicitGlobalRegion" : "eu-isoe-west-1",
"name" : "aws-iso-e",
"supportsDualStack" : false,
"supportsFIPS" : true
},
"regionRegex" : "^eu\\-isoe\\-\\w+\\-\\d+$",
"regions" : { }
}, {
"id" : "aws-iso-f",
"outputs" : {
"dnsSuffix" : "csp.hci.ic.gov",
"dualStackDnsSuffix" : "csp.hci.ic.gov",
"implicitGlobalRegion" : "us-isof-south-1",
"name" : "aws-iso-f",
"supportsDualStack" : false,
"supportsFIPS" : true
},
"regionRegex" : "^us\\-isof\\-\\w+\\-\\d+$",
"regions" : { }
} ],
"version" : "1.1"
}
Loading