Skip to content
Open
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
40 changes: 19 additions & 21 deletions src/aws/flb_aws_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@
#include <sys/stat.h>
#include <fcntl.h>

#define AWS_SERVICE_ENDPOINT_FORMAT "%s.%s.amazonaws.com"
#define AWS_SERVICE_ENDPOINT_BASE_LEN 15
#define AWS_SERVICE_ENDPOINT_FORMAT "%s.%s%s"
#define AWS_SERVICE_ENDPOINT_SUFFIX_COM ".amazonaws.com"
#define AWS_SERVICE_ENDPOINT_SUFFIX_COM_CN ".amazonaws.com.cn"
#define AWS_SERVICE_ENDPOINT_SUFFIX_EU ".amazonaws.eu"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EuSC is available as preview and will soon be publicly launched as well. logs.eusc-de-east-1.amazonaws.eu does exist


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

/*
* https://service.region.amazonaws.com(.cn)
* https://service.region.amazonaws.[com(.cn)|eu]
*/
char *flb_aws_endpoint(char* service, char* region)
{
char *endpoint = NULL;
size_t len = AWS_SERVICE_ENDPOINT_BASE_LEN;
int is_cn = FLB_FALSE;
const char *domain_suffix = AWS_SERVICE_ENDPOINT_SUFFIX_COM;
size_t len;
int bytes;


/* In the China regions, ".cn" is appended to the URL */
if (strcmp("cn-north-1", region) == 0) {
len += 3;
is_cn = FLB_TRUE;
/* China regions end with amazonaws.com.cn */
if (strcmp("cn-north-1", region) == 0 ||
strcmp("cn-northwest-1", region) == 0) {
domain_suffix = AWS_SERVICE_ENDPOINT_SUFFIX_COM_CN;
}
if (strcmp("cn-northwest-1", region) == 0) {
len += 3;
is_cn = FLB_TRUE;
else if (strncmp(region, "eusc-", 5) == 0) {
domain_suffix = AWS_SERVICE_ENDPOINT_SUFFIX_EU;
}

len += strlen(service);
len = strlen(service);
len += 1; /* dot between service and region */
len += strlen(region);
len++; /* null byte */
len += strlen(domain_suffix);
len += 1; /* null byte */

endpoint = flb_calloc(len, sizeof(char));
if (!endpoint) {
flb_errno();
return NULL;
}

bytes = snprintf(endpoint, len, AWS_SERVICE_ENDPOINT_FORMAT, service, region);
if (bytes < 0) {
bytes = snprintf(endpoint, len, AWS_SERVICE_ENDPOINT_FORMAT, service, region, domain_suffix);
if (bytes < 0 || bytes >= len) {
flb_errno();
flb_free(endpoint);
return NULL;
}

if (is_cn) {
memcpy(endpoint + bytes, ".cn", 3);
endpoint[bytes + 3] = '\0';
}

return endpoint;

}
Expand Down
7 changes: 7 additions & 0 deletions tests/internal/aws_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ static void test_flb_aws_endpoint()
endpoint) == 0);
flb_free(endpoint);

/* EU Sovereign Cloud regions have a different domain */
endpoint = flb_aws_endpoint("cloudwatch", "eusc-de-east-1");

TEST_CHECK(strcmp("cloudwatch.eusc-de-east-1.amazonaws.eu",
endpoint) == 0);
flb_free(endpoint);

}

static void test_flb_get_s3_key_multi_tag_exists()
Expand Down