|
33 | 33 | #include <sys/stat.h> |
34 | 34 | #include <fcntl.h> |
35 | 35 |
|
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" |
38 | 40 |
|
39 | 41 | #define TAG_PART_DESCRIPTOR "$TAG[%d]" |
40 | 42 | #define TAG_DESCRIPTOR "$TAG" |
@@ -71,48 +73,44 @@ struct flb_http_client *request_do(struct flb_aws_client *aws_client, |
71 | 73 | size_t dynamic_headers_len); |
72 | 74 |
|
73 | 75 | /* |
74 | | - * https://service.region.amazonaws.com(.cn) |
| 76 | + * https://service.region.amazonaws.[com(.cn)|eu] |
75 | 77 | */ |
76 | 78 | char *flb_aws_endpoint(char* service, char* region) |
77 | 79 | { |
78 | 80 | 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; |
81 | 83 | int bytes; |
82 | 84 |
|
83 | 85 |
|
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; |
88 | 90 | } |
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; |
92 | 93 | } |
93 | 94 |
|
94 | | - len += strlen(service); |
| 95 | + len = strlen(service); |
| 96 | + len += 1; /* dot between service and region */ |
95 | 97 | len += strlen(region); |
96 | | - len++; /* null byte */ |
| 98 | + len += strlen(domain_suffix); |
| 99 | + len += 1; /* null byte */ |
97 | 100 |
|
98 | 101 | endpoint = flb_calloc(len, sizeof(char)); |
99 | 102 | if (!endpoint) { |
100 | 103 | flb_errno(); |
101 | 104 | return NULL; |
102 | 105 | } |
103 | 106 |
|
104 | | - bytes = snprintf(endpoint, len, AWS_SERVICE_ENDPOINT_FORMAT, service, region); |
| 107 | + bytes = snprintf(endpoint, len, AWS_SERVICE_ENDPOINT_FORMAT, service, region, domain_suffix); |
105 | 108 | if (bytes < 0) { |
106 | 109 | flb_errno(); |
107 | 110 | flb_free(endpoint); |
108 | 111 | return NULL; |
109 | 112 | } |
110 | 113 |
|
111 | | - if (is_cn) { |
112 | | - memcpy(endpoint + bytes, ".cn", 3); |
113 | | - endpoint[bytes + 3] = '\0'; |
114 | | - } |
115 | | - |
116 | 114 | return endpoint; |
117 | 115 |
|
118 | 116 | } |
|
0 commit comments