| 322 | } |
| 323 | |
| 324 | URI::URI(const Poco::URI & uri_, bool parse_region) |
| 325 | { |
| 326 | /// Case when bucket name represented in domain name of S3 URL. |
| 327 | /// E.g. (https://bucket-name.s3.Region.amazonaws.com/key) |
| 328 | /// https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html#virtual-hosted-style-access |
| 329 | |
| 330 | static const RE2 virtual_hosted_style_pattern(R"((.+)\.(s3|cos|tos)([.\-][a-z0-9\-.:]+))"); |
| 331 | |
| 332 | |
| 333 | /// Case when bucket name and key represented in path of S3 URL. |
| 334 | /// E.g. (https://s3.Region.amazonaws.com/bucket-name/key) |
| 335 | /// https://docs.aws.amazon.com/AmazonS3/latest/dev/VirtualHosting.html#path-style-access |
| 336 | static const RE2 path_style_pattern("^/([^/]*)/(.*)"); |
| 337 | |
| 338 | static constexpr auto S3 = "S3"; |
| 339 | static constexpr auto COSN = "COSN"; |
| 340 | static constexpr auto COS = "COS"; |
| 341 | static constexpr auto TOS = "TOS"; |
| 342 | |
| 343 | |
| 344 | uri = uri_; |
| 345 | storage_name = S3; |
| 346 | |
| 347 | if (uri.getHost().empty()) |
| 348 | throw Exception("Host is empty in S3 URI: " + uri.toString(), ErrorCodes::BAD_ARGUMENTS); |
| 349 | |
| 350 | if (isS3Scheme(uri.getScheme())) |
| 351 | { |
| 352 | // URI has format s3://bucket/key |
| 353 | endpoint = ""; |
| 354 | bucket = uri.getAuthority(); |
| 355 | validateBucket(bucket, uri); |
| 356 | if (uri.getPath().length() <= 1) |
| 357 | throw Exception("Invalid S3 URI: no key: " + uri.toString(), ErrorCodes::BAD_ARGUMENTS); |
| 358 | if (!uri.getQuery().empty()) |
| 359 | key = uri.getPathAndQuery().substr(1); |
| 360 | else |
| 361 | key = uri.getPath().substr(1); |
| 362 | is_virtual_hosted_style = false; |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | String name; |
| 367 | String endpoint_authority_from_uri; |
| 368 | String endpoint_without_scheme; |
| 369 | |
| 370 | if (re2::RE2::FullMatch(uri.getAuthority(), virtual_hosted_style_pattern, &bucket, &name, &endpoint_authority_from_uri)) |
| 371 | { |
| 372 | is_virtual_hosted_style = true; |
| 373 | endpoint_without_scheme = name + endpoint_authority_from_uri; |
| 374 | endpoint = uri.getScheme() + "://" + endpoint_without_scheme; |
| 375 | |
| 376 | /// S3 specification requires at least 3 and at most 63 characters in bucket name. |
| 377 | /// https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-s3-bucket-naming-requirements.html |
| 378 | if (bucket.length() < 3 || bucket.length() > 63) |
| 379 | throw Exception("Bucket name length is out of bounds in virtual hosted style S3 URI: " |
| 380 | + quoteString(bucket) + "(" + uri.toString() + ")", ErrorCodes::BAD_ARGUMENTS); |
| 381 |
nothing calls this directly
no test coverage detected