You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/12/31 18:05:08 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #3424: Derive Clone for ObjectStore builders (#3419)

tustvold opened a new pull request, #3424:
URL: https://github.com/apache/arrow-rs/pull/3424

   Make URL parsing more strict
   
   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #3419
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   No, this does not making any breaking changes to released APIs
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   
   FYI @roeap perhaps you would be able to review this :pray: 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] winding-lines commented on a diff in pull request #3424: Derive Clone for ObjectStore builders and Make URL Parsing Stricter (#3419)

Posted by GitBox <gi...@apache.org>.
winding-lines commented on code in PR #3424:
URL: https://github.com/apache/arrow-rs/pull/3424#discussion_r1059674714


##########
object_store/src/azure/mod.rs:
##########
@@ -365,10 +368,10 @@ pub struct MicrosoftAzureBuilder {
     tenant_id: Option<String>,
     sas_query_pairs: Option<Vec<(String, String)>>,
     authority_host: Option<String>,
+    url: Option<String>,

Review Comment:
   The MicrosoftAzureBuilder is missing the Clone in the derive list.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] alamb commented on a diff in pull request #3424: Derive Clone for ObjectStore builders and Make URL Parsing Stricter (#3419)

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #3424:
URL: https://github.com/apache/arrow-rs/pull/3424#discussion_r1059756304


