Skip to content

Commit

Permalink
feat: Support AI Core Service Binding (#4563)
Browse files Browse the repository at this point in the history
* Support AI Core Service Binding

* Changes from lint:fix

* Add changenote

---------

Co-authored-by: cloud-sdk-js <cloud-sdk-js@github.com>
Co-authored-by: Dennis Hempfing <dennis.hempfing@sap.com>
  • Loading branch information
3 people committed Mar 14, 2024
1 parent aa6d6c8 commit f72986a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/fifty-clouds-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sap-cloud-sdk/connectivity": minor
---

Support the AI Core Service Binding when creating destinations from service bindings
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ describe('vcap-service-destination', () => {
return spyInstance.mock.calls[0][0]['credentials']['clientid'];
}

it('creates a destination for the aicore service', async () => {
await expect(
getDestinationFromServiceBinding({
destinationName: 'my-aicore',
jwt: providerUserToken
})
).resolves.toEqual({
url: 'https://https://api.ai.internalprod.eu-central-1.aws.ml.hana.ondemand.com',
authentication: 'OAuth2ClientCredentials',
name: 'my-aicore',
authTokens: [expect.objectContaining({ value: expect.any(String) })]
});

expect(getActualClientId(serviceTokenSpy)).toBe('clientIdBusinessLogging');
});

it('creates a destination for the business logging service', async () => {
await expect(
getDestinationFromServiceBinding({
Expand Down Expand Up @@ -324,6 +340,22 @@ function mockServiceBindings() {
}

const serviceBindings = {
aicore: [
{
name: 'my-aicore',
label: 'aicore',
tags: ['aicore'],
credentials: {
serviceurls: {
AI_API_URL:
'https://https://api.ai.internalprod.eu-central-1.aws.ml.hana.ondemand.com'
},
clientid: 'clientIdAicore',
clientsecret: 'secretAicore',
url: 'https://subaccount.authentication.sap.hana.ondemand.com'
}
}
],
'business-logging': [
{
name: 'my-business-logging',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,22 @@ export const serviceToDestinationTransformers: Record<
'saas-registry': saasRegistryBindingToDestination,
workflow: workflowBindingToDestination,
'service-manager': serviceManagerBindingToDestination,
xsuaa: xsuaaToDestination
xsuaa: xsuaaToDestination,
aicore: aicoreToDestiation
};

async function aicoreToDestiation(
service: Service,
options?: ServiceBindingTransformOptions
): Promise<Destination> {
const token = await serviceToken(service, options);
return buildClientCredentialsDestination(
token,
service.credentials.serviceurls.AI_API_URL,
service.name
);
}

async function xsuaaToDestination(
service: Service,
options?: ServiceBindingTransformOptions
Expand Down

0 comments on commit f72986a

Please sign in to comment.