Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
7ec0e84
feat: Extend add-new-model generator to support external services for…
mmilko01 Apr 6, 2026
72da9ea
fix: various fixes
mmilko01 Apr 7, 2026
3b4fc46
fix: add additional message for annotation URI prompt
mmilko01 Apr 7, 2026
9998d2a
chore: resolve conflicts
mmilko01 Apr 7, 2026
d35a6fa
Linting auto fix commit
github-actions[bot] Apr 7, 2026
f52d6c3
fix: remove install and build steps from generator
mmilko01 Apr 7, 2026
abe6ca5
Merge branch 'feat/add-external-service-cf' of https://github.com/SAP…
mmilko01 Apr 7, 2026
e9b501a
refactor: remove unneeded code
mmilko01 Apr 7, 2026
bc623f6
chore: create changeset
mmilko01 Apr 7, 2026
e360a3e
chore: fix changeset
mmilko01 Apr 8, 2026
08469db
test: fix tests for windows
mmilko01 Apr 8, 2026
f984760
test: fix tests for windows
mmilko01 Apr 8, 2026
1e569e2
test: fix api tests file format
mmilko01 Apr 8, 2026
fb18f4d
refactor: move btp related api call to /btp
mmilko01 Apr 8, 2026
236a9c4
fix: sonar issues
mmilko01 Apr 8, 2026
21be925
Linting auto fix commit
github-actions[bot] Apr 8, 2026
53a3786
fix: address comments
mmilko01 Apr 8, 2026
2bf588e
Merge
mmilko01 Apr 8, 2026
75df0e2
fix: address text comments
mmilko01 Apr 8, 2026
88ad967
fix: sonar issue
mmilko01 Apr 8, 2026
c0990ea
Linting auto fix commit
github-actions[bot] Apr 8, 2026
0123c19
fix: expected texts in tests
mmilko01 Apr 8, 2026
4c75522
Merge branch 'feat/add-external-service-cf' of https://github.com/SAP…
mmilko01 Apr 8, 2026
010704a
fix: for HTTP service type use different change type
mmilko01 Apr 8, 2026
f5056bf
fix: address comments
mmilko01 Apr 8, 2026
26509c2
Merge branch 'main' into feat/add-external-service-cf
mmilko01 Apr 8, 2026
d11c3cb
chore: address text comments
mmilko01 Apr 8, 2026
ba12478
Merge branch 'main' into feat/add-external-service-cf
mmilko01 Apr 9, 2026
d513390
fix: translations json
mmilko01 Apr 9, 2026
39106d6
fix: lint issue
mmilko01 Apr 9, 2026
c278645
Merge branch 'main' into feat/add-external-service-cf
mmilko01 Apr 9, 2026
5374259
chore: simplify code
mmilko01 Apr 9, 2026
b2c143f
Merge branch 'feat/add-external-service-cf' of https://github.com/SAP…
mmilko01 Apr 9, 2026
54a699d
fix: address comments
mmilko01 Apr 9, 2026
0b97b86
test: update changed text
mmilko01 Apr 14, 2026
9d6ee47
fix: validation for duplicate change
mmilko01 Apr 14, 2026
87a8d3f
fix: add check for org/space mismatch
mmilko01 Apr 14, 2026
c9597aa
fix: remove leading slash in CF scenario for change uri
mmilko01 Apr 14, 2026
67f96f6
Linting auto fix commit
github-actions[bot] Apr 14, 2026
b9183e5
Merge branch 'main' into feat/add-external-service-cf
mmilko01 Apr 14, 2026
7c21623
Merge branch 'main' into feat/add-external-service-cf
nikmace Apr 15, 2026
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
7 changes: 7 additions & 0 deletions .changeset/selfish-monkeys-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@sap-ux/adp-tooling": patch
"@sap-ux/generator-adp": patch
"@sap-ux/create": patch
---

feat: Extend add-new-model generator to support external services for CF projects
45 changes: 41 additions & 4 deletions packages/adp-tooling/src/btp/api.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import axios from 'axios';

import type { ToolsLogger } from '@sap-ux/logger';
import type { Destinations } from '@sap-ux/btp-utils';

import { t } from '../i18n';
import type { Uaa, BtpDestinationConfig } from '../types';
import type { Uaa, BtpDestinationConfig, CfDestinationServiceCredentials } from '../types';

