Skip to content

Commit caef1a9

Browse files
MatKuhrMattKuhr
andauthored
feat: Support AI Core by default in Service Binding Destination Loading (#358)
Co-authored-by: Matthias Kuhr <[email protected]>
1 parent a7fe631 commit caef1a9

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

cloudplatform/connectivity-oauth/src/main/java/com/sap/cloud/sdk/cloudplatform/connectivity/BtpServicePropertySuppliers.java

+18
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class BtpServicePropertySuppliers
7676
.withUrlKey(BusinessLoggingOptions.READ_API, "readservice")
7777
.withUrlKey(BusinessLoggingOptions.WRITE_API, "writeservice")
7878
.factory());
79+
static final OAuth2PropertySupplierResolver AI_CORE =
80+
OAuth2PropertySupplierResolver.forServiceIdentifier(ServiceIdentifier.of("aicore"), AiCore::new);
7981

8082
private static final List<OAuth2PropertySupplierResolver> DEFAULT_SERVICE_RESOLVERS = new ArrayList<>();
8183

@@ -86,6 +88,7 @@ class BtpServicePropertySuppliers
8688
DEFAULT_SERVICE_RESOLVERS.add(WORKFLOW);
8789
DEFAULT_SERVICE_RESOLVERS.add(BUSINESS_LOGGING);
8890
DEFAULT_SERVICE_RESOLVERS.add(IDENTITY_AUTHENTICATION);
91+
DEFAULT_SERVICE_RESOLVERS.add(AI_CORE);
8992
}
9093

9194
static List<OAuth2PropertySupplierResolver> getDefaultServiceResolvers()
@@ -255,4 +258,19 @@ private KeyStore getClientKeyStore()
255258
}
256259
}
257260
}
261+
262+
private static class AiCore extends DefaultOAuth2PropertySupplier
263+
{
264+
AiCore( @Nonnull final ServiceBindingDestinationOptions options )
265+
{
266+
super(options, Collections.emptyList());
267+
}
268+
269+
@Nonnull
270+
@Override
271+
public URI getServiceUri()
272+
{
273+
return getCredentialOrThrow(URI.class, "serviceurls", "AI_API_URL");
274+
}
275+
}
258276
}

cloudplatform/connectivity-oauth/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/BtpServicePropertySuppliersTest.java

+31
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package com.sap.cloud.sdk.cloudplatform.connectivity;
66

77
import static com.sap.cloud.sdk.cloudplatform.connectivity.BtpServiceOptions.IasOptions;
8+
import static com.sap.cloud.sdk.cloudplatform.connectivity.BtpServicePropertySuppliers.AI_CORE;
89
import static com.sap.cloud.sdk.cloudplatform.connectivity.BtpServicePropertySuppliers.BUSINESS_LOGGING;
910
import static com.sap.cloud.sdk.cloudplatform.connectivity.BtpServicePropertySuppliers.BUSINESS_RULES;
1011
import static com.sap.cloud.sdk.cloudplatform.connectivity.BtpServicePropertySuppliers.CONNECTIVITY;
@@ -16,6 +17,7 @@
1617
import static org.assertj.core.api.Assertions.entry;
1718

1819
import java.lang.reflect.Modifier;
20+
import java.net.URI;
1921
import java.nio.file.Files;
2022
import java.nio.file.Path;
2123
import java.security.KeyStore;
@@ -246,6 +248,35 @@ void testThrowsWithoutOption()
246248
}
247249
}
248250

251+
@Nested
252+
@DisplayName( "AiCore" )
253+
class AiCoreTest
254+
{
255+
final ServiceBinding binding =
256+
bindingWithCredentials(
257+
ServiceIdentifier.of("aicore"),
258+
entry("serviceurls.AI_API_URL", "https://api.ai.internalprod.eu-central-1.aws.ml.hana.ondemand.com"),
259+
entry("clientid", "client-id"),
260+
entry("clientsecret", "client-secret"),
261+
entry("url", "https://subaccount.authentication.sap.hana.ondemand.com"));
262+
263+
@Test
264+
void testAiCore()
265+
{
266+
final ServiceBindingDestinationOptions options =
267+
ServiceBindingDestinationOptions.forService(binding).build();
268+
269+
final OAuth2PropertySupplier sut = AI_CORE.resolve(options);
270+
271+
assertThat(sut.getServiceUri())
272+
.isEqualTo(URI.create("https://api.ai.internalprod.eu-central-1.aws.ml.hana.ondemand.com"));
273+
assertThat(sut.getClientIdentity().getId()).isEqualTo("client-id");
274+
assertThat(sut.getClientIdentity().getSecret()).isEqualTo("client-secret");
275+
assertThat(sut.getTokenUri())
276+
.isEqualTo(URI.create("https://subaccount.authentication.sap.hana.ondemand.com"));
277+
}
278+
}
279+
249280
@Nested
250281
@DisplayName( "Business Logging" )
251282
class BusinessLoggingTest

release_notes.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
### ✨ New Functionality
1414

15-
-
15+
- Support service bindings to the [SAP BTP AI Core Service](https://api.sap.com/api/AI_CORE_API) by default in the `ServiceBindingDestinationLoader` API.
1616

1717
### 📈 Improvements
1818

0 commit comments

Comments
 (0)