You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "JiriOndrusek (via GitHub)" <gi...@apache.org> on 2023/02/02 14:01:10 UTC

[GitHub] [camel-quarkus] JiriOndrusek opened a new pull request, #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

JiriOndrusek opened a new pull request, #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474

   fixes https://github.com/apache/camel-quarkus/issues/4442
   (follows https://github.com/apache/camel-quarkus/issues/4401)
   
   PR extends `camel-quarkus-integration-tests-support-aws2` to cover tests with default credentials provider without a lot of changes in each aws2 test module.
   To fully use the support there are a few requirements for each aws2 test module:
   
   1. Add  dependencies of both flavors (of `camel-quarkus-integration-tests-support-aws2`) into the pom:
   
   ```
           <dependency>
               <groupId>org.apache.camel.quarkus</groupId>
               <artifactId>camel-quarkus-integration-tests-support-aws2</artifactId>
           </dependency>
           <dependency>
               <groupId>org.apache.camel.quarkus</groupId>
               <artifactId>camel-quarkus-integration-tests-support-aws2</artifactId>
               <type>test-jar</type>
               <scope>test</scope>
           </dependency>
   ```
   
   2. Extend `BaseAws2Resource` by the resource class.
   3. Extend `BaseAWs2TestSupport` by the test class.
   4. Add parameter `"?useDefaultCredentialsProvider=" + useDefaultCredentials` into endpoint url called from the resource.
   5. Implement simple test method (overriding) `testMethodForDefaultCredentialsProvider()`
   
   If all items are satisfied, 2 new tests are executed for the test module (`failingDefaultCredentialsProviderTest` and `successfulDefaultCredentialsProviderTest`).
   One covers positive scenario, the other negative scenario.
   
   Be aware that the tests are executed only with **mocked backend**, **without quarkus client**, and only in case that **awsDefaultCredentialsProvider is not defined on the system**. Otherwise tests are skipped. See `Aws2DefaultCredentialsProviderAvailabilityCondition`.
   
    
   
   - Cw: Tests were refactored to use helper methods from aws-support.
   - Kinesis: Test class was split into kinesis & firehose test classes to cover default credentials testing for  both extensions.
   - S3: Name of the rest resource used for testing was renamed to the same pattern as other aws2 testing extensions.
   
   <!-- Uncomment and fill this section if your PR is not trivial
   [ ] An issue should be filed for the change unless this is a trivial change (fixing a typo or similar). One issue should ideally be fixed by not more than one commit and the other way round, each commit should fix just one issue, without pulling in other changes.
   [ ] Each commit in the pull request should have a meaningful and properly spelled subject line and body. Copying the title of the associated issue is typically enough. Please include the issue number in the commit message prefixed by #.
   [ ] The pull request description should explain what the pull request does, how, and why. If the info is available in the associated issue or some other external document, a link is enough.
   [ ] Phrases like Fix #<issueNumber> or Fixes #<issueNumber> will auto-close the named issue upon merging the pull request. Using them is typically a good idea.
   [ ] Please run mvn process-resources -Pformat (and amend the changes if necessary) before sending the pull request.
   [ ] Contributor guide is your good friend: https://camel.apache.org/camel-quarkus/latest/contributor-guide.html
   -->


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094592955


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2Helper.java:
##########
@@ -0,0 +1,35 @@
+package org.apache.camel.quarkus.test.support.aws2;
+
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.core.exception.SdkClientException;
+
+public class Aws2Helper {
+
+    public static final String UNABLE_TO_LOAD_CREDENTIALS_MSG = "Unable to load credentials";
+
+    public static boolean isDefaultCredentialsProviderDefinedOnSystem() {
+        try {
+            DefaultCredentialsProvider.create().resolveCredentials();
+        } catch (Exception e) {
+            //if message starts with "Unable to load credentials", allow testing
+            if (e instanceof SdkClientException && e.getMessage() != null
+                    && e.getMessage().startsWith(UNABLE_TO_LOAD_CREDENTIALS_MSG)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static void setAwsSysteCredentials(String accessKey, String secretKey) {

Review Comment:
   fixed



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094585928


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2Helper.java:
##########
@@ -0,0 +1,35 @@
+package org.apache.camel.quarkus.test.support.aws2;
+
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.core.exception.SdkClientException;
+
+public class Aws2Helper {
+
+    public static final String UNABLE_TO_LOAD_CREDENTIALS_MSG = "Unable to load credentials";
+
+    public static boolean isDefaultCredentialsProviderDefinedOnSystem() {
+        try {
+            DefaultCredentialsProvider.create().resolveCredentials();
+        } catch (Exception e) {
+            //if message starts with "Unable to load credentials", allow testing
+            if (e instanceof SdkClientException && e.getMessage() != null
+                    && e.getMessage().startsWith(UNABLE_TO_LOAD_CREDENTIALS_MSG)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static void setAwsSysteCredentials(String accessKey, String secretKey) {
+        System.setProperty("aws.accessKeyId", accessKey);
+        System.setProperty("aws.secretAccessKey", secretKey);
+
+    }
+
+    public static void clearAwsSysteCredentials() {

Review Comment:
   I'll replace it cross the PR:)



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] aldettinger commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094737141


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import javax.enterprise.event.Observes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.runtime.ShutdownEvent;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
+
+/**
+ * Parent for testing resources for aws2 extensions.
+ *
+ * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials
+ * to be used in inherited classes.
+ *
+ * Rest endpoints are expected by test classes.
+ */
+public class BaseAws2Resource {
+
+    private static final Logger LOG = Logger.getLogger(BaseAws2Resource.class);
+
+    protected boolean useDefaultCredentials;
+
+    private final String serviceName;
+
+    private boolean clearAwsredentials;
+
+    public BaseAws2Resource(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+    @Path("/setUseDefaultCredentialsProvider")
+    @POST
+    public Response setUseDefaultCredentials(boolean useDefaultCredentialsProvider) throws Exception {
+        this.useDefaultCredentials = useDefaultCredentialsProvider;
+        return Response.ok().build();
+    }
+
+    @Path("/initializeDefaultCredentials")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response initializeDefaultCredentials(boolean initialize) throws Exception {
+        if (initialize) {
+            //set flag to clear at the end
+            clearAwsredentials = true;
+            LOG.debug(
+                    "Setting both System.properties `aws.secretAccessKey` and `aws.accessKeyId` to cover defaultCredentialsProviderTest.");
+            //defaultCredentials provider gets the credentials from fixed location. One of them is system.properties,
+            //therefore to succeed the test, system.properties has to be initialized with the values from the configuration
+            Aws2Helper.setAwsSystemCredentials(
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".access-key", String.class),
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".secret-key", String.class));
+
+        } else {
+            LOG.debug("Clearing both System.properties `aws.secretAccessKey` and `aws.accessKeyId`.");
+            Aws2Helper.clearAwsSystemCredentials();
+            clearAwsredentials = false;
+        }
+
+        return Response.ok().build();
+    }
+
+    /**
+     * Listeners ensures, that system credentials are cleared at the end of the lifecycle.
+     * Tests are clearing them by itself, this is just a precaution.
+     */

Review Comment:
   As far as I get, the `onStop` listener is called when quarkus shutdown.
   
   The question would be more like, do we have situations where we set properties, then exception is thrown without cleanup. And then, a next test would fail because the properties was not cleaned up.



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] aldettinger commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094739427


##########
integration-tests-support/aws2/src/test/java/org/apache/camel/quarkus/test/support/aws2/BaseAWs2TestSupport.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import io.restassured.RestAssured;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Parent for aws test classes which should cover default credentials test case.
+ * Parent adds two test methods {@link #successfulDefaultCredentialsProviderTest()} and
+ * {@link #failingDefaultCredentialsProviderTest()}
+ *
+ * Test expects that test resource extends {@link BaseAws2Resource}.
+ *
+ */
+public abstract class BaseAWs2TestSupport {
+
+    //Rest path to connect to rest resource. Path differs for different aws2 extensions (like "/aws2-ddb" or "/aws2-s3"
+    private final String restPath;
+
+    public BaseAWs2TestSupport(String restPath) {
+        this.restPath = restPath;
+    }
+
+    /**
+     * Testing method used for {@link #successfulDefaultCredentialsProviderTest()} and
+     * {@link #failingDefaultCredentialsProviderTest()}.
+     *
+     * This method is called twice.
+     * 1 - Credentials are not set, therefore this method should fail.
+     * 2 - Credentials are set, there this method should succeed.
+     *
+     * Returns true if test passes, fa;se otherwise.
+     */
+    public abstract void testMethodForDefaultCredentialsProvider();
+
+    //test can be executed only if mock backend is used and no defaultCredentialsProvider is defined in the system
+    @ExtendWith(Aws2DefaultCredentialsProviderAvailabilityCondition.class)
+    @Test
+    public void successfulDefaultCredentialsProviderTest() {
+        try {
+            RestAssured.given()
+                    .body(true)
+                    .post(restPath + "/setUseDefaultCredentialsProvider")
+                    .then()
+                    .statusCode(200);
+
+            RestAssured.given()
+                    .body(true)
+                    .post(restPath + "/initializeDefaultCredentials")
+                    .then()
+                    .statusCode(200);
+
+            //should succeed
+            testMethodForDefaultCredentialsProvider();
+
+        } finally {
+            RestAssured.given()

Review Comment:
   ok, that was the missing part :+1 Thanks



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] ppalaga merged pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "ppalaga (via GitHub)" <gi...@apache.org>.
ppalaga merged PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] aldettinger commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094581880


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import javax.enterprise.event.Observes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.runtime.ShutdownEvent;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
+
+/**
+ * Parent for testing resources for aws2 extensions.
+ *
+ * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials

Review Comment:
   protected variable ?



##########
integration-tests-support/aws2/src/test/java/org/apache/camel/quarkus/test/support/aws2/BaseAWs2TestSupport.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import io.restassured.RestAssured;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Parent for aws test classes which should cover default credentials test case.
+ * Parent adds two test methods {@link #successfulDefaultCredentialsProviderTest()} and
+ * {@link #failingDefaultCredentialsProviderTest()}
+ *
+ * Test expects that test resource extends {@link BaseAws2Resource}.
+ *
+ */
+public abstract class BaseAWs2TestSupport {
+
+    //Rest path to connect to rest resource. Path differs for different aws2 extensions (like "/aws2-ddb" or "/aws2-s3"

Review Comment:
   We may close the ")" ?



##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import javax.enterprise.event.Observes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.runtime.ShutdownEvent;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
+
+/**
+ * Parent for testing resources for aws2 extensions.
+ *
+ * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials
+ * to be used in inherited classes.
+ *
+ * Rest endpoints are expected by test classes.
+ */
+public class BaseAws2Resource {
+
+    private static final Logger LOG = Logger.getLogger(BaseAws2Resource.class);
+
+    protected boolean useDefaultCredentials;
+
+    private final String serviceName;
+
+    private boolean clearAwsredentials;
+
+    public BaseAws2Resource(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+    @Path("/setUseDefaultCredentialsProvider")
+    @POST
+    public Response setUseDefaultCredentials(boolean useDefaultCredentialsProvider) throws Exception {
+        this.useDefaultCredentials = useDefaultCredentialsProvider;
+        return Response.ok().build();
+    }
+
+    @Path("/initializeDefaultCredentials")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response initializeDefaultCredentials(boolean initialize) throws Exception {
+        if (initialize) {
+            //set flag to clear at the end
+            clearAwsredentials = true;
+            LOG.debug(
+                    "Setting both System.properties `aws.secretAccessKey` and `aws.accessKeyId` to cover defaultCredentialsProviderTest.");
+            //defaultCredentials provider gets the credentials from fixed location. One of them is system.properties,
+            //therefore to succeed the test, system.properties has to be initialized with the values from the configuration
+            Aws2Helper.setAwsSystemCredentials(
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".access-key", String.class),
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".secret-key", String.class));
+
+        } else {
+            LOG.debug("Clearing both System.properties `aws.secretAccessKey` and `aws.accessKeyId`.");
+            Aws2Helper.clearAwsSystemCredentials();
+            clearAwsredentials = false;
+        }
+
+        return Response.ok().build();
+    }
+
+    /**
+     * Listeners ensures, that system credentials are cleared at the end of the lifecycle.
+     * Tests are clearing them by itself, this is just a precaution.
+     */

Review Comment:
   Are we also clearing the properties when an unexpected exception is thrown during a test ?



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] aldettinger commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094580006


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2Helper.java:
##########
@@ -0,0 +1,35 @@
+package org.apache.camel.quarkus.test.support.aws2;
+
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.core.exception.SdkClientException;
+
+public class Aws2Helper {
+
+    public static final String UNABLE_TO_LOAD_CREDENTIALS_MSG = "Unable to load credentials";
+
+    public static boolean isDefaultCredentialsProviderDefinedOnSystem() {
+        try {
+            DefaultCredentialsProvider.create().resolveCredentials();
+        } catch (Exception e) {
+            //if message starts with "Unable to load credentials", allow testing
+            if (e instanceof SdkClientException && e.getMessage() != null
+                    && e.getMessage().startsWith(UNABLE_TO_LOAD_CREDENTIALS_MSG)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static void setAwsSysteCredentials(String accessKey, String secretKey) {
+        System.setProperty("aws.accessKeyId", accessKey);
+        System.setProperty("aws.secretAccessKey", secretKey);
+
+    }
+
+    public static void clearAwsSysteCredentials() {

Review Comment:
   Same way: System ?



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] jamesnetherton commented on pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "jamesnetherton (via GitHub)" <gi...@apache.org>.
jamesnetherton commented on PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#issuecomment-1429368985

   @JiriOndrusek can you rebase this with the latest work from `main`. If CI is good we can merge.


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094623218


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import javax.enterprise.event.Observes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.runtime.ShutdownEvent;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
+
+/**
+ * Parent for testing resources for aws2 extensions.
+ *
+ * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials
+ * to be used in inherited classes.
+ *
+ * Rest endpoints are expected by test classes.
+ */
+public class BaseAws2Resource {
+
+    private static final Logger LOG = Logger.getLogger(BaseAws2Resource.class);
+
+    protected boolean useDefaultCredentials;
+
+    private final String serviceName;
+
+    private boolean clearAwsredentials;
+
+    public BaseAws2Resource(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+    @Path("/setUseDefaultCredentialsProvider")
+    @POST
+    public Response setUseDefaultCredentials(boolean useDefaultCredentialsProvider) throws Exception {
+        this.useDefaultCredentials = useDefaultCredentialsProvider;
+        return Response.ok().build();
+    }
+
+    @Path("/initializeDefaultCredentials")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response initializeDefaultCredentials(boolean initialize) throws Exception {
+        if (initialize) {
+            //set flag to clear at the end
+            clearAwsredentials = true;
+            LOG.debug(
+                    "Setting both System.properties `aws.secretAccessKey` and `aws.accessKeyId` to cover defaultCredentialsProviderTest.");
+            //defaultCredentials provider gets the credentials from fixed location. One of them is system.properties,
+            //therefore to succeed the test, system.properties has to be initialized with the values from the configuration
+            Aws2Helper.setAwsSystemCredentials(
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".access-key", String.class),
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".secret-key", String.class));
+
+        } else {
+            LOG.debug("Clearing both System.properties `aws.secretAccessKey` and `aws.accessKeyId`.");
+            Aws2Helper.clearAwsSystemCredentials();
+            clearAwsredentials = false;
+        }
+
+        return Response.ok().build();
+    }
+
+    /**
+     * Listeners ensures, that system credentials are cleared at the end of the lifecycle.
+     * Tests are clearing them by itself, this is just a precaution.
+     */

Review Comment:
   I can hook another safety clear attempt into close of  [Aws2TestResource.java](https://github.com/apache/camel-quarkus/blob/main/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2TestResource.java#L109). That could help, what do you think, @aldettinger ?



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094630049


##########
integration-tests-support/aws2/src/test/java/org/apache/camel/quarkus/test/support/aws2/BaseAWs2TestSupport.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import io.restassured.RestAssured;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Parent for aws test classes which should cover default credentials test case.
+ * Parent adds two test methods {@link #successfulDefaultCredentialsProviderTest()} and
+ * {@link #failingDefaultCredentialsProviderTest()}
+ *
+ * Test expects that test resource extends {@link BaseAws2Resource}.
+ *
+ */
+public abstract class BaseAWs2TestSupport {
+
+    //Rest path to connect to rest resource. Path differs for different aws2 extensions (like "/aws2-ddb" or "/aws2-s3"
+    private final String restPath;
+
+    public BaseAWs2TestSupport(String restPath) {
+        this.restPath = restPath;
+    }
+
+    /**
+     * Testing method used for {@link #successfulDefaultCredentialsProviderTest()} and
+     * {@link #failingDefaultCredentialsProviderTest()}.
+     *
+     * This method is called twice.
+     * 1 - Credentials are not set, therefore this method should fail.
+     * 2 - Credentials are set, there this method should succeed.
+     *
+     * Returns true if test passes, fa;se otherwise.
+     */
+    public abstract void testMethodForDefaultCredentialsProvider();
+
+    //test can be executed only if mock backend is used and no defaultCredentialsProvider is defined in the system
+    @ExtendWith(Aws2DefaultCredentialsProviderAvailabilityCondition.class)
+    @Test
+    public void successfulDefaultCredentialsProviderTest() {
+        try {
+            RestAssured.given()
+                    .body(true)
+                    .post(restPath + "/setUseDefaultCredentialsProvider")
+                    .then()
+                    .statusCode(200);
+
+            RestAssured.given()
+                    .body(true)
+                    .post(restPath + "/initializeDefaultCredentials")
+                    .then()
+                    .statusCode(200);
+
+            //should succeed
+            testMethodForDefaultCredentialsProvider();
+
+        } finally {
+            RestAssured.given()

Review Comment:
   @aldettinger  the test is trying to clear the system.properties in final block. (so it covers unexpected exception)



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] aldettinger commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094579690


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2Helper.java:
##########
@@ -0,0 +1,35 @@
+package org.apache.camel.quarkus.test.support.aws2;
+
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.core.exception.SdkClientException;
+
+public class Aws2Helper {
+
+    public static final String UNABLE_TO_LOAD_CREDENTIALS_MSG = "Unable to load credentials";
+
+    public static boolean isDefaultCredentialsProviderDefinedOnSystem() {
+        try {
+            DefaultCredentialsProvider.create().resolveCredentials();
+        } catch (Exception e) {
+            //if message starts with "Unable to load credentials", allow testing
+            if (e instanceof SdkClientException && e.getMessage() != null
+                    && e.getMessage().startsWith(UNABLE_TO_LOAD_CREDENTIALS_MSG)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static void setAwsSysteCredentials(String accessKey, String secretKey) {

Review Comment:
   small typo here ?



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] aldettinger commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094730293


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import javax.enterprise.event.Observes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.runtime.ShutdownEvent;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
+
+/**
+ * Parent for testing resources for aws2 extensions.
+ *
+ * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials

Review Comment:
   Oh, it was just to state another typo `varialbe`



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] aldettinger commented on pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#issuecomment-1413822769

   The comments in the pr and the code are very much welcome @JiriOndrusek :clap: It helps with review from my perspective.
   
   It looks good pr, only few nitpicks and 1 question.


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1095629400


##########
integration-tests-support/aws2/src/test/java/org/apache/camel/quarkus/test/support/aws2/BaseAWs2TestSupport.java:
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import io.restassured.RestAssured;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+/**
+ * Parent for aws test classes which should cover default credentials test case.
+ * Parent adds two test methods {@link #successfulDefaultCredentialsProviderTest()} and
+ * {@link #failingDefaultCredentialsProviderTest()}
+ *
+ * Test expects that test resource extends {@link BaseAws2Resource}.
+ *
+ */
+public abstract class BaseAWs2TestSupport {
+
+    //Rest path to connect to rest resource. Path differs for different aws2 extensions (like "/aws2-ddb" or "/aws2-s3"

Review Comment:
   fixed



##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import javax.enterprise.event.Observes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.runtime.ShutdownEvent;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
+
+/**
+ * Parent for testing resources for aws2 extensions.
+ *
+ * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials

Review Comment:
   fixed



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] JiriOndrusek commented on pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#issuecomment-1429378228

   sure, I'll do that, thanks.


-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094623218


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import javax.enterprise.event.Observes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.runtime.ShutdownEvent;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
+
+/**
+ * Parent for testing resources for aws2 extensions.
+ *
+ * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials
+ * to be used in inherited classes.
+ *
+ * Rest endpoints are expected by test classes.
+ */
+public class BaseAws2Resource {
+
+    private static final Logger LOG = Logger.getLogger(BaseAws2Resource.class);
+
+    protected boolean useDefaultCredentials;
+
+    private final String serviceName;
+
+    private boolean clearAwsredentials;
+
+    public BaseAws2Resource(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+    @Path("/setUseDefaultCredentialsProvider")
+    @POST
+    public Response setUseDefaultCredentials(boolean useDefaultCredentialsProvider) throws Exception {
+        this.useDefaultCredentials = useDefaultCredentialsProvider;
+        return Response.ok().build();
+    }
+
+    @Path("/initializeDefaultCredentials")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response initializeDefaultCredentials(boolean initialize) throws Exception {
+        if (initialize) {
+            //set flag to clear at the end
+            clearAwsredentials = true;
+            LOG.debug(
+                    "Setting both System.properties `aws.secretAccessKey` and `aws.accessKeyId` to cover defaultCredentialsProviderTest.");
+            //defaultCredentials provider gets the credentials from fixed location. One of them is system.properties,
+            //therefore to succeed the test, system.properties has to be initialized with the values from the configuration
+            Aws2Helper.setAwsSystemCredentials(
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".access-key", String.class),
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".secret-key", String.class));
+
+        } else {
+            LOG.debug("Clearing both System.properties `aws.secretAccessKey` and `aws.accessKeyId`.");
+            Aws2Helper.clearAwsSystemCredentials();
+            clearAwsredentials = false;
+        }
+
+        return Response.ok().build();
+    }
+
+    /**
+     * Listeners ensures, that system credentials are cleared at the end of the lifecycle.
+     * Tests are clearing them by itself, this is just a precaution.
+     */

Review Comment:
   I can hook another safety clear into [Aws2TestResource.java](https://github.com/apache/camel-quarkus/blob/main/integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2TestResource.java#L109). That could help, what do you think, @aldettinger ?



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094600117


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import javax.enterprise.event.Observes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.runtime.ShutdownEvent;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
+
+/**
+ * Parent for testing resources for aws2 extensions.
+ *
+ * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials
+ * to be used in inherited classes.
+ *
+ * Rest endpoints are expected by test classes.
+ */
+public class BaseAws2Resource {
+
+    private static final Logger LOG = Logger.getLogger(BaseAws2Resource.class);
+
+    protected boolean useDefaultCredentials;
+
+    private final String serviceName;
+
+    private boolean clearAwsredentials;
+
+    public BaseAws2Resource(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+    @Path("/setUseDefaultCredentialsProvider")
+    @POST
+    public Response setUseDefaultCredentials(boolean useDefaultCredentialsProvider) throws Exception {
+        this.useDefaultCredentials = useDefaultCredentialsProvider;
+        return Response.ok().build();
+    }
+
+    @Path("/initializeDefaultCredentials")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response initializeDefaultCredentials(boolean initialize) throws Exception {
+        if (initialize) {
+            //set flag to clear at the end
+            clearAwsredentials = true;
+            LOG.debug(
+                    "Setting both System.properties `aws.secretAccessKey` and `aws.accessKeyId` to cover defaultCredentialsProviderTest.");
+            //defaultCredentials provider gets the credentials from fixed location. One of them is system.properties,
+            //therefore to succeed the test, system.properties has to be initialized with the values from the configuration
+            Aws2Helper.setAwsSystemCredentials(
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".access-key", String.class),
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".secret-key", String.class));
+
+        } else {
+            LOG.debug("Clearing both System.properties `aws.secretAccessKey` and `aws.accessKeyId`.");
+            Aws2Helper.clearAwsSystemCredentials();
+            clearAwsredentials = false;
+        }
+
+        return Response.ok().build();
+    }
+
+    /**
+     * Listeners ensures, that system credentials are cleared at the end of the lifecycle.
+     * Tests are clearing them by itself, this is just a precaution.
+     */

Review Comment:
   I thought that this listener should be called also with unexpected shutdown. Therefore it should clear properties for all cases. Am I missing here something? (https://quarkus.io/guides/lifecycle#listening-for-startup-and-shutdown-events)



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094626742


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import javax.enterprise.event.Observes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.runtime.ShutdownEvent;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
+
+/**
+ * Parent for testing resources for aws2 extensions.
+ *
+ * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials

Review Comment:
   I kept it as protected, so the inherited classes can call it directly. I will  use getter (`is*`) and keep variable private and remove the word `protected` from the comment



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] aldettinger commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094740575


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/BaseAws2Resource.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.camel.quarkus.test.support.aws2;
+
+import javax.enterprise.event.Observes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+
+import io.quarkus.runtime.ShutdownEvent;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.jboss.logging.Logger;
+
+/**
+ * Parent for testing resources for aws2 extensions.
+ *
+ * This class adds endpoints to force default credentials to be used + provides protected varialbe useDefaultCredentials
+ * to be used in inherited classes.
+ *
+ * Rest endpoints are expected by test classes.
+ */
+public class BaseAws2Resource {
+
+    private static final Logger LOG = Logger.getLogger(BaseAws2Resource.class);
+
+    protected boolean useDefaultCredentials;
+
+    private final String serviceName;
+
+    private boolean clearAwsredentials;
+
+    public BaseAws2Resource(String serviceName) {
+        this.serviceName = serviceName;
+    }
+
+    @Path("/setUseDefaultCredentialsProvider")
+    @POST
+    public Response setUseDefaultCredentials(boolean useDefaultCredentialsProvider) throws Exception {
+        this.useDefaultCredentials = useDefaultCredentialsProvider;
+        return Response.ok().build();
+    }
+
+    @Path("/initializeDefaultCredentials")
+    @POST
+    @Produces(MediaType.TEXT_PLAIN)
+    public Response initializeDefaultCredentials(boolean initialize) throws Exception {
+        if (initialize) {
+            //set flag to clear at the end
+            clearAwsredentials = true;
+            LOG.debug(
+                    "Setting both System.properties `aws.secretAccessKey` and `aws.accessKeyId` to cover defaultCredentialsProviderTest.");
+            //defaultCredentials provider gets the credentials from fixed location. One of them is system.properties,
+            //therefore to succeed the test, system.properties has to be initialized with the values from the configuration
+            Aws2Helper.setAwsSystemCredentials(
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".access-key", String.class),
+                    ConfigProvider.getConfig().getValue("camel.component.aws2-" + serviceName + ".secret-key", String.class));
+
+        } else {
+            LOG.debug("Clearing both System.properties `aws.secretAccessKey` and `aws.accessKeyId`.");
+            Aws2Helper.clearAwsSystemCredentials();
+            clearAwsredentials = false;
+        }
+
+        return Response.ok().build();
+    }
+
+    /**
+     * Listeners ensures, that system credentials are cleared at the end of the lifecycle.
+     * Tests are clearing them by itself, this is just a precaution.
+     */

Review Comment:
   Ok, it was solved in a comment below. There is a finally block in the test that would restore the properties.



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] JiriOndrusek commented on a diff in pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "JiriOndrusek (via GitHub)" <gi...@apache.org>.
JiriOndrusek commented on code in PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#discussion_r1094593219


##########
integration-tests-support/aws2/src/main/java/org/apache/camel/quarkus/test/support/aws2/Aws2Helper.java:
##########
@@ -0,0 +1,35 @@
+package org.apache.camel.quarkus.test.support.aws2;
+
+import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
+import software.amazon.awssdk.core.exception.SdkClientException;
+
+public class Aws2Helper {
+
+    public static final String UNABLE_TO_LOAD_CREDENTIALS_MSG = "Unable to load credentials";
+
+    public static boolean isDefaultCredentialsProviderDefinedOnSystem() {
+        try {
+            DefaultCredentialsProvider.create().resolveCredentials();
+        } catch (Exception e) {
+            //if message starts with "Unable to load credentials", allow testing
+            if (e instanceof SdkClientException && e.getMessage() != null
+                    && e.getMessage().startsWith(UNABLE_TO_LOAD_CREDENTIALS_MSG)) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    public static void setAwsSysteCredentials(String accessKey, String secretKey) {
+        System.setProperty("aws.accessKeyId", accessKey);
+        System.setProperty("aws.secretAccessKey", secretKey);
+
+    }
+
+    public static void clearAwsSysteCredentials() {

Review Comment:
   fixed



-- 
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: commits-unsubscribe@camel.apache.org

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


[GitHub] [camel-quarkus] aldettinger commented on pull request #4474: Aws2: Add testing of defaultCredentialProvider to each extension #4442

Posted by "aldettinger (via GitHub)" <gi...@apache.org>.
aldettinger commented on PR #4474:
URL: https://github.com/apache/camel-quarkus/pull/4474#issuecomment-1430187503

   I would say this one can be merged ?


-- 
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: commits-unsubscribe@camel.apache.org

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