Skip to content

Commit f7bcebf

Browse files
committed
aws: update support for additional regions
- add new endpoint suffixes - use mapping between region prefix to endpoint suffix - update flb_aws_endpoint to use new mapping Signed-off-by: Shelby Hagman <shelbyzh@amazon.com>
1 parent 29deec9 commit f7bcebf

1 file changed

Lines changed: 40 additions & 9 deletions

File tree

src/aws/flb_aws_util.c

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,34 @@
3535

3636
#define AWS_SERVICE_ENDPOINT_FORMAT "%s.%s%s"
3737
#define AWS_SERVICE_ENDPOINT_SUFFIX_COM ".amazonaws.com"
38-
#define AWS_SERVICE_ENDPOINT_SUFFIX_COM_CN ".amazonaws.com.cn"
38+
#define AWS_SERVICE_ENDPOINT_SUFFIX_SC2S ".sc2s.sgov.gov"
39+
#define AWS_SERVICE_ENDPOINT_SUFFIX_CSP ".csp.hci.ic.gov"
40+
#define AWS_SERVICE_ENDPOINT_SUFFIX_C2S ".c2s.ic.gov"
41+
#define AWS_SERVICE_ENDPOINT_SUFFIX_ADC_E ".cloud.adc-e.uk"
3942
#define AWS_SERVICE_ENDPOINT_SUFFIX_EU ".amazonaws.eu"
43+
#define AWS_SERVICE_ENDPOINT_SUFFIX_COM_CN ".amazonaws.com.cn"
44+
45+
/* Maps a region name prefix to its endpoint domain suffix. */
46+
struct flb_aws_endpoint_suffix {
47+
const char *prefix;
48+
const char *suffix;
49+
};
50+
51+
/*
52+
* Region prefix to domain suffix mapping for non-standard AWS region families.
53+
* Matched via strncmp against the region string, so entries must be ordered
54+
* most-specific first to prevent a shorter prefix (e.g. "us-iso-") from
55+
* matching before a longer one (e.g. "us-isob-", "us-isof-").
56+
*/
57+
static const struct flb_aws_endpoint_suffix endpoint_suffixes[] = {
58+
{ "us-isob-", AWS_SERVICE_ENDPOINT_SUFFIX_SC2S },
59+
{ "us-isof-", AWS_SERVICE_ENDPOINT_SUFFIX_CSP },
60+
{ "us-iso-", AWS_SERVICE_ENDPOINT_SUFFIX_C2S },
61+
{ "eu-isoe-", AWS_SERVICE_ENDPOINT_SUFFIX_ADC_E },
62+
{ "eusc-", AWS_SERVICE_ENDPOINT_SUFFIX_EU },
63+
{ "cn-", AWS_SERVICE_ENDPOINT_SUFFIX_COM_CN },
64+
{ NULL, NULL }
65+
};
4066

4167
#define TAG_PART_DESCRIPTOR "$TAG[%d]"
4268
#define TAG_DESCRIPTOR "$TAG"
@@ -73,23 +99,28 @@ struct flb_http_client *request_do(struct flb_aws_client *aws_client,
7399
size_t dynamic_headers_len);
74100

75101
/*
76-
* https://service.region.amazonaws.[com(.cn)|eu]
102+
* Constructs an AWS service endpoint of the form: service.region.<domain-suffix>
103+
* The domain suffix is resolved via endpoint_suffixes[], defaulting to .amazonaws.com.
77104
*/
78105
char *flb_aws_endpoint(char* service, char* region)
79106
{
80107
char *endpoint = NULL;
81108
const char *domain_suffix = AWS_SERVICE_ENDPOINT_SUFFIX_COM;
82109
size_t len;
83110
int bytes;
111+
int i;
84112

85-
86-
/* China regions end with amazonaws.com.cn */
87-
if (strcmp("cn-north-1", region) == 0 ||
88-
strcmp("cn-northwest-1", region) == 0) {
89-
domain_suffix = AWS_SERVICE_ENDPOINT_SUFFIX_COM_CN;
113+
if (!service || !region) {
114+
return NULL;
90115
}
91-
else if (strncmp(region, "eusc-", 5) == 0) {
92-
domain_suffix = AWS_SERVICE_ENDPOINT_SUFFIX_EU;
116+
117+
/* Walk the prefix table; first match wins */
118+
for (i = 0; endpoint_suffixes[i].prefix != NULL; i++) {
119+
if (strncmp(region, endpoint_suffixes[i].prefix,
120+
strlen(endpoint_suffixes[i].prefix)) == 0) {
121+
domain_suffix = endpoint_suffixes[i].suffix;
122+
break;
123+
}
93124
}
94125

95126
len = strlen(service);

0 commit comments

Comments
 (0)