Skip to content

Commit c77dc5a

Browse files
committed
feature: switch AWS Endpoints for European Souvereign Cloud
1 parent e19e07e commit c77dc5a

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

src/aws/flb_aws_util.c

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
#include <sys/stat.h>
3434
#include <fcntl.h>
3535

36-
#define AWS_SERVICE_ENDPOINT_FORMAT "%s.%s.amazonaws.com"
37-
#define AWS_SERVICE_ENDPOINT_BASE_LEN 15
36+
#define AWS_SERVICE_ENDPOINT_FORMAT "%s.%s%s"
37+
#define AWS_SERVICE_ENDPOINT_SUFFIX_COM ".amazonaws.com"
38+
#define AWS_SERVICE_ENDPOINT_SUFFIX_COM_CN ".amazonaws.com.cn"
39+
#define AWS_SERVICE_ENDPOINT_SUFFIX_EU ".amazonaws.eu"
3840

3941
#define TAG_PART_DESCRIPTOR "$TAG[%d]"
4042
#define TAG_DESCRIPTOR "$TAG"
@@ -71,48 +73,44 @@ struct flb_http_client *request_do(struct flb_aws_client *aws_client,
7173
size_t dynamic_headers_len);
7274

7375
/*
74-
* https://service.region.amazonaws.com(.cn)
76+
* https://service.region.amazonaws.[com(.cn)|eu]
7577
*/
7678
char *flb_aws_endpoint(char* service, char* region)
7779
{
7880
char *endpoint = NULL;
79-
size_t len = AWS_SERVICE_ENDPOINT_BASE_LEN;
80-
int is_cn = FLB_FALSE;
81+
const char *domain_suffix = AWS_SERVICE_ENDPOINT_SUFFIX_COM;
82+
size_t len;
8183
int bytes;
8284

8385

84-
/* In the China regions, ".cn" is appended to the URL */
85-
if (strcmp("cn-north-1", region) == 0) {
86-
len += 3;
87-
is_cn = FLB_TRUE;
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;
8890
}
89-
if (strcmp("cn-northwest-1", region) == 0) {
90-
len += 3;
91-
is_cn = FLB_TRUE;
91+
else if (strcmp("eusc-de-east-1", region) == 0) {
92+
domain_suffix = AWS_SERVICE_ENDPOINT_SUFFIX_EU;
9293
}
9394

94-
len += strlen(service);
95+
len = strlen(service);
96+
len += 1; /* dot between service and region */
9597
len += strlen(region);
96-
len++; /* null byte */
98+
len += strlen(domain_suffix);
99+
len += 1; /* null byte */
97100

98101
endpoint = flb_calloc(len, sizeof(char));
99102
if (!endpoint) {
100103
flb_errno();
101104
return NULL;
102105
}
103106

104-
bytes = snprintf(endpoint, len, AWS_SERVICE_ENDPOINT_FORMAT, service, region);
107+
bytes = snprintf(endpoint, len, AWS_SERVICE_ENDPOINT_FORMAT, service, region, domain_suffix);
105108
if (bytes < 0) {
106109
flb_errno();
107110
flb_free(endpoint);
108111
return NULL;
109112
}
110113

111-
if (is_cn) {
112-
memcpy(endpoint + bytes, ".cn", 3);
113-
endpoint[bytes + 3] = '\0';
114-
}
115-
116114
return endpoint;
117115

118116
}

tests/internal/aws_util.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ static void test_flb_aws_endpoint()
163163
endpoint) == 0);
164164
flb_free(endpoint);
165165

166+
/* EU Sovereign Cloud regions have a different domain */
167+
endpoint = flb_aws_endpoint("cloudwatch", "eusc-de-east-1");
168+
169+
TEST_CHECK(strcmp("cloudwatch.eusc-de-east-1.amazonaws.eu",
170+
endpoint) == 0);
171+
flb_free(endpoint);
172+
166173
}
167174

168175
static void test_flb_get_s3_key_multi_tag_exists()

0 commit comments

Comments
 (0)