steveloughran commented on code in PR #6507:
URL: https://github.com/apache/hadoop/pull/6507#discussion_r1512593751


##########
hadoop-project/pom.xml:
##########
@@ -1976,6 +1976,30 @@
         <artifactId>log4j-web</artifactId>
         <version>${log4j2.version}</version>
       </dependency>
+      <dependency>
+        <groupId>software.amazon.s3.accessgrants</groupId>
+        <artifactId>aws-s3-accessgrants-java-plugin</artifactId>
+        <version>2.0.0</version>
+        <scope>provided</scope>
+        <exclusions>
+          <exclusion>
+            <groupId>software.amazon.awssdk</groupId>
+            <artifactId>*</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>com.github.ben-manes.caffeine</groupId>
+            <artifactId>*</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.apache.logging.log4j</groupId>
+            <artifactId>*</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.assertj</groupId>

Review Comment:
   this should really be scoped as testing in the module itself...



##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/DefaultS3ClientFactory.java:
##########
@@ -401,4 +409,33 @@ private static Region getS3RegionFromEndpoint(final String 
endpoint,
     return Region.of(AWS_S3_DEFAULT_REGION);
   }
 
+  public static <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>, 
ClientT> void
+      applyS3AccessGrantsConfigurations(BuilderT builder, Configuration conf) {
+    boolean s3agEnabled = conf.getBoolean(AWS_S3_ACCESS_GRANTS_ENABLED, false);
+    if (!s3agEnabled){
+      LOG.debug("S3 Access Grants plugin is not enabled.");
+      return;
+    }
+    try {
+      LOG_S3AG_ENABLED.info("S3 Access Grants plugin is enabled.");
+      Class s3agUtil = Class.forName(S3AG_UTIL_CLASSNAME);
+      Method applyS3agConfig =
+          s3agUtil.getMethod("applyS3AccessGrantsConfigurations", 
S3BaseClientBuilder.class, Configuration.class);
+      applyS3agConfig.invoke(null, builder, conf);
+    } catch (ClassNotFoundException e) {
+      LOG.debug(
+          "Class {} is not found exception: {}.",
+          S3AG_UTIL_CLASSNAME,
+          e.getStackTrace()

Review Comment:
   1. pass in e and let the logger handle the rest.
   2. use multiple classes in the catch statement to avoid 
duplication/maintenance costs



##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/S3AccessGrantsUtil.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.s3a.impl;
+
+import org.apache.hadoop.conf.Configuration;

Review Comment:
   nit: import ordering. I will keep complaining about this on new classes, so 
learn them and we will both save time. There's a style file for intellij 
somewhere to help



##########
hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/s3_access_grants.md:
##########
@@ -0,0 +1,61 @@
+<!---
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License. See accompanying LICENSE file.
+-->
+
+# S3 Access Grants
+
+<!-- MACRO{toc|fromDepth=0|toDepth=5} -->
+
+S3 Access Grants is a credential vending service for S3 data. More information:
+* https://aws.amazon.com/s3/features/access-grants/

Review Comment:
   use bracketed links with [title] as well as (url)



##########
hadoop-project/pom.xml:
##########
@@ -1976,6 +1976,30 @@
         <artifactId>log4j-web</artifactId>
         <version>${log4j2.version}</version>
       </dependency>
+      <dependency>
+        <groupId>software.amazon.s3.accessgrants</groupId>
+        <artifactId>aws-s3-accessgrants-java-plugin</artifactId>
+        <version>2.0.0</version>

Review Comment:
   can you move this version flag into a property next to the other aws s3 
options, at least until this module is merged into bundle.jar. this makes it 
overrideable



##########
hadoop-project/pom.xml:
##########
@@ -1976,6 +1976,30 @@
         <artifactId>log4j-web</artifactId>
         <version>${log4j2.version}</version>
       </dependency>
+      <dependency>
+        <groupId>software.amazon.s3.accessgrants</groupId>
+        <artifactId>aws-s3-accessgrants-java-plugin</artifactId>
+        <version>2.0.0</version>
+        <scope>provided</scope>
+        <exclusions>
+          <exclusion>
+            <groupId>software.amazon.awssdk</groupId>
+            <artifactId>*</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>com.github.ben-manes.caffeine</groupId>

Review Comment:
   are you confident this isn't used?



##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AccessGrantConfiguration.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.s3a;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.test.AbstractHadoopTestBase;
+import org.junit.Test;
+
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
+import software.amazon.awssdk.services.s3.S3Client;
+
+import static org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_ENABLED;
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Test S3 Access Grants configurations.
+ */
+public class TestS3AccessGrantConfiguration extends AbstractHadoopTestBase {
+
+  @Test
+  public void testS3AccessGrantsEnabled() {
+    applyVerifyS3AGPlugin(S3Client.builder(), false, true);
+  }
+
+  @Test
+  public void testS3AccessGrantsEnabledAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), false, true);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabled() {
+    applyVerifyS3AGPlugin(S3Client.builder(), false, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledByDefault() {
+    applyVerifyS3AGPlugin(S3Client.builder(), true, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), false, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledByDefaultAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), true, false);
+  }
+
+  private Configuration createConfig(boolean isDefault, boolean s3agEnabled) {

Review Comment:
   add javadoc



##########
hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/s3_access_grants.md:
##########
@@ -0,0 +1,61 @@
+<!---
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License. See accompanying LICENSE file.
+-->
+
+# S3 Access Grants
+
+<!-- MACRO{toc|fromDepth=0|toDepth=5} -->
+
+S3 Access Grants is a credential vending service for S3 data. More information:
+* https://aws.amazon.com/s3/features/access-grants/
+
+In S3A, S3 Access Grants Plugin is used to support S3 Access Grants. More 
information:
+* https://github.com/aws/aws-s3-accessgrants-plugin-java-v2/
+
+
+
+## How to enable S3 Access Grants in S3A
+
+1. Add the `hadoop-aws` JAR on your classpath.
+
+1. Add the `aws-java-sdk-bundle.jar` JAR to your classpath, the minimum 
version is v2.23.7.
+
+2. Add the `aws-s3-accessgrants-java-plugin-2.0.0.jar` JAR to your classpath.
+3. Add the `caffeine.jar` JAR to your classpath.

Review Comment:
   ok, if it is compulsory then leave it as an access grant dependency. 



##########
hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/s3_access_grants.md:
##########
@@ -0,0 +1,61 @@
+<!---
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License. See accompanying LICENSE file.
+-->
+
+# S3 Access Grants
+
+<!-- MACRO{toc|fromDepth=0|toDepth=5} -->
+
+S3 Access Grants is a credential vending service for S3 data. More information:
+* https://aws.amazon.com/s3/features/access-grants/
+
+In S3A, S3 Access Grants Plugin is used to support S3 Access Grants. More 
information:
+* https://github.com/aws/aws-s3-accessgrants-plugin-java-v2/
+
+
+
+## How to enable S3 Access Grants in S3A
+
+1. Add the `hadoop-aws` JAR on your classpath.
+
+1. Add the `aws-java-sdk-bundle.jar` JAR to your classpath, the minimum 
version is v2.23.7.

Review Comment:
   cut this. name is wrong and version is already out of date



##########
hadoop-tools/hadoop-aws/pom.xml:
##########
@@ -508,6 +508,29 @@
       <artifactId>bundle</artifactId>
       <scope>compile</scope>
     </dependency>
+    <dependency>
+      <groupId>software.amazon.s3.accessgrants</groupId>

Review Comment:
   @ahmarsuhail put in the work to get s3 express in



##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AccessGrantConfiguration.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.s3a;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.test.AbstractHadoopTestBase;
+import org.junit.Test;
+
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
+import software.amazon.awssdk.services.s3.S3Client;
+
+import static org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_ENABLED;
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Test S3 Access Grants configurations.
+ */
+public class TestS3AccessGrantConfiguration extends AbstractHadoopTestBase {
+
+  @Test
+  public void testS3AccessGrantsEnabled() {
+    applyVerifyS3AGPlugin(S3Client.builder(), false, true);
+  }
+
+  @Test
+  public void testS3AccessGrantsEnabledAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), false, true);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabled() {
+    applyVerifyS3AGPlugin(S3Client.builder(), false, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledByDefault() {
+    applyVerifyS3AGPlugin(S3Client.builder(), true, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), false, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledByDefaultAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), true, false);
+  }
+
+  private Configuration createConfig(boolean isDefault, boolean s3agEnabled) {
+    Configuration conf = new Configuration();
+    if (!isDefault){
+      conf.setBoolean(AWS_S3_ACCESS_GRANTS_ENABLED, s3agEnabled);
+    }
+    return conf;
+  }
+
+  private <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>, ClientT> 
void
+  applyVerifyS3AGPlugin(BuilderT builder, boolean isDefault, boolean enabled) {
+    DefaultS3ClientFactory.applyS3AccessGrantsConfigurations(builder, 
createConfig(isDefault, enabled));
+    if (enabled){
+      assertEquals(1, builder.plugins().size());
+      
assertEquals("software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin",

Review Comment:
   use assertj asserts here



##########
hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/s3_access_grants.md:
##########
@@ -0,0 +1,61 @@
+<!---
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License. See accompanying LICENSE file.
+-->
+
+# S3 Access Grants
+
+<!-- MACRO{toc|fromDepth=0|toDepth=5} -->
+
+S3 Access Grants is a credential vending service for S3 data. More information:
+* https://aws.amazon.com/s3/features/access-grants/
+
+In S3A, S3 Access Grants Plugin is used to support S3 Access Grants. More 
information:
+* https://github.com/aws/aws-s3-accessgrants-plugin-java-v2/
+
+
+
+## How to enable S3 Access Grants in S3A
+
+1. Add the `hadoop-aws` JAR on your classpath.

Review Comment:
   just say "hadoop-aws JAR of the hadoop release and the normal dependencies, 
including bundle.jar
   
   (gives us scope to add more mandatory stuff; i think wildfly is there 
already)



##########
hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/s3_access_grants.md:
##########
@@ -0,0 +1,61 @@
+<!---
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License. See accompanying LICENSE file.
+-->
+
+# S3 Access Grants
+
+<!-- MACRO{toc|fromDepth=0|toDepth=5} -->
+
+S3 Access Grants is a credential vending service for S3 data. More information:
+* https://aws.amazon.com/s3/features/access-grants/
+
+In S3A, S3 Access Grants Plugin is used to support S3 Access Grants. More 
information:
+* https://github.com/aws/aws-s3-accessgrants-plugin-java-v2/
+
+
+
+## How to enable S3 Access Grants in S3A
+
+1. Add the `hadoop-aws` JAR on your classpath.
+
+1. Add the `aws-java-sdk-bundle.jar` JAR to your classpath, the minimum 
version is v2.23.7.
+
+2. Add the `aws-s3-accessgrants-java-plugin-2.0.0.jar` JAR to your classpath.
+3. Add the `caffeine.jar` JAR to your classpath.
+
+1. Add configurations to enable S3 Access Grants in `core-site.xml`
+
+
+
+Example:
+
+```xml
+<configuration>
+...
+    <property>

Review Comment:
   nit: use two chars for indentation



##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AccessGrantConfiguration.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.s3a;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.test.AbstractHadoopTestBase;
+import org.junit.Test;
+
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
+import software.amazon.awssdk.services.s3.S3Client;
+
+import static org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_ENABLED;
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Test S3 Access Grants configurations.
+ */
+public class TestS3AccessGrantConfiguration extends AbstractHadoopTestBase {
+
+  @Test
+  public void testS3AccessGrantsEnabled() {
+    applyVerifyS3AGPlugin(S3Client.builder(), false, true);
+  }
+
+  @Test
+  public void testS3AccessGrantsEnabledAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), false, true);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabled() {
+    applyVerifyS3AGPlugin(S3Client.builder(), false, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledByDefault() {
+    applyVerifyS3AGPlugin(S3Client.builder(), true, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), false, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledByDefaultAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), true, false);
+  }
+
+  private Configuration createConfig(boolean isDefault, boolean s3agEnabled) {
+    Configuration conf = new Configuration();
+    if (!isDefault){
+      conf.setBoolean(AWS_S3_ACCESS_GRANTS_ENABLED, s3agEnabled);
+    }
+    return conf;
+  }
+
+  private <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>, ClientT> 
void
+  applyVerifyS3AGPlugin(BuilderT builder, boolean isDefault, boolean enabled) {
+    DefaultS3ClientFactory.applyS3AccessGrantsConfigurations(builder, 
createConfig(isDefault, enabled));
+    if (enabled){
+      assertEquals(1, builder.plugins().size());

Review Comment:
   assert j assert on .hasSize() for list



##########
hadoop-tools/hadoop-aws/src/site/markdown/tools/hadoop-aws/s3_access_grants.md:
##########
@@ -0,0 +1,61 @@
+<!---
+  Licensed under the Apache License, Version 2.0 (the "License");
+  you may not use this file except in compliance with the License.
+  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License. See accompanying LICENSE file.
+-->
+
+# S3 Access Grants
+
+<!-- MACRO{toc|fromDepth=0|toDepth=5} -->
+
+S3 Access Grants is a credential vending service for S3 data. More information:
+* https://aws.amazon.com/s3/features/access-grants/
+
+In S3A, S3 Access Grants Plugin is used to support S3 Access Grants. More 
information:
+* https://github.com/aws/aws-s3-accessgrants-plugin-java-v2/
+
+
+
+## How to enable S3 Access Grants in S3A
+
+1. Add the `hadoop-aws` JAR on your classpath.
+
+1. Add the `aws-java-sdk-bundle.jar` JAR to your classpath, the minimum 
version is v2.23.7.
+
+2. Add the `aws-s3-accessgrants-java-plugin-2.0.0.jar` JAR to your classpath.

Review Comment:
   don't state the version; adds more work and will go out of date fast.



##########
hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/TestS3AccessGrantConfiguration.java:
##########
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.s3a;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.test.AbstractHadoopTestBase;
+import org.junit.Test;
+
+import software.amazon.awssdk.services.s3.S3AsyncClient;
+import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
+import software.amazon.awssdk.services.s3.S3Client;
+
+import static org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_ENABLED;
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Test S3 Access Grants configurations.
+ */
+public class TestS3AccessGrantConfiguration extends AbstractHadoopTestBase {
+
+  @Test
+  public void testS3AccessGrantsEnabled() {
+    applyVerifyS3AGPlugin(S3Client.builder(), false, true);
+  }
+
+  @Test
+  public void testS3AccessGrantsEnabledAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), false, true);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabled() {
+    applyVerifyS3AGPlugin(S3Client.builder(), false, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledByDefault() {
+    applyVerifyS3AGPlugin(S3Client.builder(), true, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), false, false);
+  }
+
+  @Test
+  public void testS3AccessGrantsDisabledByDefaultAsync() {
+    applyVerifyS3AGPlugin(S3AsyncClient.builder(), true, false);
+  }
+
+  private Configuration createConfig(boolean isDefault, boolean s3agEnabled) {
+    Configuration conf = new Configuration();
+    if (!isDefault){
+      conf.setBoolean(AWS_S3_ACCESS_GRANTS_ENABLED, s3agEnabled);
+    }
+    return conf;
+  }
+
+  private <BuilderT extends S3BaseClientBuilder<BuilderT, ClientT>, ClientT> 
void
+  applyVerifyS3AGPlugin(BuilderT builder, boolean isDefault, boolean enabled) {
+    DefaultS3ClientFactory.applyS3AccessGrantsConfigurations(builder, 
createConfig(isDefault, enabled));
+    if (enabled){
+      assertEquals(1, builder.plugins().size());
+      
assertEquals("software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin",
+          builder.plugins().get(0).getClass().getName()
+          );
+    }
+    else {
+      assertEquals(builder.plugins().size(), 0);

Review Comment:
   assertj



##########
hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/impl/S3AccessGrantsUtil.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hadoop.fs.s3a.impl;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.hadoop.fs.s3a.DefaultS3ClientFactory;
+import org.apache.hadoop.fs.store.LogExactlyOnce;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.s3accessgrants.plugin.S3AccessGrantsPlugin;
+import software.amazon.awssdk.services.s3.S3BaseClientBuilder;
+
+import static 
org.apache.hadoop.fs.s3a.Constants.AWS_S3_ACCESS_GRANTS_FALLBACK_TO_IAM_ENABLED;
+
+public class S3AccessGrantsUtil {

Review Comment:
   1. javadocs here and on methods below.
   2. mark as final and give a private constructor



-- 
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: common-issues-unsubscr...@hadoop.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to