iSparshP commented on code in PR #7777:
URL: https://github.com/apache/datafusion-comet/pull/7777#discussion_r4768428143


##########
native/core/src/execution/operators/parquet_writer.rs:
##########
@@ -572,6 +572,55 @@ impl ParquetWriterExec {
     }
 }
 
+impl Debug for ParquetWriterExec {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+        f.debug_struct("ParquetWriterExec")
+            .field("input", &self.input)
+            .field("output_path", &RedactedPath(&self.output_path))
+            .field("compression", &self.compression)
+            .field("partition_id", &self.partition_id)
+            .field("column_names", &self.column_names)
+            .field("output_schema", &self.output_schema)
+            .field("spark_version", &self.spark_version)
+            .field(
+                "object_store_options",
+                &RedactedOptions(&self.object_store_options),
+            )
+            .field("output_stream", &self.output_stream)
+            .field("metrics", &self.metrics)
+            .field("cache", &self.cache)
+            .finish()
+    }
+}
+
+/// Drops the userinfo and query, which can hold a password, access key ID or 
SAS token.
+struct RedactedPath<'a>(&'a str);
+
+impl Debug for RedactedPath<'_> {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+        match Url::parse(self.0) {
+            Ok(url) => Debug::fmt(without_credentials(&url).as_str(), f),
+            // Credentials cannot be stripped from a path that does not parse.
+            Err(_) => f.write_str("<unparseable>"),
+        }
+    }
+}
+
+/// Shows the option keys but not their values, which can hold object store 
credentials.
+struct RedactedOptions<'a>(&'a HashMap<String, String>);

Review Comment:
   done, moved it into operators/mod.rs as RedactedValues with sorted keys. 
IcebergScanExec uses it now too and both private copies are gone.



##########
native/core/src/execution/operators/parquet_writer.rs:
##########
@@ -572,6 +572,55 @@ impl ParquetWriterExec {
     }
 }
 
+impl Debug for ParquetWriterExec {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+        f.debug_struct("ParquetWriterExec")
+            .field("input", &self.input)
+            .field("output_path", &RedactedPath(&self.output_path))
+            .field("compression", &self.compression)
+            .field("partition_id", &self.partition_id)
+            .field("column_names", &self.column_names)
+            .field("output_schema", &self.output_schema)
+            .field("spark_version", &self.spark_version)
+            .field(
+                "object_store_options",
+                &RedactedOptions(&self.object_store_options),
+            )
+            .field("output_stream", &self.output_stream)
+            .field("metrics", &self.metrics)
+            .field("cache", &self.cache)
+            .finish()
+    }
+}
+
+/// Drops the userinfo and query, which can hold a password, access key ID or 
SAS token.
+struct RedactedPath<'a>(&'a str);
+
+impl Debug for RedactedPath<'_> {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
+        match Url::parse(self.0) {
+            Ok(url) => Debug::fmt(without_credentials(&url).as_str(), f),
+            // Credentials cannot be stripped from a path that does not parse.
+            Err(_) => f.write_str("<unparseable>"),

Review Comment:
   went with following the scheme: abfs/abfss/wasb/wasbs/az go through 
without_secrets so the container stays, everything else still uses 
without_credentials. the container isn't a secret and it's what you need to 
find the file in a plan dump, the password and sas query still get dropped. 
added an abfss case to the test.



##########
native/core/src/execution/operators/parquet_writer.rs:
##########
@@ -1418,6 +1467,30 @@ mod tests {
         );
     }
 
+    #[test]
+    fn test_parquet_writer_debug_redacts_credentials() -> Result<()> {
+        let schema = Arc::new(Schema::new(vec![Field::new("id", 
DataType::Int32, true)]));
+        let memory_source = MemorySourceConfig::try_new(&[vec![]], 
Arc::clone(&schema), None)?;
+        let writer = ParquetWriterExec::try_new(
+            Arc::new(DataSourceExec::new(Arc::new(memory_source))),
+            
"s3a://AKIDEXAMPLE:s3cretpw@bucket/part-00000.parquet?sig=sastoken".to_string(),
+            ParquetCompression::None,
+            0,
+            vec!["id".to_string()],
+            None,
+            HashMap::from([("fs.s3a.secret.key".to_string(), 
"supersecret".to_string())]),
+        )?;
+
+        let debug = format!("{writer:?}");
+        assert!(debug.contains("s3a://bucket/part-00000.parquet"), "{debug}");
+        assert!(debug.contains("fs.s3a.secret.key"), "{debug}");
+        for secret in ["AKIDEXAMPLE", "s3cretpw", "sastoken", "supersecret"] {

Review Comment:
   added it, Url::parse does reject the bad port so it hits the <unparseable> 
branch, and the first url now has a fragment too. the test checks none of the 
secrets show up for any of the paths.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to