##########
object_store/src/aws/mod.rs:
##########
@@ -465,44 +466,41 @@ impl AmazonS3Builder {
     ///     .with_url("s3://bucket/path")
     ///     .build();
     /// ```
-    pub fn with_url(mut self, url: impl AsRef<str>) -> Self {
-        let maybe_parsed = Url::parse(url.as_ref());
-        match maybe_parsed {
-            Ok(parsed) => match parsed.scheme() {
-                "s3" | "s3a" => {
-                    self.bucket_name = parsed.host_str().map(|host| host.to_owned());
-                }
-                "https" => {
-                    if let Some(host) = parsed.host_str() {
-                        let parts = host.splitn(4, '.').collect::<Vec<&str>>();
-                        if parts.len() == 4 && parts[0] == "s3" && parts[2] == "amazonaws"
-                        {
-                            self.bucket_name = Some(parts[1].to_string());
-                        }
-                        if parts.len() == 4
-                            && parts[1] == "s3"
-                            && parts[3] == "amazonaws.com"
-                        {
-                            self.bucket_name = Some(parts[0].to_string());
-                            self.region = Some(parts[2].to_string());
-                            self.virtual_hosted_style_request = true;
-                        }
-                    }
-                }
-                other => {
-                    self.url_parse_error = Some(Error::UnknownUrlScheme {
-                        scheme: other.into(),
-                    });
-                }
+    pub fn with_url(mut self, url: impl Into<String>) -> Self {
+        self.url = Some(url.into());
+        self
+    }
+
+    /// Sets properties on this builder based on a URL
+    ///
+    /// This is a separate member function to allow fallible computation to
+    /// be deferred until [`Self::build`] which in turn allows deriving [`Clone`]
+    fn parse_url(&mut self, url: &str) -> Result<()> {
+        let parsed = Url::parse(url).context(UnableToParseUrlSnafu { url })?;
+        let host = parsed.host_str().context(UrlNotRecognisedSnafu { url })?;
+        let bucket = match parsed.scheme() {
+            "s3" | "s3a" => match host.contains('.') {
+                false => host,
+                _ => return Err(UrlNotRecognisedSnafu { url }.build().into()),
             },
-            Err(err) => {
-                self.url_parse_error = Some(Error::UnableToParseUrl {
-                    source: err,
-                    url: url.as_ref().into(),
-                });
-            }
+            "https" => match host.strip_suffix(".amazonaws.com") {
+                Some(prefix) => match prefix.strip_prefix("s3.") {
+                    Some(b) => match b.contains('.') {
+                        false => b, // https://s3.<bucket>.amazonaws.com
+                        _ => return Err(UrlNotRecognisedSnafu { url }.build().into()),
+                    },
+                    _ => match prefix.split_once('.') {
+                        // https://<bucket>.s3.<region>.amazonaws.com
+                        Some((b, r)) if r.starts_with("s3.") => b,

Review Comment:
   I think we should make sure we cover this case with a test so we are sure it works / and it isn't broken in a future refactoring



##########
object_store/src/aws/mod.rs:
##########
@@ -1022,15 +1020,20 @@ mod tests {
 
     #[test]
     fn s3_test_urls() {
-        let builder = AmazonS3Builder::new().with_url("s3://bucket/path");
+        let mut builder = AmazonS3Builder::new();
+        builder.parse_url("s3://bucket/path").unwrap();
         assert_eq!(builder.bucket_name, Some("bucket".to_string()));
 
-        let builder = AmazonS3Builder::new().with_url("https://s3.bucket.amazonaws.com");
+        let mut builder = AmazonS3Builder::new();
+        builder
+            .parse_url("https://s3.bucket.amazonaws.com")
+            .unwrap();
         assert_eq!(builder.bucket_name, Some("bucket".to_string()));
 
-        let builder =
-            AmazonS3Builder::new().with_url("https://bucket.s3.region.amazonaws.com");
+        let mut builder = AmazonS3Builder::new();

Review Comment:
   perhaps should we add a test for parsing errors?
   
   (also applies to the other `test_urls` functions)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] winding-lines commented on pull request #3424: Derive Clone for ObjectStore builders and Make URL Parsing Stricter (#3419)

Posted by GitBox <gi...@apache.org>.
winding-lines commented on PR #3424:
URL: https://github.com/apache/arrow-rs/pull/3424#issuecomment-1368989651

   Many thanks! I have been looking into the verde support. The structs re-exported from http::headers do not work out of the box but I am close, I think. Will submit a PR after this one, unless @tustvold already started on it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] roeap commented on a diff in pull request #3424: Derive Clone for ObjectStore builders and Make URL Parsing Stricter (#3419)

Posted by GitBox <gi...@apache.org>.
roeap commented on code in PR #3424:
URL: https://github.com/apache/arrow-rs/pull/3424#discussion_r1059725335


##########
object_store/src/aws/mod.rs:
##########
@@ -465,44 +466,41 @@ impl AmazonS3Builder {
     ///     .with_url("s3://bucket/path")
     ///     .build();
     /// ```
-    pub fn with_url(mut self, url: impl AsRef<str>) -> Self {
-        let maybe_parsed = Url::parse(url.as_ref());
-        match maybe_parsed {
-            Ok(parsed) => match parsed.scheme() {
-                "s3" | "s3a" => {
-                    self.bucket_name = parsed.host_str().map(|host| host.to_owned());
-                }
-                "https" => {
-                    if let Some(host) = parsed.host_str() {
-                        let parts = host.splitn(4, '.').collect::<Vec<&str>>();
-                        if parts.len() == 4 && parts[0] == "s3" && parts[2] == "amazonaws"
-                        {
-                            self.bucket_name = Some(parts[1].to_string());
-                        }
-                        if parts.len() == 4
-                            && parts[1] == "s3"
-                            && parts[3] == "amazonaws.com"
-                        {
-                            self.bucket_name = Some(parts[0].to_string());
-                            self.region = Some(parts[2].to_string());
-                            self.virtual_hosted_style_request = true;
-                        }
-                    }
-                }
-                other => {
-                    self.url_parse_error = Some(Error::UnknownUrlScheme {
-                        scheme: other.into(),
-                    });
-                }
+    pub fn with_url(mut self, url: impl Into<String>) -> Self {
+        self.url = Some(url.into());
+        self
+    }
+
+    /// Sets properties on this builder based on a URL
+    ///
+    /// This is a separate member function to allow fallible computation to
+    /// be deferred until [`Self::build`] which in turn allows deriving [`Clone`]
+    fn parse_url(&mut self, url: &str) -> Result<()> {
+        let parsed = Url::parse(url).context(UnableToParseUrlSnafu { url })?;
+        let host = parsed.host_str().context(UrlNotRecognisedSnafu { url })?;
+        let bucket = match parsed.scheme() {
+            "s3" | "s3a" => match host.contains('.') {
+                false => host,
+                _ => return Err(UrlNotRecognisedSnafu { url }.build().into()),
             },
-            Err(err) => {
-                self.url_parse_error = Some(Error::UnableToParseUrl {
-                    source: err,
-                    url: url.as_ref().into(),
-                });
-            }
+            "https" => match host.strip_suffix(".amazonaws.com") {
+                Some(prefix) => match prefix.strip_prefix("s3.") {
+                    Some(b) => match b.contains('.') {
+                        false => b, // https://s3.<bucket>.amazonaws.com
+                        _ => return Err(UrlNotRecognisedSnafu { url }.build().into()),
+                    },
+                    _ => match prefix.split_once('.') {
+                        // https://<bucket>.s3.<region>.amazonaws.com
+                        Some((b, r)) if r.starts_with("s3.") => b,

Review Comment:
   Should we set `region` and `virtual_hosted_style_request` here before returning the bucket? Otherwise I think the user would have to set these separetely for things to work.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold merged pull request #3424: Derive Clone for ObjectStore builders and Make URL Parsing Stricter (#3419)

Posted by GitBox <gi...@apache.org>.
tustvold merged PR #3424:
URL: https://github.com/apache/arrow-rs/pull/3424


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] ursabot commented on pull request #3424: Derive Clone for ObjectStore builders and Make URL Parsing Stricter (#3419)

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #3424:
URL: https://github.com/apache/arrow-rs/pull/3424#issuecomment-1369007965

   Benchmark runs are scheduled for baseline = b371f41f338737b4e214d74b48e18939f5643a84 and contender = 1889e33da31218ee2c58ad874036b17b699538b9. 1889e33da31218ee2c58ad874036b17b699538b9 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/aeaf5389aafb45a6bb025096f39d453c...987c84c9a4db4a59a749e77a49da570d/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/064e1974d2bb4c08a13dd574bfc7f548...ce74f51989a846cb8e7ae65edb2f84b2/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/ef0263ac42184882a73bf9a0a8550eeb...edce6a3ae87840ba8abee3c4f5401211/)
   [Skipped :warning: Benchmarking of arrow-rs-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/ec0d6e1d2b7d4d0fba2975473942b9b0...9a0f6b6e27f142a2b14054992dd39a0f/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #3424: Derive Clone for ObjectStore builders and Make URL Parsing Stricter (#3419)

Posted by GitBox <gi...@apache.org>.
tustvold commented on code in PR #3424:
URL: https://github.com/apache/arrow-rs/pull/3424#discussion_r1059668165


##########
object_store/src/aws/mod.rs:
##########
@@ -465,44 +466,41 @@ impl AmazonS3Builder {
     ///     .with_url("s3://bucket/path")
     ///     .build();
     /// ```
-    pub fn with_url(mut self, url: impl AsRef<str>) -> Self {
-        let maybe_parsed = Url::parse(url.as_ref());
-        match maybe_parsed {
-            Ok(parsed) => match parsed.scheme() {
-                "s3" | "s3a" => {
-                    self.bucket_name = parsed.host_str().map(|host| host.to_owned());
-                }
-                "https" => {
-                    if let Some(host) = parsed.host_str() {
-                        let parts = host.splitn(4, '.').collect::<Vec<&str>>();
-                        if parts.len() == 4 && parts[0] == "s3" && parts[2] == "amazonaws"
-                        {
-                            self.bucket_name = Some(parts[1].to_string());
-                        }
-                        if parts.len() == 4
-                            && parts[1] == "s3"
-                            && parts[3] == "amazonaws.com"
-                        {
-                            self.bucket_name = Some(parts[0].to_string());
-                            self.region = Some(parts[2].to_string());
-                            self.virtual_hosted_style_request = true;
-                        }
-                    }
-                }
-                other => {
-                    self.url_parse_error = Some(Error::UnknownUrlScheme {
-                        scheme: other.into(),
-                    });
-                }
+    pub fn with_url(mut self, url: impl Into<String>) -> Self {
+        self.url = Some(url.into());
+        self
+    }
+
+    /// Sets properties on this builder based on a URL
+    ///
+    /// This is a separate member function to allow fallible computation to
+    /// be deferred until [`Self::build`] which in turn allows deriving [`Clone`]
+    fn parse_url(&mut self, url: &str) -> Result<()> {

Review Comment:
   Previously invalid URLs would be silently ignored, they now result in an error which I think makes for a better UX



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org