MCPcopy Create free account
hub / github.com/ByConity/ByConity / URI

Method URI

src/IO/S3Common.cpp:324–442  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 11

isS3SchemeFunction · 0.85
quoteStringFunction · 0.85
lengthMethod · 0.80
starts_withMethod · 0.80
ExceptionClass · 0.50
splitFunction · 0.50
emptyMethod · 0.45
toStringMethod · 0.45
getPathMethod · 0.45
getQueryMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected