Skip to content

Commit d453d78

Browse files
committed
improve service binding logic
1 parent d2db8a7 commit d453d78

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

core/src/main/java/com/sap/ai/sdk/core/AiCoreServiceKeyAccessor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ static ServiceBinding createServiceBinding(@Nonnull final String serviceKey)
8181
new AiCoreCredentialsInvalidException("Missing clientid in service key"));
8282
}
8383

84+
if (credentials.get("clientsecret") != null && credentials.get("credentials-type") == null) {
85+
// add missing "credential-type: binding-secret"
86+
credentials.put("credential-type", "binding-secret");
87+
}
88+
8489
return new DefaultServiceBindingBuilder()
8590
.withServiceIdentifier(ServiceIdentifier.AI_CORE)
8691
.withCredentials(credentials)

core/src/test/java/com/sap/ai/sdk/core/DestinationResolverTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ void testGetDestinationFromBinding() {
3030
var binding = AiCoreServiceKeyAccessor.createServiceBinding(serviceKey);
3131
var resolver = new DestinationResolver(() -> List.of(binding));
3232
var result = resolver.getDestination();
33+
assertThat(binding.getCredentials().containsKey("credential-type"))
34+
.describedAs("The missing 'credential-type' should have automatically been added")
35+
.isTrue();
3336
assertThat(result.getUri())
3437
.describedAs("The destination should already contain the /v2 base path")
3538
.hasToString("https://api.ai.core/v2/");

0 commit comments

Comments
 (0)