This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new e54cb477269b CAMEL-26524: camel-google-secret-manager - createSecret
fails before creating the secret when the value is empty (#30057)
e54cb477269b is described below
commit e54cb477269b77fc2a60dc3bbfb83ec4b79158b2
Author: Pratik <[email protected]>
AuthorDate: Sun Nov 15 10:05:14 2026 -0800
CAMEL-26524: camel-google-secret-manager - createSecret fails before
creating the secret when the value is empty (#30057)
---
.../docs/google-secret-manager-component.adoc | 4 +--
.../main/docs/google-secret-manager-component.adoc | 4 +--
.../manager/GoogleSecretManagerProducer.java | 12 ++++++++-
.../unit/GoogleSecretManagerCreateSecretTest.java | 29 ++++++++++++++++++++++
4 files changed, 44 insertions(+), 5 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/google-secret-manager-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/google-secret-manager-component.adoc
index 3aeb28f81ca2..9c83ef3e534f 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/google-secret-manager-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/google-secret-manager-component.adoc
@@ -643,8 +643,8 @@ YAML::
====
The message body is the value of the secret, as text: bytes, a stream or a
file are read as text. This operation returns
-the `SecretVersion` it added. A message without a body fails with an
`InvalidPayloadException` before the secret is
-created.
+the `SecretVersion` it added. A message without a body, or with an empty
value, fails with an
+`InvalidPayloadException` before the secret is created.
With `pojoRequest=true`, the body is the request of the Google SDK instead: a
`CreateSecretRequest` creates the secret,
without a version, and returns the `Secret`, and an `AddSecretVersionRequest`
adds a version to a secret that exists,
diff --git
a/components/camel-google/camel-google-secret-manager/src/main/docs/google-secret-manager-component.adoc
b/components/camel-google/camel-google-secret-manager/src/main/docs/google-secret-manager-component.adoc
index 3aeb28f81ca2..9c83ef3e534f 100644
---
a/components/camel-google/camel-google-secret-manager/src/main/docs/google-secret-manager-component.adoc
+++
b/components/camel-google/camel-google-secret-manager/src/main/docs/google-secret-manager-component.adoc
@@ -643,8 +643,8 @@ YAML::
====
The message body is the value of the secret, as text: bytes, a stream or a
file are read as text. This operation returns
-the `SecretVersion` it added. A message without a body fails with an
`InvalidPayloadException` before the secret is
-created.
+the `SecretVersion` it added. A message without a body, or with an empty
value, fails with an
+`InvalidPayloadException` before the secret is created.
With `pojoRequest=true`, the body is the request of the Google SDK instead: a
`CreateSecretRequest` creates the secret,
without a version, and returns the `Secret`, and an `AddSecretVersionRequest`
adds a version to a secret that exists,
diff --git
a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerProducer.java
b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerProducer.java
index c1dcd9260174..75e112778b50 100644
---
a/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerProducer.java
+++
b/components/camel-google/camel-google-secret-manager/src/main/java/org/apache/camel/component/google/secret/manager/GoogleSecretManagerProducer.java
@@ -44,6 +44,9 @@ public class GoogleSecretManagerProducer extends
DefaultProducer {
= "createSecret with pojoRequest=true takes a CreateSecretRequest,
to create the secret, or an"
+ " AddSecretVersionRequest, to add a version to a secret that
exists";
+ private static final String CREATE_SECRET_EMPTY_VALUE_HINT
+ = "createSecret takes the value of the secret as the message body,
and the value must not be empty";
+
private GoogleSecretManagerEndpoint endpoint;
public GoogleSecretManagerProducer(GoogleSecretManagerEndpoint endpoint) {
@@ -89,8 +92,15 @@ public class GoogleSecretManagerProducer extends
DefaultProducer {
String secretId =
exchange.getMessage().getHeader(GoogleSecretManagerConstants.SECRET_ID,
String.class);
// read the value first: a message without a body then fails
before the secret is created, instead of
// leaving a secret without a version behind
+ String secretValue =
exchange.getMessage().getMandatoryBody(String.class);
+ // Secret Manager rejects an empty payload, so an empty value
would create the secret and then fail
+ // to add the version, again leaving a secret without a version
behind: fail before creating it
+ if (secretValue.isEmpty()) {
+ throw new InvalidPayloadException(
+ exchange, String.class, exchange.getMessage(),
CREATE_SECRET_EMPTY_VALUE_HINT);
+ }
SecretPayload payload = SecretPayload.newBuilder()
-
.setData(ByteString.copyFromUtf8(exchange.getMessage().getMandatoryBody(String.class))).build();
+ .setData(ByteString.copyFromUtf8(secretValue)).build();
Secret secret = Secret.newBuilder()
.setReplication(
Replication.newBuilder()
diff --git
a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/unit/GoogleSecretManagerCreateSecretTest.java
b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/unit/GoogleSecretManagerCreateSecretTest.java
index bf936a80587f..24560d886348 100644
---
a/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/unit/GoogleSecretManagerCreateSecretTest.java
+++
b/components/camel-google/camel-google-secret-manager/src/test/java/org/apache/camel/component/google/secret/manager/unit/GoogleSecretManagerCreateSecretTest.java
@@ -89,6 +89,35 @@ class GoogleSecretManagerCreateSecretTest extends
CamelTestSupport {
assertEquals(String.class, cause.getType());
}
+ @Test
+ void createSecretWithAnEmptyValueFailsBeforeTheSecretIsCreated() {
+ Exchange exchange = template.request(CREATE_SECRET, e -> {
+ e.getIn().setHeader(GoogleSecretManagerConstants.SECRET_ID,
"test");
+ e.getIn().setBody("");
+ });
+
+ // no secret is left behind without a version
+ verify(client, never()).createSecret(any(ProjectName.class), any(),
any(Secret.class));
+ verify(client, never()).addSecretVersion((String) any(),
any(SecretPayload.class));
+ InvalidPayloadException cause =
assertInstanceOf(InvalidPayloadException.class, exchange.getException());
+ assertEquals(String.class, cause.getType());
+ assertTrue(cause.getMessage().contains("must not be empty"),
cause.getMessage());
+ }
+
+ @Test
+ void createSecretWithAnEmptyStreamFailsBeforeTheSecretIsCreated() {
+ Exchange exchange = template.request(CREATE_SECRET, e -> {
+ e.getIn().setHeader(GoogleSecretManagerConstants.SECRET_ID,
"test");
+ e.getIn().setBody(new ByteArrayInputStream(new byte[0]));
+ });
+
+ // no secret is left behind without a version
+ verify(client, never()).createSecret(any(ProjectName.class), any(),
any(Secret.class));
+ verify(client, never()).addSecretVersion((String) any(),
any(SecretPayload.class));
+ InvalidPayloadException cause =
assertInstanceOf(InvalidPayloadException.class, exchange.getException());
+ assertEquals(String.class, cause.getType());
+ }
+
@Test
void createSecretCreatesTheSecretAndAddsTheValueAsAVersion() {
Exchange exchange = template.request(CREATE_SECRET, e -> {