Skip to content

Commit 0604341

Browse files
t-bonksjvans
andauthored
feat: support-cross-subaccount-consumption (#122)
Co-authored-by: sjvans <[email protected]>
1 parent 62c0a86 commit 0604341

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ Please see [Validation of VMR Provisioning](https://help.sap.com/docs/sap-integr
101101

102102
Additional configuration options for the messaging service are:
103103

104-
Property | Type | Description |
105-
| --- | --- | --- |
104+
Property | Type | Description |
105+
|---------------------------------------------------------------------|-----------|-------------------------------------------------------------------------------------------------------------------------------------------------------|
106106
| `cds.messaging.services.<key>.connection.properties.skipManagement` | `boolean` | If set to `true`, the plugin will not create a queue or subscription. This is useful if you want to manage these resources manually, default: `false` |
107+
| `cds.messaging.services.<key>.connection.properties.subaccountId` | `String` | If set to a subaccount ID, the plugin will call the validation service with that given value, default: `null` |
107108

108109

109110
## Support, Feedback, Contributing

cds-feature-advanced-event-mesh/src/main/java/com/sap/cds/feature/messaging/aem/client/AemValidationClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.sap.cds.feature.messaging.aem.client;
22

3+
import com.google.common.base.Strings;
34
import com.sap.cloud.environment.servicebinding.api.ServiceBinding;
45
import com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions;
56
import java.io.IOException;
67
import java.net.URI;
78
import java.net.URISyntaxException;
9+
import java.util.HashMap;
810
import java.util.Map;
911

1012
public class AemValidationClient extends RestClient {
@@ -13,9 +15,15 @@ public AemValidationClient(ServiceBinding binding) {
1315
super(ServiceBindingDestinationOptions.forService(binding).build());
1416
}
1517

16-
public void validate(String managementUri) throws IOException, URISyntaxException {
18+
public void validate(String managementUri, String subaccountId) throws IOException, URISyntaxException {
1719
URI uri = new URI(managementUri);
18-
String payload = this.mapper.writeValueAsString(Map.of("hostName", uri.getHost()));
20+
Map<String, String> payloadMap = new HashMap<>(Map.of("hostName", uri.getHost()));
21+
22+
if (!Strings.isNullOrEmpty(subaccountId)) {
23+
payloadMap.put("subaccountId", subaccountId);
24+
}
25+
26+
String payload = this.mapper.writeValueAsString(payloadMap);
1927

2028
// The response is not used, only the status code is relevant. If there is a status code not
2129
// equal to 200,

cds-feature-advanced-event-mesh/src/main/java/com/sap/cds/feature/messaging/aem/service/AemMessagingService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class AemMessagingService extends AbstractMessagingService {
3838
private volatile BrokerConnection connection;
3939
private volatile Boolean aemBrokerValidated = false;
4040
private volatile Boolean skipManagement = false;
41+
private volatile String subaccountId = null;
4142

4243
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
4344
protected AemMessagingService(
@@ -57,6 +58,9 @@ protected AemMessagingService(
5758
String skipManagementProperty = properties.get("skipManagement");
5859
String skip_ManagementProperty = properties.get("skip-management");
5960
this.skipManagement = Boolean.parseBoolean(skipManagementProperty) || Boolean.parseBoolean(skip_ManagementProperty);
61+
String subaccountId = properties.getOrDefault("subaccountId", null);
62+
String subaccount_Id = properties.getOrDefault("subaccount-id", null);
63+
this.subaccountId = subaccountId != null ? subaccountId : subaccount_Id;
6064
}
6165

6266
@VisibleForTesting
@@ -163,7 +167,7 @@ private void validate(String endpoint) {
163167
AemValidationClient validationClient = new AemValidationClient(this.validationBinding);
164168

165169
try {
166-
validationClient.validate(endpoint);
170+
validationClient.validate(endpoint, this.subaccountId);
167171
this.aemBrokerValidated = true;
168172
} catch (IOException | URISyntaxException e) {
169173
throw new ServiceException("Failed to validate the AEM endpoint.", e);

0 commit comments

Comments
 (0)