saravanakumar1987 opened a new pull request, #30139:
URL: https://github.com/apache/camel/pull/30139

   # Description
   
   Part of [CAMEL-23832](https://issues.apache.org/jira/browse/CAMEL-23832). 
This pull request covers `camel-alibaba-kms` (scheme `alibaba-kms`). It does 
not complete the ticket, so please keep the ticket open.
   
   This is the third of the eight Alibaba components, after `camel-alibaba-ots` 
(#29991) and `camel-alibaba-fc` (#30004). The texts of `operation`, `region`, 
`endpoint`, `accessKey`, `secretKey`, `serviceKeys` and `kmsClient` are the 
texts merged there, with the kms names (`region`, `endpoint` and `kmsClient` as 
in fc). The sentences on the header and the exchange property that replace an 
option, and the request ID text, are those of the ots and fc texts too.
   
   Only description texts change: 12 endpoint options and 6 headers. No option 
or header is added, removed or renamed, and no default value, label, type or 
enum value changes. The component description stays as it is. The row of 
`camel-alibaba-kms` in `tasks/component-descriptions.md` is marked done.
   
   The new texts are in the `description` attribute of the annotations 
(`@UriPath` and `@UriParam` on the endpoint options, `@Metadata` on the header 
constants). The old texts were already in that attribute and no setter had 
Javadoc, so no Javadoc is removed.
   
   The names were checked against the sources of the KMS SDK for Java 2.3.2 
(`com.aliyun:kms20160120`), the version set by `aliyun-kms-version` in 
`parent/pom.xml`, which calls the KMS API version 2016-01-20. Its client 
extends the client of `com.aliyun:tea-openapi` 0.3.20 (`tea-openapi-version`) 
and runs on `com.aliyun:tea` 1.4.3 (`tea-version`), whose sources were read 
too, and on `com.aliyun:tea-util` 0.2.28 (`tea-util-version`). The runs named 
in the table used only 127.0.0.1: a local HTTP server, with a client set to the 
protocol HTTP where a route needed a response. No request was sent to Alibaba 
Cloud and no page of the Alibaba Cloud documentation was read, so the terms 
come from the SDK Javadoc (KMS key, data key, key ID, alias, ARN) and from the 
names the component already uses (ciphertext blob, key spec, number of bytes).
   
   | Text | Problem in the current text | Checked against |
   |---|---|---|
   | `operation` (endpoint path option) | It does not say that the 
CamelAlibabaKmsOperation header, and after it an exchange property of the same 
name, replace the option. | `KMSComponent.createEndpoint` and the `KMSEndpoint` 
constructor (the path of the endpoint URI), `KMSProducer.process`, 
`KMSUtils.createClientConfigurations`, camel-alibaba-common 
`OpenApiClientSupport.resolveString` (the header, else the exchange property of 
the same name, else the option), `KMSProperties` (the name 
CamelAlibabaKmsOperation); a run in which the header with the value encrypt 
made the producer of an `alibaba-kms:decrypt` endpoint send an Encrypt request; 
the ots and fc text word for word, with the kms header name; the tests use only 
the path value encrypt |
   | `region` (endpoint option) | It does not say that the value is a region 
ID, that it only builds the endpoint when the endpoint option is not set, nor 
that it is not used when kmsClient is set or autowired. | 
`KMSUtils.createClient` and `createTeaConfig` (region or endpoint is required, 
and the region goes into the SDK configuration only when it is not empty; no 
other Camel code reads the option), `KMSEndpoint.initClient`, 
`DefaultEndpoint.doInit` with the generated `KMSEndpointConfigurer` (a single 
`Client` in the registry is autowired into kmsClient); KMS SDK `Client` (a set 
endpoint is used as it is, else `com.aliyun:endpoint-util` 0.0.8 builds 
kms.{region}.aliyuncs.com, as a run without sending showed for cn-hangzhou and 
ap-southeast-1); tea-openapi `Client` (the region ID is read only by `execute`, 
which the kms operations do not use, because Camel sets no signature version or 
algorithm; with the endpoint option set, a run sent the same request for two 
regions, apart from th
 e date, the nonce and the signature); the region on the doc page and in 
`testconfiguration.properties` (cn-hangzhou), and the region id of the 
tea-openapi `Config` Javadoc; the fc text with KMS and kmsClient; no test reads 
the option |
   | `endpoint` (endpoint option) | It calls the value a URL, although the SDK 
takes a host name and every request fails when the value has http:// or 
https://, and "Carries higher precedence than region based client 
initialization" does not say what happens. | `KMSUtils.createClient` and 
`createTeaConfig` (one of region and endpoint is required, Camel checks nothing 
else); KMS SDK `Client.getEndpoint` (a set endpoint is used as it is); 
tea-openapi `Client` (the endpoint is the host of each request, and the 
protocol is the HTTPS of the operation, because Camel sets no protocol); tea 
`Tea` (the URL is the protocol, ://, the host and the path); a run in which the 
client that the Camel endpoint creates started a TLS handshake with a local 
plain HTTP server; runs with the endpoint https://127.0.0.1:8443, stopped 
before sending, in which the URL that the SDK built did not have the host 
127.0.0.1; the tea-openapi `Config` Javadoc (the example endpoint 
cs.aliyuncs.com, without a scheme); th
 e fc text with KMS and kmsClient; no test reads the option |
   | `accessKey` (endpoint option) | It does not use the Alibaba Cloud term 
AccessKey ID, and it does not say how the option relates to serviceKeys and 
kmsClient. | `KMSUtils.createTeaConfig`, camel-alibaba-common 
`OpenApiClientSupport.resolveAccessKey` (the option, else the accessKey of 
serviceKeys, else an IllegalArgumentException), `KMSEndpoint.initClient` (a set 
or autowired client is returned before any key is read), 
`DefaultEndpoint.doInit`; tea-openapi `Client` (a credential from accessKeyId 
and accessKeySecret, and the ACS3-HMAC-SHA256 Authorization header, which 
carries the AccessKey ID, as a run showed, and is signed with the AccessKey 
secret); the ots and fc text word for word, with KMS and kmsClient |
   | `secretKey` (endpoint option) | It does not use the Alibaba Cloud term 
AccessKey secret, and it does not say how the option relates to serviceKeys and 
kmsClient. | `KMSUtils.createTeaConfig`, 
`OpenApiClientSupport.resolveSecretKey` (as `accessKey`), 
`KMSEndpoint.initClient`, `DefaultEndpoint.doInit`; tea-openapi `Client` (the 
AccessKey secret signs the request); the ots and fc text word for word, with 
KMS and kmsClient |
   | `serviceKeys` (endpoint option) | It does not say what the object holds, 
nor when its values are used. | camel-alibaba-common `ServiceKeys` (the 
properties accessKey and secretKey), `OpenApiClientSupport.resolveAccessKey` 
and `resolveSecretKey` (each key falls back to serviceKeys on its own), 
`KMSUtils.createClient`, `KMSEndpoint.initClient`, `DefaultEndpoint.doInit`; 
the ots and fc text word for word, with kmsClient |
   | `keyId` (endpoint option) | It does not say that an alias or an ARN works 
too, which operations use the key, that a header and an exchange property 
replace the option, nor that one of the three is required. | 
`KMSUtils.createClientConfigurations` and `OpenApiClientSupport.resolveString` 
(as `operation`), `KMSProducer` (encrypt and generateDataKey fail without a key 
ID, and decrypt does not read it); KMS SDK `EncryptRequest` and 
`GenerateDataKeyRequest` (the ID of the key, or its alias or ARN, sent as it 
is), and `DecryptRequest`, which has no key ID; a run in which the header won 
over the exchange property and the option, and an empty header fell through to 
the exchange property; the alias alias/my-key in the examples of the doc page; 
`EncryptPlaintextTest` checks the key ID of each request for the option, and no 
test sets the header or the exchange property |
   | `plaintext` (endpoint option) | It does not say that the producer encodes 
the text in UTF-8 and sends it in Base64, that a header and an exchange 
property replace the option, nor that the producer takes the plaintext from the 
message body when none of the three is set. | 
`KMSUtils.createClientConfigurations` and `OpenApiClientSupport.resolveString` 
(as `operation`), `KMSUtils.encodePlaintextForEncrypt` (a value from the three 
becomes its UTF-8 bytes in Base64, else the message body is sent in Base64), 
`KMSProducer.encrypt` (only encrypt reads it, and an empty result fails); KMS 
SDK `EncryptRequest` (the plaintext must be Base64-encoded, and the SDK sends 
it as it is); a run in which the body hello was sent as aGVsbG8=, and the 
header, the exchange property or the option was sent in Base64 in place of the 
body; `EncryptTest` and `EncryptPlaintextTest` cover the body, and no test sets 
the option, the header or the exchange property |
   | `ciphertextBlob` (endpoint option) | It does not say where the ciphertext 
blob comes from, that a header and an exchange property replace the option, nor 
that the producer takes the ciphertext blob from the message body when none of 
the three is set. | `KMSUtils.createClientConfigurations` and 
`OpenApiClientSupport.resolveString` (as `operation`), `KMSProducer.decrypt` 
(the value from the three, else the body as a String, else an 
IllegalArgumentException; only decrypt reads it); KMS SDK `DecryptRequest` (the 
ciphertext, which Encrypt and GenerateDataKey can generate) and the responses 
of encrypt and generateDataKey, whose ciphertext blob `KMSUtils` puts unchanged 
into the result Map; a run in which the body was sent, the header won over the 
body, and no body failed the exchange before any request; the term ciphertext 
blob of the display name, the body type text, the doc page and the error 
message of the component; no test calls decrypt |
   | `keySpec` (endpoint option) | It does not give the values, nor say how it 
relates to the number of bytes, that a header and an exchange property replace 
the option, or what happens when it is not set. | 
`KMSUtils.createClientConfigurations` and `OpenApiClientSupport.resolveString` 
(as `operation`), `KMSProducer.generateDataKey` (the KeySpec of the request 
only when the value is not empty, and both values when both resolve; only 
generateDataKey reads it); KMS SDK `GenerateDataKeyRequest` (the valid values 
AES_256 and AES_128, and that KMS ignores KeySpec when both parameters are 
specified, so the sentence "KMS does not use it when the number of bytes is set 
as well." rests on this Javadoc, as no request was sent to KMS); a run in which 
the request had neither KeySpec nor NumberOfBytes without the options, and both 
with both options; no test calls generateDataKey |
   | `numberOfBytes` (endpoint option) | It does not give the range, nor say 
that a header and an exchange property replace the option, nor what happens 
when it is not set. | `KMSUtils.createClientConfigurations` and 
`OpenApiClientSupport.resolveInteger` (the header as an Integer, else the 
exchange property, else the option), `KMSProducer.generateDataKey` (the 
NumberOfBytes of the request only when the value is not null; only 
generateDataKey reads it); KMS SDK `GenerateDataKeyRequest` (valid values 1 to 
1024, which the SDK does not check); a run in which the header with the String 
24 was sent as 24 and won over the option 16; no test calls generateDataKey |
   | `kmsClient` (endpoint option) | It does not say what the option replaces, 
nor who creates the client and when. | `KMSEndpoint` (`initClient`, 
`setKmsClient` and its flag, `doStop`, which drops the reference to a client 
that the Camel endpoint created and closes nothing), `KMSProducer.process` (it 
calls `initClient` while its own reference is null, so for the first message), 
the generated `KMSEndpointConfigurer` (`getAutowiredNames`), 
`DefaultEndpoint.doInit` (autowiring: in a run with one `Client` bean in the 
registry and no client, region, endpoint or keys in the URI, the Camel endpoint 
used that bean); KMS SDK `Client`, which extends the tea-openapi `Client` 
(neither has a method to close or shut down the client, so the sentences of the 
otsClient text about shutting down are left out); the fc text word for word, 
with the kms class; `EncryptTest` and `EncryptPlaintextTest` set kmsClient with 
a mock, and no test covers creating the client, autowiring or `doStop` |
   | `CamelAlibabaKmsKeyId` (header) | It says override without saying what is 
overridden. | as `keyId`: `KMSUtils.createClientConfigurations`, 
`OpenApiClientSupport.resolveString`, and the run with the header, the exchange 
property and the option; no test sets the header |
   | `CamelAlibabaKmsPlaintext` (header) | It does not say that the header 
replaces the plaintext option, nor what the producer does with the text. | as 
`plaintext`: `KMSUtils.createClientConfigurations` and 
`encodePlaintextForEncrypt`; in the run, the header p was sent as cA==, the 
Base64 of p, and the body was not used; no test sets the header |
   | `CamelAlibabaKmsCiphertextBlob` (header) | It does not say that the header 
replaces the ciphertextBlob option, nor where the ciphertext blob comes from. | 
as `ciphertextBlob`: `KMSUtils.createClientConfigurations` and 
`KMSProducer.decrypt`; in the run, the header won over the body; no test sets 
the header |
   | `CamelAlibabaKmsKeySpec` (header) | It does not say that the header 
replaces the keySpec option, nor give the values. | as `keySpec`: 
`KMSUtils.createClientConfigurations`, `KMSProducer.generateDataKey`, and the 
KMS SDK `GenerateDataKeyRequest` Javadoc for the values and for the sentence on 
the number of bytes; no test sets the header |
   | `CamelAlibabaKmsNumberOfBytes` (header) | It does not say that the header 
replaces the numberOfBytes option, nor give the range. | as `numberOfBytes`: 
`KMSUtils.createClientConfigurations`, `OpenApiClientSupport.resolveInteger`, 
`KMSProducer.generateDataKey`; in the run, the header with the String 24 won 
over the option 16; no test sets the header |
   | `CamelAlibabaKmsRequestId` (header) | It does not say who sets the header, 
nor when. | `KMSProducer.setRequestId`, called by the three operations after 
the call returns (the RequestId of the response body, when it is not empty); 
KMS SDK `EncryptResponseBody`, `DecryptResponseBody` and 
`GenerateDataKeyResponseBody` (the ID of the request); tea-openapi `Client` 
(for a status code from 400 to 599 the SDK throws unless returnErrorResponse is 
set, which Camel does not do, and the three operations do not retry); runs in 
which 400, 500 and 429 responses failed the exchange after one request without 
setting the header, while a client set with returnErrorResponse returned the 
400 response and the header was set, which is why the text says "unless the 
exchange fails" and not "when the operation succeeds"; the ots text with KMS 
and the condition of the fc texts; `EncryptTest` checks the header after 
encrypt |
   
   ## Found in the review, not changed here
   
   - `region` has `@Metadata(required = true)`, but the code needs `region` or 
`endpoint`, and neither when `kmsClient` is set or autowired: a run with one 
`Client` bean in the registry and none of the three in the URI worked. Catalog 
validation would therefore report `region` as missing for a URI that sets only 
`endpoint` or only `kmsClient`. Not verified: catalog validation was not run, 
so that part rests on the required flag.
   - `KMSHeaders` has no constant for `CamelAlibabaKmsOperation`, which the 
producer reads like the other input headers, as a run showed. Only 
`KMSProperties` declares it, so the header is missing from the header list of 
the component JSON, the endpoint DSL and the doc page, and only the `operation` 
text names it.
   - `KMSProperties` has `@Metadata` with texts of its own on its seven header 
names, but the build reads only the headers class `KMSHeaders` and its 
supertypes, so these texts are not used, and the six that `KMSHeaders` also 
declares now differ from its texts. The generated JSON shows this, as it has no 
entry for the `OPERATION` constant of `KMSProperties`. Not verified: whether a 
tool outside the Camel build reads these annotations.
   - `KMSEndpoint.initClient` and the producer's check of its own client field 
are not synchronized, as in `camel-alibaba-ots` before CAMEL-26971 and in 
`camel-alibaba-mns` and `camel-alibaba-oss` before CAMEL-27003. Creating a KMS 
client starts no thread and opens no connection, as the SDK sources show. Not 
investigated further for this pull request.
   - The client is created when the producer processes its first message, not 
when the route starts. An empty `region` and `endpoint`, or a missing AccessKey 
pair, shows up only then, and an unknown operation, a missing key ID or a 
missing plaintext or ciphertext blob fails only after the client exists. Not 
verified by a run: this rests on reading the producer code.
   - An empty or non-numeric String in the `CamelAlibabaKmsNumberOfBytes` 
header or exchange property fails every exchange with a 
`TypeConversionException`, for encrypt and decrypt too, before any request and 
without falling back to the option: `OpenApiClientSupport.resolveInteger` lets 
only null through, and the producer resolves all six names for each exchange. A 
run showed this with the empty String and with abc.
   - `keySpec` has no enums, although the SDK Javadoc lists the two values 
AES_256 and AES_128. Adding them is a metadata change.
   - The body type texts, added by CAMEL-24961 and CAMEL-26258, name the 
plaintext and ciphertextBlob option or header but not the exchange property. 
The producerOut text says "the fields of the response", but the Map leaves out 
CiphertextForRecipient, DataKeyName, DataKeyVersionId and DataKeyVersionName, 
and the text does not name the keys keyVersionId and requestId. The two texts 
also write "the body" and "request id", where the option and header texts write 
"the message body" and "request ID". This pull request changes only option and 
header texts, so these texts stay as they are.
   - A Map or a POJO in the `CamelAlibabaKmsPlaintext` header or exchange 
property is encrypted as its toString(), because 
`OpenApiClientSupport.resolveString` reads it as a String. The same value as 
the body fails with an InvalidPayloadException since CAMEL-26258, which the 
4.24 upgrade guide describes as the end of encrypting a toString(). Not 
verified against KMS: this was found with the module's classes and a stub 
client, without sending a request.
   
   # Target
   
   - [x] I checked that the commit is targeting the correct branch (Camel 4 
uses the `main` branch)
   
   # Tracking
   
   - [x] If this is a large change, bug fix, or code improvement, I checked 
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for 
the change (usually before you start working on it).
   
   # Apache Camel coding standards and style
   
   - [x] I checked that each commit in the pull request has a meaningful 
subject line and body.
   - [x] I have run `mvn clean install -Dquickly -DskipTests` from the root 
folder on commit 27efa340d2df and then `mvn install -DskipTests -nsu` in 
`components/camel-alibaba/camel-alibaba-kms`, `catalog/camel-catalog` and 
`dsl/camel-endpointdsl`, and I have committed all auto-generated changes.
   
   # AI-assisted contributions
   
   - [x] If this PR includes AI-generated code, commits have proper 
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR 
description identifies the AI tool used.
   
   The descriptions and this text were drafted with Claude (Anthropic) and 
checked against the Camel source and the KMS SDK for Java 2.3.2 sources.
   
   _Claude Code on behalf of saravanakumar1987_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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