@sap-ux/adp-tooling 0.18.97 → 0.18.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cf/services/api.js +2 -2
- package/dist/cf/services/cli.d.ts +7 -5
- package/dist/cf/services/cli.js +37 -5
- package/dist/types.d.ts +1 -0
- package/package.json +1 -1
package/dist/cf/services/api.js
CHANGED
|
@@ -329,7 +329,7 @@ async function getServiceInstance(params) {
|
|
|
329
329
|
async function getOrCreateServiceKeys(serviceInstance, logger) {
|
|
330
330
|
const serviceInstanceName = serviceInstance.name;
|
|
331
331
|
try {
|
|
332
|
-
const credentials = await (0, cli_1.getServiceKeys)(serviceInstance.guid);
|
|
332
|
+
const credentials = await (0, cli_1.getServiceKeys)(serviceInstance.guid, 'updated_at', logger);
|
|
333
333
|
if (credentials?.length > 0) {
|
|
334
334
|
return credentials;
|
|
335
335
|
}
|
|
@@ -337,7 +337,7 @@ async function getOrCreateServiceKeys(serviceInstance, logger) {
|
|
|
337
337
|
const serviceKeyName = serviceInstanceName + '_key';
|
|
338
338
|
logger?.log(`Creating service key '${serviceKeyName}' for service instance '${serviceInstanceName}'`);
|
|
339
339
|
await (0, cli_1.createServiceKey)(serviceInstanceName, serviceKeyName);
|
|
340
|
-
return (0, cli_1.getServiceKeys)(serviceInstance.guid);
|
|
340
|
+
return (0, cli_1.getServiceKeys)(serviceInstance.guid, 'updated_at', logger);
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
343
|
catch (e) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ToolsLogger } from '@sap-ux/logger';
|
|
2
|
-
import type { ServiceKeys } from '../../types';
|
|
2
|
+
import type { ServiceKeys, ServiceKeySortField } from '../../types';
|
|
3
3
|
/**
|
|
4
4
|
* Checks if Cloud Foundry is installed.
|
|
5
5
|
*
|
|
@@ -8,12 +8,14 @@ import type { ServiceKeys } from '../../types';
|
|
|
8
8
|
*/
|
|
9
9
|
export declare function isCfInstalled(logger: ToolsLogger): Promise<boolean>;
|
|
10
10
|
/**
|
|
11
|
-
* Gets the service instance credentials.
|
|
11
|
+
* Gets the service instance credentials, sorted by the specified metadata field.
|
|
12
12
|
*
|
|
13
|
-
* @param
|
|
14
|
-
* @
|
|
13
|
+
* @param serviceInstanceGuid - The service instance GUID.
|
|
14
|
+
* @param sortBy - The metadata field to sort by, defaults to 'updated_at'.
|
|
15
|
+
* @param logger - Optional logger.
|
|
16
|
+
* @returns The service instance credentials sorted by the specified field (newest first).
|
|
15
17
|
*/
|
|
16
|
-
export declare function getServiceKeys(serviceInstanceGuid: string): Promise<ServiceKeys[]>;
|
|
18
|
+
export declare function getServiceKeys(serviceInstanceGuid: string, sortBy?: ServiceKeySortField, logger?: ToolsLogger): Promise<ServiceKeys[]>;
|
|
17
19
|
/**
|
|
18
20
|
* Creates a service key.
|
|
19
21
|
*
|
package/dist/cf/services/cli.js
CHANGED
|
@@ -27,14 +27,16 @@ async function isCfInstalled(logger) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* Gets the service instance credentials.
|
|
30
|
+
* Gets the service instance credentials, sorted by the specified metadata field.
|
|
31
31
|
*
|
|
32
|
-
* @param
|
|
33
|
-
* @
|
|
32
|
+
* @param serviceInstanceGuid - The service instance GUID.
|
|
33
|
+
* @param sortBy - The metadata field to sort by, defaults to 'updated_at'.
|
|
34
|
+
* @param logger - Optional logger.
|
|
35
|
+
* @returns The service instance credentials sorted by the specified field (newest first).
|
|
34
36
|
*/
|
|
35
|
-
async function getServiceKeys(serviceInstanceGuid) {
|
|
37
|
+
async function getServiceKeys(serviceInstanceGuid, sortBy = 'updated_at', logger) {
|
|
36
38
|
try {
|
|
37
|
-
|
|
39
|
+
const resources = await (0, cf_tools_1.cfGetServiceKeys)({
|
|
38
40
|
filters: [
|
|
39
41
|
{
|
|
40
42
|
value: serviceInstanceGuid,
|
|
@@ -42,6 +44,36 @@ async function getServiceKeys(serviceInstanceGuid) {
|
|
|
42
44
|
}
|
|
43
45
|
]
|
|
44
46
|
});
|
|
47
|
+
logger?.info(`Found ${resources.length} service key(s) for instance '${serviceInstanceGuid}'`);
|
|
48
|
+
const sorted = [...resources].sort((a, b) => {
|
|
49
|
+
const dateA = a[sortBy];
|
|
50
|
+
const dateB = b[sortBy];
|
|
51
|
+
if (!dateA && !dateB) {
|
|
52
|
+
return 0;
|
|
53
|
+
}
|
|
54
|
+
if (!dateA) {
|
|
55
|
+
return 1;
|
|
56
|
+
}
|
|
57
|
+
if (!dateB) {
|
|
58
|
+
return -1;
|
|
59
|
+
}
|
|
60
|
+
return new Date(dateB).getTime() - new Date(dateA).getTime();
|
|
61
|
+
});
|
|
62
|
+
if (sorted.length > 0) {
|
|
63
|
+
logger?.debug(`Service keys sorted by '${sortBy}', using key '${sorted[0].name}' as primary`);
|
|
64
|
+
}
|
|
65
|
+
const results = await Promise.all(sorted.map(async (resource) => {
|
|
66
|
+
try {
|
|
67
|
+
return await requestCfApi(`/v3/service_credential_bindings/${resource.guid}/details`);
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
logger?.warn(`Failed to fetch credentials for service key '${resource.name}': ${e.message}`);
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
}));
|
|
74
|
+
const filtered = results.filter((r) => r !== undefined);
|
|
75
|
+
logger?.debug(`Retrieved credentials for ${filtered.length} of ${sorted.length} service key(s)`);
|
|
76
|
+
return filtered;
|
|
45
77
|
}
|
|
46
78
|
catch (e) {
|
|
47
79
|
throw new Error((0, i18n_1.t)('error.cfGetInstanceCredentialsFailed', { serviceInstanceGuid, error: e.message }));
|
package/dist/types.d.ts
CHANGED
|
@@ -801,6 +801,7 @@ export interface CfAppParams {
|
|
|
801
801
|
export interface AppParamsExtended extends CfAppParams {
|
|
802
802
|
spaceGuid: string;
|
|
803
803
|
}
|
|
804
|
+
export type ServiceKeySortField = 'updated_at' | 'created_at';
|
|
804
805
|
export interface ServiceKeys {
|
|
805
806
|
credentials: {
|
|
806
807
|
[key: string]: any;
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/SAP/open-ux-tools/issues?q=is%3Aopen+is%3Aissue+label%3Abug+label%3Aadp-tooling"
|
|
11
11
|
},
|
|
12
|
-
"version": "0.18.
|
|
12
|
+
"version": "0.18.98",
|
|
13
13
|
"license": "Apache-2.0",
|
|
14
14
|
"author": "@SAP/ux-tools-team",
|
|
15
15
|
"main": "dist/index.js",
|