@ui5/task-adaptation 1.6.7 → 1.7.0
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/.github/workflows/codeql.yml +35 -0
- package/.github/workflows/release-please.yml +53 -0
- package/.release-please-manifest.json +3 -0
- package/CHANGELOG.md +42 -36
- package/dist/adapters/abapAdapter.d.ts +3 -3
- package/dist/adapters/abapAdapter.js +19 -8
- package/dist/adapters/adapter.d.ts +3 -2
- package/dist/adapters/adapter.js +9 -3
- package/dist/adapters/cfAdapter.d.ts +2 -2
- package/dist/adapters/cfAdapter.js +12 -12
- package/dist/adapters/commands/command.js +0 -27
- package/dist/adapters/commands/downloadAnnotationsCommand.d.ts +3 -4
- package/dist/adapters/commands/downloadAnnotationsCommand.js +4 -4
- package/dist/adapters/commands/fetchPreviewResourcesCommand.js +1 -1
- package/dist/adapters/commands/omitDeletedResourcesCommand.d.ts +1 -1
- package/dist/adapters/commands/renameFilesCommand.d.ts +0 -22
- package/dist/adapters/commands/renameFilesCommand.js +2 -114
- package/dist/adapters/commands/renameManifestCommand.js +2 -2
- package/dist/adapters/previewAdapter.d.ts +2 -2
- package/dist/adapters/previewAdapter.js +4 -4
- package/dist/annotations/abapAnnotationManager.js +1 -3
- package/dist/annotations/dataSource/dataSource.d.ts +6 -5
- package/dist/annotations/dataSource/dataSource.js +36 -12
- package/dist/annotations/dataSource/dataSourceManager.d.ts +2 -2
- package/dist/annotations/dataSource/dataSourceManager.js +2 -2
- package/dist/annotations/dataSource/dataSourceOData.d.ts +2 -2
- package/dist/annotations/transformers/transformer.d.ts +2 -2
- package/dist/annotations/transformers/traverseReferences.d.ts +1 -1
- package/dist/annotations/transformers/traverseReferences.js +2 -2
- package/dist/appVariant.d.ts +5 -7
- package/dist/appVariant.js +9 -23
- package/dist/baseApp.d.ts +1 -0
- package/dist/baseApp.js +10 -0
- package/dist/bundle.js +86 -53
- package/dist/cache/cacheHolder.d.ts +6 -12
- package/dist/cache/cacheHolder.js +27 -39
- package/dist/cache/cachedResource.d.ts +2 -1
- package/dist/index.d.ts +6 -7
- package/dist/index.js +49 -42
- package/dist/landscapeConfiguration.d.ts +4 -4
- package/dist/landscapeConfiguration.js +48 -44
- package/dist/model/configuration.d.ts +0 -1
- package/dist/model/types.d.ts +1 -3
- package/dist/repositories/abapRepository.d.ts +1 -1
- package/dist/repositories/abapRepository.js +3 -3
- package/dist/repositories/cacheRepository.d.ts +4 -5
- package/dist/repositories/cacheRepository.js +10 -18
- package/dist/repositories/html5Repository.d.ts +1 -1
- package/dist/repositories/html5Repository.js +2 -2
- package/dist/repositories/localRepository.d.ts +1 -1
- package/dist/repositories/localRepository.js +2 -2
- package/dist/repositories/repository.d.ts +1 -1
- package/dist/util/cfUtil.d.ts +6 -24
- package/dist/util/cfUtil.js +36 -93
- package/dist/util/commonUtil.d.ts +1 -9
- package/dist/util/commonUtil.js +27 -29
- package/dist/util/fsUtil.js +1 -2
- package/dist/util/movingHandler/changeFileMoveHandler.d.ts +1 -0
- package/dist/util/movingHandler/changeFileMoveHandler.js +11 -3
- package/dist/util/referencesBuilder.d.ts +15 -0
- package/dist/util/referencesBuilder.js +35 -0
- package/dist/util/renaming/fileRenamer.d.ts +23 -0
- package/dist/util/renaming/fileRenamer.js +120 -0
- package/dist/util/{renamingHandlers → renaming/handlers}/jsonRenamingHandler.d.ts +0 -2
- package/dist/util/{renamingHandlers → renaming/handlers}/jsonRenamingHandler.js +0 -6
- package/dist/util/{renamingUtil.d.ts → renaming/referenceRenaming.d.ts} +4 -4
- package/dist/util/{renamingUtil.js → renaming/referenceRenaming.js} +8 -8
- package/dist/util/resourceUtil.js +6 -2
- package/package.json +11 -4
- package/release-please-config.json +66 -0
- package/dist/annotations/serviceRequestor.d.ts +0 -9
- package/dist/annotations/serviceRequestor.js +0 -62
- /package/dist/util/{renamingHandlers → renaming/handlers}/manifestRenamingHandler.d.ts +0 -0
- /package/dist/util/{renamingHandlers → renaming/handlers}/manifestRenamingHandler.js +0 -0
|
@@ -8,12 +8,16 @@ const log = getLogger("@ui5/task-adaptation::LandscapeConfiguration");
|
|
|
8
8
|
export async function initialize(configuration, options = {}) {
|
|
9
9
|
const type = await getTypeByConfiguration(configuration);
|
|
10
10
|
const enhancedConfig = { ...configuration, type };
|
|
11
|
-
|
|
11
|
+
let repository = await getRepository(enhancedConfig);
|
|
12
12
|
const annotationManager = await getAnnotationManager(enhancedConfig, repository);
|
|
13
|
+
if (options.useCache) {
|
|
14
|
+
const { default: CacheRepository } = await import("./repositories/cacheRepository.js");
|
|
15
|
+
repository = new CacheRepository(repository);
|
|
16
|
+
}
|
|
17
|
+
const adapter = await getAdapter(enhancedConfig, annotationManager);
|
|
13
18
|
return {
|
|
14
|
-
adapter
|
|
15
|
-
repository
|
|
16
|
-
annotationManager
|
|
19
|
+
adapter,
|
|
20
|
+
repository
|
|
17
21
|
};
|
|
18
22
|
}
|
|
19
23
|
async function getTypeByConfiguration(configuration) {
|
|
@@ -38,62 +42,62 @@ async function getTypeByConfiguration(configuration) {
|
|
|
38
42
|
throw new Error("'type' should be specified in ui5.yaml configuration: 'cf' or 'abap'");
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return new PreviewAdapter(configuration);
|
|
45
|
-
}
|
|
46
|
-
switch (configuration.type) {
|
|
47
|
-
case "abap": {
|
|
45
|
+
const LANDSCAPE_FACTORIES = {
|
|
46
|
+
abap: {
|
|
47
|
+
adapter: async (_configuration, annotationManager) => {
|
|
48
48
|
const { default: AbapAdapter } = await import("./adapters/abapAdapter.js");
|
|
49
49
|
return new AbapAdapter(annotationManager);
|
|
50
|
-
}
|
|
51
|
-
|
|
50
|
+
},
|
|
51
|
+
repository: async (configuration) => {
|
|
52
|
+
const { default: AbapRepository } = await import("./repositories/abapRepository.js");
|
|
53
|
+
return new AbapRepository(configuration);
|
|
54
|
+
},
|
|
55
|
+
annotationManager: async (configuration, repository) => {
|
|
56
|
+
const { default: AbapAnnotationManager } = await import("./annotations/abapAnnotationManager.js");
|
|
57
|
+
return new AbapAnnotationManager(configuration, repository);
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
cf: {
|
|
61
|
+
adapter: async (configuration) => {
|
|
52
62
|
const { default: CFAdapter } = await import("./adapters/cfAdapter.js");
|
|
53
63
|
return new CFAdapter(configuration);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
64
|
+
},
|
|
65
|
+
repository: async (configuration) => {
|
|
66
|
+
const { default: HTML5Repository } = await import("./repositories/html5Repository.js");
|
|
67
|
+
return new HTML5Repository(configuration);
|
|
68
|
+
},
|
|
69
|
+
annotationManager: async () => {
|
|
70
|
+
const { default: CFAnnotationManager } = await import("./annotations/cfAnnotationManager.js");
|
|
71
|
+
return new CFAnnotationManager();
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
function landscapeFactory(configuration) {
|
|
76
|
+
const factory = LANDSCAPE_FACTORIES[configuration.type];
|
|
77
|
+
if (!factory) {
|
|
78
|
+
throw new Error(`No landscape factory found for the given configuration type '${configuration.type}'`);
|
|
57
79
|
}
|
|
80
|
+
return factory;
|
|
58
81
|
}
|
|
59
|
-
async function
|
|
60
|
-
if (
|
|
61
|
-
const { default:
|
|
62
|
-
return new
|
|
82
|
+
async function getAdapter(configuration, annotationManager) {
|
|
83
|
+
if (isPreview()) {
|
|
84
|
+
const { default: PreviewAdapter } = await import("./adapters/previewAdapter.js");
|
|
85
|
+
return new PreviewAdapter(configuration);
|
|
63
86
|
}
|
|
87
|
+
return landscapeFactory(configuration).adapter(configuration, annotationManager);
|
|
88
|
+
}
|
|
89
|
+
async function getRepository(configuration) {
|
|
64
90
|
if (isLocal()) {
|
|
65
91
|
const { default: LocalRepository } = await import("./repositories/localRepository.js");
|
|
66
92
|
return new LocalRepository();
|
|
67
93
|
}
|
|
68
|
-
|
|
69
|
-
case "abap": {
|
|
70
|
-
const { default: AbapRepository } = await import("./repositories/abapRepository.js");
|
|
71
|
-
return new AbapRepository(configuration);
|
|
72
|
-
}
|
|
73
|
-
case "cf": {
|
|
74
|
-
const { default: HTML5Repository } = await import("./repositories/html5Repository.js");
|
|
75
|
-
return new HTML5Repository(configuration);
|
|
76
|
-
}
|
|
77
|
-
default:
|
|
78
|
-
throw new Error(`No repository found for the given configuration type '${configuration.type}'`);
|
|
79
|
-
}
|
|
94
|
+
return landscapeFactory(configuration).repository(configuration);
|
|
80
95
|
}
|
|
81
96
|
async function getAnnotationManager(configuration, repository) {
|
|
82
97
|
if (isLocal()) {
|
|
83
98
|
return new LocalAnnotationManager();
|
|
84
99
|
}
|
|
85
|
-
|
|
86
|
-
case "abap": {
|
|
87
|
-
const { default: AbapAnnotationManager } = await import("./annotations/abapAnnotationManager.js");
|
|
88
|
-
return new AbapAnnotationManager(configuration, repository);
|
|
89
|
-
}
|
|
90
|
-
case "cf": {
|
|
91
|
-
const { default: CFAnnotationManager } = await import("./annotations/cfAnnotationManager.js");
|
|
92
|
-
return new CFAnnotationManager();
|
|
93
|
-
}
|
|
94
|
-
default:
|
|
95
|
-
throw new Error(`No annotation manager found for the given configuration type '${configuration.type}'`);
|
|
96
|
-
}
|
|
100
|
+
return landscapeFactory(configuration).annotationManager(configuration, repository);
|
|
97
101
|
}
|
|
98
102
|
function isLocal() {
|
|
99
103
|
return process.env.ADP_BUILDER_MODE === "local";
|
package/dist/model/types.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export interface IGetServiceInstanceParams {
|
|
|
22
22
|
export interface IServiceInstance {
|
|
23
23
|
name: string;
|
|
24
24
|
guid: string;
|
|
25
|
+
type?: string;
|
|
25
26
|
}
|
|
26
27
|
export interface IResource {
|
|
27
28
|
name: string;
|
|
@@ -131,6 +132,3 @@ export type ServiceCredentials = {
|
|
|
131
132
|
};
|
|
132
133
|
export type FetchFilesPromise = Map<string, Promise<ReadonlyMap<string, Buffer>>>;
|
|
133
134
|
export { IConfiguration };
|
|
134
|
-
export interface IInitializeOptions {
|
|
135
|
-
useCacheRepository?: boolean;
|
|
136
|
-
}
|
|
@@ -9,7 +9,7 @@ export default class AbapRepository implements IRepository {
|
|
|
9
9
|
constructor(configuration: IConfiguration, abapProvider?: AbapProvider);
|
|
10
10
|
getAppVariantIdHierarchy(id: string): Promise<IAbapResource[]>;
|
|
11
11
|
getAnnotationMetadata(uri: string): Promise<IMetadata>;
|
|
12
|
-
downloadAnnotationFile(uri: string): Promise<
|
|
12
|
+
downloadAnnotationFile(uri: string): Promise<any>;
|
|
13
13
|
getMetadata(id: string): Promise<IMetadata>;
|
|
14
14
|
fetch(resource: IAbapResource): Promise<Map<string, Buffer>>;
|
|
15
15
|
}
|
|
@@ -37,14 +37,14 @@ export default class AbapRepository {
|
|
|
37
37
|
const hierarchy = JSON.parse(response.data)?.appVariantIdHierarchy;
|
|
38
38
|
return hierarchy.map(item => ({
|
|
39
39
|
appName: item.repoName,
|
|
40
|
-
|
|
40
|
+
token: Promise.resolve(item.cachebusterToken)
|
|
41
41
|
}));
|
|
42
42
|
}
|
|
43
43
|
else if (this.configuration.appName) {
|
|
44
44
|
// Fallback to old API on old ABAP backend or CF for backward compatibility
|
|
45
45
|
return [{
|
|
46
46
|
appName: this.configuration.appName,
|
|
47
|
-
|
|
47
|
+
token: this.getMetadata(id).then(metadata => metadata.changedOn),
|
|
48
48
|
}];
|
|
49
49
|
}
|
|
50
50
|
throw new Error(`App variant id hierarchy for app id '${id}' is not provided`);
|
|
@@ -59,7 +59,7 @@ export default class AbapRepository {
|
|
|
59
59
|
const response = await provider.get(uri, {
|
|
60
60
|
headers: REQUEST_OPTIONS_XML.headers
|
|
61
61
|
});
|
|
62
|
-
return
|
|
62
|
+
return response.data;
|
|
63
63
|
}
|
|
64
64
|
async getMetadata(id) {
|
|
65
65
|
const provider = await this.abapProvider.get(this.configuration);
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import ICachedResource from "../cache/cachedResource.js";
|
|
2
|
-
import { IConfiguration } from "../model/types.js";
|
|
3
2
|
import IRepository from "./repository.js";
|
|
4
3
|
export default class CacheRepository implements IRepository {
|
|
5
|
-
private
|
|
6
|
-
constructor(
|
|
7
|
-
getAppVariantIdHierarchy(
|
|
4
|
+
private repository;
|
|
5
|
+
constructor(repository: IRepository);
|
|
6
|
+
getAppVariantIdHierarchy(appId: string): Promise<ICachedResource[]>;
|
|
8
7
|
fetch(resource: ICachedResource): Promise<Map<string, Buffer>>;
|
|
9
|
-
downloadAnnotationFile(uri: string): Promise<
|
|
8
|
+
downloadAnnotationFile(uri: string): Promise<string>;
|
|
10
9
|
}
|
|
@@ -1,29 +1,21 @@
|
|
|
1
1
|
import CacheHolder from "../cache/cacheHolder.js";
|
|
2
2
|
export default class CacheRepository {
|
|
3
|
-
|
|
4
|
-
constructor(
|
|
5
|
-
this.
|
|
3
|
+
repository;
|
|
4
|
+
constructor(repository) {
|
|
5
|
+
this.repository = repository;
|
|
6
6
|
}
|
|
7
|
-
async getAppVariantIdHierarchy(
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
10
|
-
|
|
7
|
+
async getAppVariantIdHierarchy(appId) {
|
|
8
|
+
const mergedResource = CacheHolder.mergedResource(appId);
|
|
9
|
+
if (await CacheHolder.hasDirectory(mergedResource)) {
|
|
10
|
+
return [mergedResource];
|
|
11
11
|
}
|
|
12
|
-
return
|
|
13
|
-
appName,
|
|
14
|
-
cacheBusterToken: Promise.resolve("")
|
|
15
|
-
}];
|
|
12
|
+
return this.repository.getAppVariantIdHierarchy(appId);
|
|
16
13
|
}
|
|
17
14
|
async fetch(resource) {
|
|
18
|
-
|
|
19
|
-
const cachedFiles = await CacheHolder.readLatest(appName);
|
|
20
|
-
if (cachedFiles.size === 0) {
|
|
21
|
-
throw new Error(`No cached base app found for '${appName}'. Please check the appName or run a full build first to populate the cache.`);
|
|
22
|
-
}
|
|
23
|
-
return cachedFiles;
|
|
15
|
+
return this.repository.fetch(resource);
|
|
24
16
|
}
|
|
25
17
|
downloadAnnotationFile(uri) {
|
|
26
|
-
|
|
18
|
+
return this.repository.downloadAnnotationFile(uri);
|
|
27
19
|
}
|
|
28
20
|
}
|
|
29
21
|
//# sourceMappingURL=cacheRepository.js.map
|
|
@@ -18,5 +18,5 @@ export default class HTML5Repository implements IRepository {
|
|
|
18
18
|
private requestMetadata;
|
|
19
19
|
private getAppZipEntries;
|
|
20
20
|
private download;
|
|
21
|
-
downloadAnnotationFile(_uri: string): Promise<
|
|
21
|
+
downloadAnnotationFile(_uri: string): Promise<string>;
|
|
22
22
|
}
|
|
@@ -25,7 +25,7 @@ export default class HTML5Repository {
|
|
|
25
25
|
}
|
|
26
26
|
return [{
|
|
27
27
|
appName,
|
|
28
|
-
|
|
28
|
+
token: this.getMetadata().then(metadata => metadata.changedOn),
|
|
29
29
|
appVersion,
|
|
30
30
|
appHostId,
|
|
31
31
|
}];
|
|
@@ -118,7 +118,7 @@ export default class HTML5Repository {
|
|
|
118
118
|
}
|
|
119
119
|
downloadAnnotationFile(_uri) {
|
|
120
120
|
log.verbose("No annotation processing in CF");
|
|
121
|
-
return Promise.resolve(
|
|
121
|
+
return Promise.resolve("");
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
__decorate([
|
|
@@ -4,7 +4,7 @@ export interface ILocalResource extends ICachedResource {
|
|
|
4
4
|
absolutePath: string;
|
|
5
5
|
}
|
|
6
6
|
export default class LocalRepository implements IRepository {
|
|
7
|
-
downloadAnnotationFile(_uri: string): Promise<
|
|
7
|
+
downloadAnnotationFile(_uri: string): Promise<string>;
|
|
8
8
|
getAppVariantIdHierarchy(appId: string): Promise<ILocalResource[]>;
|
|
9
9
|
fetch(resource: ILocalResource): Promise<Map<string, Buffer>>;
|
|
10
10
|
private buildManifestIndex;
|
|
@@ -7,7 +7,7 @@ const log = getLogger("@ui5/task-adaptation::LocalRepository");
|
|
|
7
7
|
export default class LocalRepository {
|
|
8
8
|
async downloadAnnotationFile(_uri) {
|
|
9
9
|
log.verbose("Downloading annotation files is not supported in LocalRepository.");
|
|
10
|
-
return
|
|
10
|
+
return "";
|
|
11
11
|
}
|
|
12
12
|
async getAppVariantIdHierarchy(appId) {
|
|
13
13
|
const items = [];
|
|
@@ -26,7 +26,7 @@ export default class LocalRepository {
|
|
|
26
26
|
}
|
|
27
27
|
items.push({
|
|
28
28
|
appName: currentAppId,
|
|
29
|
-
|
|
29
|
+
token: Promise.resolve("local"),
|
|
30
30
|
absolutePath: entry.absolutePath,
|
|
31
31
|
});
|
|
32
32
|
if (entry.isVariant) {
|
|
@@ -2,5 +2,5 @@ import ICachedResource from "../cache/cachedResource.js";
|
|
|
2
2
|
export default interface IRepository {
|
|
3
3
|
getAppVariantIdHierarchy(appId: string): Promise<ICachedResource[]>;
|
|
4
4
|
fetch(resource: ICachedResource): Promise<Map<string, Buffer>>;
|
|
5
|
-
downloadAnnotationFile(uri: string): Promise<
|
|
5
|
+
downloadAnnotationFile(uri: string): Promise<string>;
|
|
6
6
|
}
|
package/dist/util/cfUtil.d.ts
CHANGED
|
@@ -10,10 +10,9 @@ export default class CFUtil {
|
|
|
10
10
|
*/
|
|
11
11
|
static getServiceInstanceKeys(getServiceInstanceParams: IGetServiceInstanceParams, createServiceInstanceParams?: ICreateServiceInstanceParams): Promise<IServiceKeys>;
|
|
12
12
|
static createService(params: ICreateServiceInstanceParams): Promise<void>;
|
|
13
|
-
private static
|
|
14
|
-
private static
|
|
13
|
+
private static getOrCreateCredentials;
|
|
14
|
+
private static fetchCredentials;
|
|
15
15
|
private static createServiceKey;
|
|
16
|
-
private static deleteServiceKeyUnsafe;
|
|
17
16
|
private static getServiceInstance;
|
|
18
17
|
static processCfErrors(errors?: ICfError[]): void;
|
|
19
18
|
static requestCfApi(url: string): Promise<IResource[]>;
|
|
@@ -22,14 +21,15 @@ export default class CFUtil {
|
|
|
22
21
|
private static errorsToString;
|
|
23
22
|
private static parseJson;
|
|
24
23
|
/**
|
|
25
|
-
*
|
|
24
|
+
* Return the most recently created service credential binding (key) for the given service instance,
|
|
25
|
+
* or undefined if no keys exist.
|
|
26
26
|
* @private
|
|
27
27
|
* @static
|
|
28
28
|
* @param {string} serviceInstanceGuid the service instance guid
|
|
29
|
-
* @return {Promise<
|
|
29
|
+
* @return {Promise<any | undefined>} the newest binding object ({ name, guid, created_at, … }) or undefined
|
|
30
30
|
* @memberof CFUtil
|
|
31
31
|
*/
|
|
32
|
-
private static
|
|
32
|
+
private static getNewestServiceKey;
|
|
33
33
|
/**
|
|
34
34
|
* Get service keys for a service instance by name. If the existing service key
|
|
35
35
|
* has endpoints as strings instead of objects, a new service key will be created.
|
|
@@ -49,24 +49,6 @@ export default class CFUtil {
|
|
|
49
49
|
* @memberof CFUtil
|
|
50
50
|
*/
|
|
51
51
|
private static hasValidEndpoints;
|
|
52
|
-
/**
|
|
53
|
-
* Get all service key names for a service instance
|
|
54
|
-
* @private
|
|
55
|
-
* @static
|
|
56
|
-
* @param {string} serviceInstanceGuid the service instance guid
|
|
57
|
-
* @return {Promise<string[]>} promise with array of service key names
|
|
58
|
-
* @memberof CFUtil
|
|
59
|
-
*/
|
|
60
|
-
private static getAllServiceKeyNames;
|
|
61
|
-
/**
|
|
62
|
-
* Generate a unique service key name in format serviceInstanceName-key-N
|
|
63
|
-
* @static
|
|
64
|
-
* @param {string} serviceInstanceName the service instance name
|
|
65
|
-
* @param {string} serviceInstanceGuid the service instance guid
|
|
66
|
-
* @return {Promise<string>} promise with unique service key name
|
|
67
|
-
* @memberof CFUtil
|
|
68
|
-
*/
|
|
69
|
-
static generateUniqueServiceKeyName(serviceInstanceName: string, serviceInstanceGuid: string): Promise<string>;
|
|
70
52
|
/**
|
|
71
53
|
* Get space guid from configuration or local CF fodler
|
|
72
54
|
* @static
|
package/dist/util/cfUtil.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { cfCreateService
|
|
1
|
+
import { cfCreateService } from "@sap/cf-tools/out/src/cf-local.js";
|
|
2
2
|
import { getSpaceGuidThrowIfUndefined } from "@sap/cf-tools/out/src/utils.js";
|
|
3
3
|
import { Cli } from "@sap/cf-tools/out/src/cli.js";
|
|
4
|
-
import { eFilters } from "@sap/cf-tools/out/src/types.js";
|
|
5
4
|
import { getLogger } from "@ui5/logger";
|
|
6
5
|
import AuthenticationError from "../model/authenticationError.js";
|
|
7
6
|
const log = getLogger("@ui5/task-adaptation::CFUtil");
|
|
@@ -25,12 +24,12 @@ export default class CFUtil {
|
|
|
25
24
|
}
|
|
26
25
|
// we can use any instance in the list to connect to HTML5 Repo
|
|
27
26
|
log.verbose(`Use '${serviceInstances[0].name}' HTML5 Repo Runtime service instance`);
|
|
28
|
-
const
|
|
29
|
-
if (!
|
|
27
|
+
const credentials = await this.getOrCreateCredentials(serviceInstances[0]);
|
|
28
|
+
if (!credentials) {
|
|
30
29
|
throw new Error(`Cannot get service keys for '${getServiceInstanceParams.names?.join(", ")}' service in current space: ${getServiceInstanceParams.spaceGuids?.join(", ")}`);
|
|
31
30
|
}
|
|
32
31
|
return {
|
|
33
|
-
credentials
|
|
32
|
+
credentials,
|
|
34
33
|
serviceInstance: serviceInstances[0]
|
|
35
34
|
};
|
|
36
35
|
}
|
|
@@ -52,27 +51,28 @@ export default class CFUtil {
|
|
|
52
51
|
throw new Error(`Cannot create a service instance '${params.serviceInstanceName}' in space '${params.spaceGuid}': ${error.message}`);
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
|
-
static async
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
static async getOrCreateCredentials(serviceInstance) {
|
|
55
|
+
if (serviceInstance.type === "user-provided") {
|
|
56
|
+
log.verbose(`Service instance '${serviceInstance.name}' is user-provided, fetching credentials directly`);
|
|
57
|
+
return this.fetchCredentials(`/v3/service_instances/${serviceInstance.guid}/credentials`);
|
|
58
|
+
}
|
|
59
|
+
let key = await this.getNewestServiceKey(serviceInstance.guid);
|
|
60
|
+
if (key == null) {
|
|
58
61
|
const serviceKeyName = serviceInstance.name + "_key";
|
|
59
62
|
log.info(`Creating service key '${serviceKeyName}' for service instance '${serviceInstance.name}'`);
|
|
60
63
|
await this.createServiceKey(serviceInstance.name, serviceKeyName);
|
|
64
|
+
key = await this.getNewestServiceKey(serviceInstance.guid);
|
|
65
|
+
if (key == null) {
|
|
66
|
+
throw new Error(`Service key was created for '${serviceInstance.name}' but could not be retrieved`);
|
|
67
|
+
}
|
|
61
68
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return this.getServiceKeys(serviceInstance.guid);
|
|
69
|
+
log.verbose(`Using service key '${key.name}' for service instance '${serviceInstance.name}'`);
|
|
70
|
+
return this.fetchCredentials(`/v3/service_credential_bindings/${key.guid}/details`);
|
|
66
71
|
}
|
|
67
|
-
static
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
key: eFilters.service_instance_guids
|
|
72
|
-
}]
|
|
73
|
-
}).catch((error) => {
|
|
74
|
-
throw new Error("Failed to get service credentials: " + error.message);
|
|
75
|
-
});
|
|
72
|
+
static async fetchCredentials(url) {
|
|
73
|
+
const parsed = this.parseJson(await this.cfExecute(["curl", url]));
|
|
74
|
+
this.processCfErrors(parsed?.errors);
|
|
75
|
+
return parsed.credentials;
|
|
76
76
|
}
|
|
77
77
|
static async createServiceKey(serviceInstanceName, serviceKeyName) {
|
|
78
78
|
try {
|
|
@@ -82,12 +82,6 @@ export default class CFUtil {
|
|
|
82
82
|
throw new Error(`Couldn't create a service key for instance: ${serviceInstanceName}: ${error}`);
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
|
-
static deleteServiceKeyUnsafe(serviceInstanceName, serviceKeyName) {
|
|
86
|
-
// Fire and forget - async delete without waiting for result or handling errors
|
|
87
|
-
this.cfExecute(["delete-service-key", serviceInstanceName, serviceKeyName, "-f"]).catch(() => {
|
|
88
|
-
// Ignore any errors - this is intentionally unsafe
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
85
|
static async getServiceInstance(params) {
|
|
92
86
|
const PARAM_MAP = {
|
|
93
87
|
spaceGuids: "space_guids",
|
|
@@ -101,7 +95,8 @@ export default class CFUtil {
|
|
|
101
95
|
const resources = await this.requestCfApi(uri);
|
|
102
96
|
return resources.map((service) => ({
|
|
103
97
|
name: service.name,
|
|
104
|
-
guid: service.guid
|
|
98
|
+
guid: service.guid,
|
|
99
|
+
type: service.type
|
|
105
100
|
}));
|
|
106
101
|
}
|
|
107
102
|
static processCfErrors(errors) {
|
|
@@ -174,18 +169,21 @@ export default class CFUtil {
|
|
|
174
169
|
}
|
|
175
170
|
}
|
|
176
171
|
/**
|
|
177
|
-
*
|
|
172
|
+
* Return the most recently created service credential binding (key) for the given service instance,
|
|
173
|
+
* or undefined if no keys exist.
|
|
178
174
|
* @private
|
|
179
175
|
* @static
|
|
180
176
|
* @param {string} serviceInstanceGuid the service instance guid
|
|
181
|
-
* @return {Promise<
|
|
177
|
+
* @return {Promise<any | undefined>} the newest binding object ({ name, guid, created_at, … }) or undefined
|
|
182
178
|
* @memberof CFUtil
|
|
183
179
|
*/
|
|
184
|
-
static async
|
|
180
|
+
static async getNewestServiceKey(serviceInstanceGuid) {
|
|
185
181
|
try {
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
182
|
+
const keyList = await this.requestCfApi(`/v3/service_credential_bindings?type=key&service_instance_guids=${serviceInstanceGuid}`);
|
|
183
|
+
if (!keyList?.length) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
return keyList.toSorted((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime())[0];
|
|
189
187
|
}
|
|
190
188
|
catch (error) {
|
|
191
189
|
throw new Error("Failed to get service credentials: " + error.message);
|
|
@@ -212,30 +210,11 @@ export default class CFUtil {
|
|
|
212
210
|
}
|
|
213
211
|
const serviceInstance = serviceInstances[0];
|
|
214
212
|
log.verbose(`Found service instance '${serviceInstance.name}' with guid: ${serviceInstance.guid}`);
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
// object with url and destination instead of a single url string
|
|
219
|
-
const validKey = await this.getServiceKeyWithValidEndpoints(serviceInstance.guid);
|
|
220
|
-
if (validKey) {
|
|
221
|
-
log.verbose(`Using existing service key with valid endpoints structure`);
|
|
222
|
-
return validKey.credentials;
|
|
223
|
-
}
|
|
224
|
-
const uniqueServiceKeyName = await uniqueServiceKeyNamePromise;
|
|
225
|
-
log.verbose(`No valid service key found with proper endpoints structure. Creating new service key '${uniqueServiceKeyName}' for '${serviceInstance.name}'`);
|
|
226
|
-
await this.createServiceKey(serviceInstance.name, uniqueServiceKeyName);
|
|
227
|
-
// Get the newly created service key and validate its endpoints
|
|
228
|
-
const newValidKey = await this.getServiceKeyWithValidEndpoints(serviceInstance.guid);
|
|
229
|
-
if (newValidKey) {
|
|
230
|
-
log.verbose(`Using newly created service key with valid endpoints structure`);
|
|
231
|
-
return newValidKey.credentials;
|
|
213
|
+
const credentials = await this.getOrCreateCredentials(serviceInstance);
|
|
214
|
+
if (!credentials?.endpoints || !this.hasValidEndpoints(credentials.endpoints)) {
|
|
215
|
+
log.info(`Service key for '${serviceInstance.name}' does not have endpoints with service urls for xs-app.json update`);
|
|
232
216
|
}
|
|
233
|
-
|
|
234
|
-
// endpoints. We don't throw an error here even if no valid endpoints
|
|
235
|
-
// found. We assume that there might be no coincidence between
|
|
236
|
-
// credential endpoints and xs-app.json destinations.
|
|
237
|
-
this.deleteServiceKeyUnsafe(serviceInstance.name, uniqueServiceKeyName);
|
|
238
|
-
log.verbose(`Created service key '${uniqueServiceKeyName}' does not have valid endpoints structure. Triggered deletion of invalid service key '${uniqueServiceKeyName}'`);
|
|
217
|
+
return credentials;
|
|
239
218
|
}
|
|
240
219
|
/**
|
|
241
220
|
* Check if endpoints object has at least one property that is an object
|
|
@@ -252,42 +231,6 @@ export default class CFUtil {
|
|
|
252
231
|
// Check if at least one property of endpoints is an object
|
|
253
232
|
return Object.values(endpoints).some(value => value && typeof value === 'object' && !Array.isArray(value));
|
|
254
233
|
}
|
|
255
|
-
/**
|
|
256
|
-
* Get all service key names for a service instance
|
|
257
|
-
* @private
|
|
258
|
-
* @static
|
|
259
|
-
* @param {string} serviceInstanceGuid the service instance guid
|
|
260
|
-
* @return {Promise<string[]>} promise with array of service key names
|
|
261
|
-
* @memberof CFUtil
|
|
262
|
-
*/
|
|
263
|
-
static async getAllServiceKeyNames(serviceInstanceGuid) {
|
|
264
|
-
try {
|
|
265
|
-
const serviceKeys = await this.requestCfApi(`/v3/service_credential_bindings?type=key&service_instance_guids=${serviceInstanceGuid}`);
|
|
266
|
-
return serviceKeys.map((key) => key.name);
|
|
267
|
-
}
|
|
268
|
-
catch (error) {
|
|
269
|
-
throw new Error(`Failed to get service key names: ${error.message}`);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Generate a unique service key name in format serviceInstanceName-key-N
|
|
274
|
-
* @static
|
|
275
|
-
* @param {string} serviceInstanceName the service instance name
|
|
276
|
-
* @param {string} serviceInstanceGuid the service instance guid
|
|
277
|
-
* @return {Promise<string>} promise with unique service key name
|
|
278
|
-
* @memberof CFUtil
|
|
279
|
-
*/
|
|
280
|
-
static async generateUniqueServiceKeyName(serviceInstanceName, serviceInstanceGuid) {
|
|
281
|
-
const existingKeyNames = await this.getAllServiceKeyNames(serviceInstanceGuid);
|
|
282
|
-
let counter = 0;
|
|
283
|
-
let keyName;
|
|
284
|
-
do {
|
|
285
|
-
keyName = `${serviceInstanceName}-key-${counter}`;
|
|
286
|
-
counter++;
|
|
287
|
-
} while (existingKeyNames.includes(keyName));
|
|
288
|
-
log.verbose(`Generated unique service key name: ${keyName}`);
|
|
289
|
-
return keyName;
|
|
290
|
-
}
|
|
291
234
|
/**
|
|
292
235
|
* Get space guid from configuration or local CF fodler
|
|
293
236
|
* @static
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import Language from "../model/language.js";
|
|
3
|
-
import AppVariant from "../appVariant.js";
|
|
1
|
+
export declare function retryOnError(maxRetries: number): MethodDecorator;
|
|
4
2
|
export declare function dotToUnderscore(value: string): string;
|
|
5
3
|
export declare function bufferToString(buffer: Buffer): string;
|
|
6
4
|
export declare function bufferToJson(buffer: Buffer): any;
|
|
@@ -11,15 +9,9 @@ export declare function validateConfiguration<T extends object>(options: T, prop
|
|
|
11
9
|
export declare function validateObject<T extends object>(options: T, properties: Array<keyof T>, message: string): void;
|
|
12
10
|
export declare function escapeRegex(update: string): string;
|
|
13
11
|
export declare function insertInArray<T>(array: T[], index: number, insert: T): void;
|
|
14
|
-
export declare function writeTempAnnotations({ writeTempFiles }: IConfiguration, name: string, language: Language, content: string): void;
|
|
15
12
|
export declare function trimExtension(filePath: string): string;
|
|
16
13
|
export declare function traverse(json: any, paths: string[], callback: (json: any, key: string | number, paths: string[]) => void): void;
|
|
17
14
|
export declare function logBuilderVersion(): void;
|
|
18
15
|
export declare function logBetaUsage(): void;
|
|
19
16
|
export declare function getUniqueName(existingNames: string[], template: string): string;
|
|
20
17
|
export declare function isManifestChange(filename: string, content: Buffer): boolean;
|
|
21
|
-
/**
|
|
22
|
-
* 4p. Reference map contains searchTerm as key and replacement as value. Base
|
|
23
|
-
* id and app variant ids are renamed to adaptation project id.
|
|
24
|
-
*/
|
|
25
|
-
export declare function getReferences(appVariants: AppVariant[], adaptationProjectId: string): Map<string, string>;
|