Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public final class DynamicParameterUtil {
public static final String PATTERN_FOR_DYNAMIC_PARAMETERS = "'{'ds/{0}/{1}'}'";
public static final String REGEX_PATTERN_FOR_DYNAMIC_PARAMETERS = "^\\{ds[A-Za-z0-9_\\-\\.\\/]+\\}$";

private static final String SERVICE_KEY_REFERENCE_PREFIX = "service-keys.";
private static final String CREDENTIALS_SEPARATOR = ".credentials.";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is written, this will only work for a 'credentials' map inside the service key. Should this be a bit more general or do we intentionally want it this way? What would happen if the ztis service changes the internal service key parameter structure.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

credentials is the standard CF contract for service keys, not a ZTIS-specific structure. Every CF service key, regardless of service type, returns its useful data under credentials

Comment on lines +8 to +9

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are these dots after or between keywords?

@stiv03 stiv03 Nov 17, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dots are delimiters in the{ds/<resource>/service-keys.<key>.credentials.<field>} reference syntax, and they're part of that literal text. The two constants are just the fixed delimiter substrings used to split the reference into its parts:

SERVICE_KEY_REFERENCE_PREFIX = "service-keys." - separates the literal service-keys token from the key name, so we can strip it off and get key

CREDENTIALS_SEPARATOR = ".credentials." - fences off the literal credentials token, so we can split off field

for exampel: "{ds/source-service/service-keys.source-key.credentials.clientid}"


private DynamicParameterUtil() {
}

Expand All @@ -16,4 +19,16 @@ public static String getParameterName(String dynamicParameter) {
return dynamicParameter.substring(dynamicParameter.lastIndexOf("/") + 1, dynamicParameter.lastIndexOf("}"));
}

public static boolean isServiceKeyCredentialReference(String parameterName) {
return parameterName.startsWith(SERVICE_KEY_REFERENCE_PREFIX) && parameterName.contains(CREDENTIALS_SEPARATOR);
}

public static String getServiceKeyName(String parameterName) {
return parameterName.substring(SERVICE_KEY_REFERENCE_PREFIX.length(), parameterName.indexOf(CREDENTIALS_SEPARATOR));
}

public static String getCredentialFieldPath(String parameterName) {
return parameterName.substring(parameterName.indexOf(CREDENTIALS_SEPARATOR) + CREDENTIALS_SEPARATOR.length());
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.cloudfoundry.multiapps.mta.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.stream.Stream;
Expand Down Expand Up @@ -34,4 +35,41 @@ void testMatchDynamicParameter(String dynamicParameter, String relationshipName,
assertTrue(dynamicParameter.matches(DynamicParameterUtil.REGEX_PATTERN_FOR_DYNAMIC_PARAMETERS));
}

static Stream<Arguments> getServiceKeyCredentialParameters() {
// dynamicParameter, relationshipName, serviceKeyName, credentialFieldPath
return Stream.of(
Arguments.of("{ds/ztis-config/service-keys.my-key.credentials.issuer}", "ztis-config", "my-key", "issuer"),
Arguments.of("{ds/ztis-config/service-keys.my-key.credentials.endpoints.url}", "ztis-config", "my-key", "endpoints.url"));
}

@ParameterizedTest
@MethodSource(value = "getServiceKeyCredentialParameters")
void testIsServiceKeyCredentialReference(String dynamicParameter, String relationshipName, String serviceKeyName,
String credentialFieldPath) {
String parameterName = DynamicParameterUtil.getParameterName(dynamicParameter);
assertTrue(DynamicParameterUtil.isServiceKeyCredentialReference(parameterName));
}

@ParameterizedTest
@MethodSource(value = "getParameters")
void testServiceGuidIsNotServiceKeyCredentialReference(String dynamicParameter, String relationshipName, String parameterName) {
assertFalse(DynamicParameterUtil.isServiceKeyCredentialReference(parameterName));
}

@ParameterizedTest
@MethodSource(value = "getServiceKeyCredentialParameters")
void testParseOfServiceKeyName(String dynamicParameter, String relationshipName, String serviceKeyName,
String credentialFieldPath) {
String parameterName = DynamicParameterUtil.getParameterName(dynamicParameter);
assertEquals(serviceKeyName, DynamicParameterUtil.getServiceKeyName(parameterName));
}

@ParameterizedTest
@MethodSource(value = "getServiceKeyCredentialParameters")
void testParseOfCredentialFieldPath(String dynamicParameter, String relationshipName, String serviceKeyName,
String credentialFieldPath) {
String parameterName = DynamicParameterUtil.getParameterName(dynamicParameter);
assertEquals(credentialFieldPath, DynamicParameterUtil.getCredentialFieldPath(parameterName));
}

}
Loading