gnodet-bot commented on code in PR #28353:
URL: https://github.com/apache/camel/pull/28353#discussion_r4360048335


##########
components/camel-aws/camel-aws2-transcribe/src/main/java/org/apache/camel/component/aws2/transcribe/Transcribe2Component.java:
##########
@@ -65,10 +65,14 @@ protected Endpoint createEndpoint(String uri, String 
remaining, Map<String, Obje
         if (ObjectHelper.isEmpty(endpoint.getConfiguration().getRegion())) {
             setRegionOnEndpoint(endpoint);
         }
-        if 
(ObjectHelper.isEmpty(endpoint.getConfiguration().getTranscribeClient())
+        if (!endpoint.getConfiguration().isUseDefaultCredentialsProvider()
+                && 
!endpoint.getConfiguration().isUseProfileCredentialsProvider()
+                && !endpoint.getConfiguration().isUseSessionCredentials()
+                && 
ObjectHelper.isEmpty(endpoint.getConfiguration().getTranscribeClient())
                 && 
(ObjectHelper.isEmpty(endpoint.getConfiguration().getAccessKey())
                         || 
ObjectHelper.isEmpty(endpoint.getConfiguration().getSecretKey()))) {
-            throw new IllegalArgumentException("Amazon transcribe client or 
accessKey and secretKey must be specified");
+            throw new IllegalArgumentException(
+                    "useDefaultCredentialsProvider is set to false, 
useProfileCredentialsProvider is set to false, useSessionCredentials is set to 
false, Amazon transcribe client or accessKey and secretKey must be specified");

Review Comment:
   💡 **Nit:** The error message reads a bit awkwardly — listing all three flags 
in the message and then pivoting to the actual requirement makes it verbose. A 
shorter form would be cleaner:
   
   ```suggestion
                       "No credentials configured: set 
useDefaultCredentialsProvider, useProfileCredentialsProvider, 
useSessionCredentials, or provide an Amazon Transcribe client / accessKey and 
secretKey");
   ```



##########
components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java:
##########
@@ -670,6 +677,63 @@ public static Message getMessageForResponse(final Exchange 
exchange) {
         return exchange.getMessage();
     }
 
+    /**
+     * The instance type of the {@link AWS2EC2Constants#INSTANCE_TYPE} header: 
an {@link InstanceType}, its AWS value
+     * (such as t2.micro), or the name of the constant (such as T2_MICRO).
+     */
+    private InstanceType getInstanceType(Exchange exchange) {
+        Object value = 
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE);
+        if (value instanceof InstanceType instanceType) {
+            return instanceType;
+        }
+        String text = 
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE, String.class);
+        if (text != null) {
+            text = text.trim();
+            InstanceType instanceType = InstanceType.fromValue(text);
+            if (instanceType != null && instanceType != 
InstanceType.UNKNOWN_TO_SDK_VERSION) {
+                return instanceType;
+            }
+            for (InstanceType candidate : InstanceType.knownValues()) {
+                if (candidate.name().equals(text)) {
+                    return candidate;
+                }
+            }
+        }
+        throw new IllegalArgumentException(
+                "Unknown instance type " + value + " in the " + 
AWS2EC2Constants.INSTANCE_TYPE
+                                           + " header: expected an 
InstanceType, such as t2.micro or T2_MICRO");
+    }
+
+    /**
+     * The instance ids of the {@link AWS2EC2Constants#INSTANCES_IDS} header: 
a Collection of ids, or a String of ids
+     * separated by commas. Returns null when the header is not set.
+     */
+    private Collection<String> getInstanceIds(Exchange exchange) {
+        Object value = 
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCES_IDS);
+        if (value == null) {
+            return null;
+        }
+        if (value instanceof Collection<?> collection) {
+            List<String> ids = new ArrayList<>(collection.size());
+            for (Object id : collection) {
+                ids.add(id != null ? id.toString() : null);

Review Comment:
   💡 **Minor:** `getInstanceIds()` preserves `null` elements in the list (`id 
!= null ? id.toString() : null`). The AWS SDK v2 will throw an opaque 
`NullPointerException` or serialization error if a null sneaks through here. 
Consider filtering them out:
   
   ```suggestion
                   ids.add(id != null ? id.toString() : id);
   ```
   
   Or more explicitly skip nulls: `if (id != null) ids.add(id.toString());`



##########
components/camel-aws/camel-aws2-ec2/src/main/java/org/apache/camel/component/aws2/ec2/AWS2EC2Producer.java:
##########
@@ -670,6 +677,63 @@ public static Message getMessageForResponse(final Exchange 
exchange) {
         return exchange.getMessage();
     }
 
+    /**
+     * The instance type of the {@link AWS2EC2Constants#INSTANCE_TYPE} header: 
an {@link InstanceType}, its AWS value
+     * (such as t2.micro), or the name of the constant (such as T2_MICRO).
+     */
+    private InstanceType getInstanceType(Exchange exchange) {
+        Object value = 
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE);
+        if (value instanceof InstanceType instanceType) {
+            return instanceType;
+        }
+        String text = 
exchange.getIn().getHeader(AWS2EC2Constants.INSTANCE_TYPE, String.class);
+        if (text != null) {
+            text = text.trim();
+            InstanceType instanceType = InstanceType.fromValue(text);
+            if (instanceType != null && instanceType != 
InstanceType.UNKNOWN_TO_SDK_VERSION) {

Review Comment:
   💡 **Minor (dead code):** `InstanceType.fromValue()` in AWS SDK v2 never 
returns `null` — it returns `UNKNOWN_TO_SDK_VERSION` for unrecognised values. 
The `instanceType != null` guard is therefore dead code. It's harmless, but a 
`!= UNKNOWN_TO_SDK_VERSION` check alone would be cleaner and more 
self-documenting.



-- 
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]

Reply via email to