/**
* Obtain an OAuth2 access token using the client credentials grant.
Expand All @@ -27,8 +28,8 @@ export async function getToken(uaa: Uaa, logger?: ToolsLogger): Promise<string>
logger?.debug('OAuth token obtained successfully');
return response.data['access_token'];
} catch (e) {
logger?.error(`Failed to obtain OAuth token from ${uri}: ${e.message}`);
throw new Error(t('error.failedToGetAuthKey', { error: e.message }));
logger?.error(`Failed to obtain OAuth token from ${uri}: ${e instanceof Error ? e.message : String(e)}`);
throw new Error(t('error.failedToGetAuthKey', { error: e instanceof Error ? e.message : String(e) }));
}
}

Expand Down Expand Up @@ -59,7 +60,43 @@ export async function getBtpDestinationConfig(
logger?.debug(`Destination "${destinationName}" config: ProxyType=${config?.ProxyType}`);
return config;
} catch (e) {
logger?.error(`Failed to fetch destination config for "${destinationName}": ${e.message}`);
logger?.error(
`Failed to fetch destination config for "${destinationName}": ${e instanceof Error ? e.message : String(e)}`
);
return undefined;
}
}

/**
* Lists all subaccount destinations from the BTP Destination Configuration API.
*
* @param {CfDestinationServiceCredentials} credentials - Destination service credentials.
* @returns {Promise<Destinations>} Map of destination name to Destination object.
*/
export async function listBtpDestinations(credentials: CfDestinationServiceCredentials): Promise<Destinations> {
const uaa =
'uaa' in credentials
? credentials.uaa
: { clientid: credentials.clientid, clientsecret: credentials.clientsecret, url: credentials.url };
const token = await getToken(uaa);
const url = `${credentials.uri}/destination-configuration/v1/subaccountDestinations`;
try {
const response = await axios.get<BtpDestinationConfig[]>(url, {
headers: { Authorization: `Bearer ${token}` }
});
const configs = Array.isArray(response.data) ? response.data : [];
return configs.reduce<Destinations>((acc, config) => {
acc[config.Name] = {
Name: config.Name,
Host: config.URL,
Type: config.Type,
Authentication: config.Authentication,
ProxyType: config.ProxyType,
Description: config.Description ?? ''
};
return acc;
}, {});
} catch (e) {
throw new Error(t('error.failedToListBtpDestinations', { error: e instanceof Error ? e.message : String(e) }));
}
}
51 changes: 50 additions & 1 deletion packages/adp-tooling/src/cf/project/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import type {
ServiceKeys
} from '../../types';
import { AppRouterType } from '../../types';
import { createServices } from '../services/api';
import { createServices, createServiceInstance, getOrCreateServiceInstanceKeys } from '../services/api';
import { getProjectNameForXsSecurity, getYamlContent } from './yaml-loader';
import { getServiceKeyDestinations } from '../app/discovery';

Expand Down Expand Up @@ -44,6 +44,55 @@ export function isMtaProject(selectedPath: string): boolean {
return fs.existsSync(path.join(selectedPath, 'mta.yaml'));
}

/**
* Adds a connectivity service resource to the project's mta.yaml if not already present,
* creates the CF service instance and generates a service key for it.
* Only applies to MTA projects. Required when the selected CF destination is OnPremise
* so the AppRouter can proxy requests through the Cloud Connector.
*
* @param {string} projectPath - The root path of the project.
* @param {Editor} memFs - The mem-fs editor instance.
* @param {ToolsLogger} [logger] - Optional logger.
*/
export async function addConnectivityServiceToMta(
projectPath: string,
memFs: Editor,
logger?: ToolsLogger
): Promise<void> {
if (!isMtaProject(projectPath)) {
return;
}

const mtaYamlPath = path.join(projectPath, 'mta.yaml');
const yamlContent = getYamlContent<MtaYaml>(mtaYamlPath);
if (!yamlContent) {
return;
}

const projectName = yamlContent.ID.toLowerCase();
const connectivityResourceName = `${projectName}-connectivity`;

if (yamlContent.resources?.some((r: MtaResource) => r.name === connectivityResourceName)) {
return;
}

await createServiceInstance('lite', connectivityResourceName, 'connectivity', { logger });
await getOrCreateServiceInstanceKeys({ names: [connectivityResourceName] }, logger);
Comment thread
heimwege marked this conversation as resolved.

yamlContent.resources = yamlContent.resources ?? [];
yamlContent.resources.push({
name: connectivityResourceName,
type: CF_MANAGED_SERVICE,
parameters: {
service: 'connectivity',
'service-plan': 'lite',
'service-name': connectivityResourceName
}
});

memFs.write(mtaYamlPath, yaml.dump(yamlContent, { lineWidth: -1 }));
}

/**
* Gets the SAP Cloud Service.
*
Expand Down
49 changes: 49 additions & 0 deletions packages/adp-tooling/src/cf/services/destinations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import * as path from 'node:path';

import type { Destinations } from '@sap-ux/btp-utils';

import { getOrCreateServiceInstanceKeys } from './api';
import { listBtpDestinations } from '../../btp/api';
import { getYamlContent } from '../project/yaml-loader';
import { t } from '../../i18n';
import type { CfDestinationServiceCredentials, MtaYaml } from '../../types';

/**
* Finds the name of the destination service instance declared in the MTA project's mta.yaml.
*
* @param {string} projectPath - The root path of the app project.
* @returns {string} The CF service instance name.
* @throws {Error} When the destination service instance is not found or mta.yaml cannot be read.
*/
function getDestinationServiceName(projectPath: string): string {
try {
const yamlContent = getYamlContent<MtaYaml>(path.join(path.dirname(projectPath), 'mta.yaml'));
const name = yamlContent?.resources?.find((r) => r.parameters?.service === 'destination')?.name;
if (!name) {
throw new Error(t('error.destinationServiceNotFoundInMtaYaml'));
}
return name;
} catch (e) {
throw e instanceof Error ? e : new Error(t('error.destinationServiceNotFoundInMtaYaml'));
}
}

/**
* Returns the list of available BTP destinations from the logged-in CF subaccount.
* Reads the destination service credentials from the CF project's service keys
* and calls the BTP Destination Configuration API directly.
*
* @param {string} projectPath - The root path of the CF app project.
* @returns {Promise<Destinations>} Map of destination name to Destination object.
*/
export async function getBtpDestinations(projectPath: string): Promise<Destinations> {
const destinationServiceName = getDestinationServiceName(projectPath);

const serviceInfo = await getOrCreateServiceInstanceKeys({ names: [destinationServiceName] });
if (!serviceInfo?.serviceKeys?.length) {
throw new Error(t('error.noServiceKeysFoundForDestination', { serviceInstanceName: destinationServiceName }));
}

const credentials = serviceInfo.serviceKeys[0].credentials as CfDestinationServiceCredentials;
return listBtpDestinations(credentials);
}
1 change: 1 addition & 0 deletions packages/adp-tooling/src/cf/services/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './api';
export * from './ssh';
export * from './cli';
export * from './destinations';
export * from './manifest';
Loading
Loading