Skip to content

Commit a257200

Browse files
committed
Merge branch 'main' into electron-prompt
2 parents ef07704 + 8ecc7f3 commit a257200

33 files changed

+178
-408
lines changed

electron/app/js/credentialManager.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright (c) 2021, Oracle and/or its affiliates.
44
* Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
55
*/
6-
// const CredentialStore = require('./credentialStore');
76
const CredentialEncryptor = require('./credentialEncryptor');
87
const { getJsonPathReference } = require('./jsonPath');
98
const { getLogger } = require('./wktLogging');

electron/app/js/helmUtils.js

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,14 @@ async function validateHelmExe(helmExe) {
4848
}
4949

5050
async function addOrUpdateWkoHelmChart(helmExe, helmOptions) {
51-
const args = [ 'repo', 'add', _wkoHelmChartRepoName, _wkoHelmChartUrl, '--force-update' ];
52-
const httpsProxyUrl = await getHttpsProxyUrl();
53-
const bypassProxyHosts = await getBypassProxyHosts();
54-
const env = getHelmEnv(httpsProxyUrl, bypassProxyHosts, helmOptions);
55-
const results = {
56-
isSuccess: true
57-
};
58-
59-
return new Promise(resolve => {
60-
executeFileCommand(helmExe, args, env).then(() => resolve(results)).catch(err => {
61-
results.isSuccess = false;
62-
results.reason = i18n.t('helm-repo-add-failed-error-message',
63-
{ helmRepo: _wkoHelmChartRepoName, error: getErrorMessage(err) });
64-
getLogger().error(results.reason);
65-
getLogger().error(err);
66-
resolve(results);
67-
});
68-
});
51+
return addOrUpdateHelmChart(helmExe, _wkoHelmChartRepoName, _wkoHelmChartUrl, helmOptions);
6952
}
7053

71-
async function addOrUpdateHelmChart(helmExe, repoName, repoUrl) {
54+
async function addOrUpdateHelmChart(helmExe, repoName, repoUrl, helmOptions) {
7255
const args = [ 'repo', 'add', repoName, repoUrl, '--force-update' ];
7356
const httpsProxyUrl = await getHttpsProxyUrl();
7457
const bypassProxyHosts = await getBypassProxyHosts();
75-
const env = getHelmEnv(httpsProxyUrl, bypassProxyHosts);
58+
const env = getHelmEnv(httpsProxyUrl, bypassProxyHosts, helmOptions);
7659
const results = {
7760
isSuccess: true
7861
};
@@ -81,7 +64,7 @@ async function addOrUpdateHelmChart(helmExe, repoName, repoUrl) {
8164
executeFileCommand(helmExe, args, env).then(() => resolve(results)).catch(err => {
8265
results.isSuccess = false;
8366
results.reason = i18n.t('helm-repo-add-failed-error-message',
84-
{ helmRepo: _wkoHelmChartRepoName, error: getErrorMessage(err) });
67+
{ helmRepo: repoName, error: getErrorMessage(err) });
8568
getLogger().error(results.reason);
8669
getLogger().error(err);
8770
resolve(results);
@@ -140,14 +123,13 @@ async function upgradeWko(helmExe, name, namespace, helmChartValues, helmOptions
140123
return _runHelmWko(helmExe, name, namespace, args, helmOptions, 'helm-upgrade-wko-failed-error-message');
141124
}
142125

143-
async function helmListAllNamespaces(helmExe, helmChartValues, helmOptions) {
126+
async function helmListAllNamespaces(helmExe, helmOptions) {
144127
const args = [ 'list', '--all-namespaces' ];
145-
processHelmChartValues(args, helmChartValues);
146128
processHelmOptions(args, helmOptions);
147129
args.push('-o');
148130
args.push('json');
149131

150-
return _runHelmWko2(helmExe, '', '', args, helmOptions, 'helm-list-failed-error-message');
132+
return _runHelmCommand(helmExe, args, helmOptions, 'helm-list-failed-error-message');
151133
}
152134

153135
async function _runHelmWko(helmExe, name, namespace, args, helmOptions, errorKey) {
@@ -170,7 +152,7 @@ async function _runHelmWko(helmExe, name, namespace, args, helmOptions, errorKey
170152
});
171153
}
172154

173-
async function _runHelmWko2(helmExe, name, namespace, args, helmOptions, errorKey) {
155+
async function _runHelmCommand(helmExe, args, helmOptions, errorKey) {
174156
const httpsProxyUrl = await getHttpsProxyUrl();
175157
const bypassProxyHosts = await getBypassProxyHosts();
176158
const env = getHelmEnv(httpsProxyUrl, bypassProxyHosts, helmOptions);
@@ -181,10 +163,11 @@ async function _runHelmWko2(helmExe, name, namespace, args, helmOptions, errorKe
181163
return new Promise(resolve => {
182164
executeFileCommand(helmExe, args, env).then(stdout => {
183165
getLogger().debug(stdout);
184-
resolve(stdout);
166+
results.stdout = stdout;
167+
resolve(results);
185168
}).catch(err => {
186169
results.isSuccess = false;
187-
results.reason = i18n.t(errorKey, { name: name, helmChart: _wkoHelmChartName, namespace: namespace, error: getErrorMessage(err) });
170+
results.reason = i18n.t(errorKey, { error: getErrorMessage(err) });
188171
resolve(results);
189172
});
190173
});

electron/app/js/modelArchive.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ async function saveContentsOfArchiveFiles(projectDirectory, archiveUpdates) {
8888
}
8989
const archiveFiles = Object.getOwnPropertyNames(archiveUpdates);
9090
const archiveContents = await getContentsOfArchiveFiles(projectDirectory, archiveFiles);
91-
// getLogger().debug('saveContentsOfArchiveFiles() returning %s', JSON.stringify(archiveContents, null, 2));
9291
return Promise.resolve(archiveContents);
9392
}
9493

@@ -224,33 +223,33 @@ async function _openArchiveFile(archiveFile) {
224223
}
225224

226225
async function _performAddOperation(archiveFile, zip, operation) {
227-
const path = operation.path;
226+
const opPath = operation.path;
228227
const filePath = operation.filePath ? operation.filePath : undefined;
229228

230-
if (path.endsWith('/')) {
229+
if (opPath.endsWith('/')) {
231230
if (filePath) {
232231
return new Promise((resolve, reject) => {
233-
_validateFilePathForArchivePath(archiveFile, path, filePath).then(() => {
234-
_addDirectoryToArchiveFile(archiveFile, zip, path, filePath).then(() => resolve()).catch(err => reject(err));
232+
_validateFilePathForArchivePath(archiveFile, opPath, filePath).then(() => {
233+
_addDirectoryToArchiveFile(archiveFile, zip, opPath, filePath).then(() => resolve()).catch(err => reject(err));
235234
}).catch(err => reject(err));
236235
});
237236
} else {
238237
return new Promise((resolve, reject) => {
239-
_addEmptyDirectoryToArchive(archiveFile, zip, path).then(() => resolve()).catch(err => reject(err));
238+
_addEmptyDirectoryToArchive(archiveFile, zip, opPath).then(() => resolve()).catch(err => reject(err));
240239
});
241240
}
242241
} else {
243242
if (filePath) {
244243
return new Promise((resolve, reject) => {
245-
_validateFilePathForArchivePath(archiveFile, path, filePath).then(() => {
246-
_addFileToArchive(archiveFile, zip, path, filePath).then(() => {
244+
_validateFilePathForArchivePath(archiveFile, opPath, filePath).then(() => {
245+
_addFileToArchive(archiveFile, zip, opPath, filePath).then(() => {
247246
resolve();
248247
}).catch(err => reject(err));
249248
}).catch(err => reject(err));
250249
});
251250
} else {
252251
const errMessage = i18n.t('model-archive-add-file-path-empty-error-message',
253-
{ archiveFile: archiveFile, path: path });
252+
{ archiveFile: archiveFile, path: opPath });
254253
return Promise.reject(new Error(errMessage));
255254
}
256255
}
@@ -308,31 +307,31 @@ async function _saveArchiveFile(zip, archiveFile) {
308307
});
309308
}
310309

311-
async function _addFileToArchive(archiveFile, zip, path, filePath) {
310+
async function _addFileToArchive(archiveFile, zip, zipPath, filePath) {
312311
return new Promise((resolve, reject) => {
313312
fsPromises.readFile(filePath).then(buffer => {
314313
try {
315-
zip.file(path, buffer, { createFolders: false });
314+
zip.file(zipPath, buffer, { createFolders: false });
316315
resolve();
317316
} catch (err) {
318317
reject(err);
319318
}
320319
}).catch(err => {
321320
const errMessage = i18n.t('model-archive-add-file-read-failed-error-message',
322-
{archiveFile: archiveFile, path: path, filePath: filePath, error: getErrorMessage(err) });
321+
{archiveFile: archiveFile, path: zipPath, filePath: filePath, error: getErrorMessage(err) });
323322
reject(new Error(errMessage));
324323
});
325324
});
326325
}
327326

328-
async function _addEmptyDirectoryToArchive(archiveFile, zip, path) {
327+
async function _addEmptyDirectoryToArchive(archiveFile, zip, zipPath) {
329328
return new Promise((resolve, reject) => {
330329
try {
331-
zip.folder(path);
330+
zip.folder(zipPath);
332331
resolve();
333332
} catch (err) {
334333
const errMessage = i18n.t('model-archive-add-folder-failed-error-message',
335-
{archiveFile: archiveFile, path: path, error: getErrorMessage(err) });
334+
{archiveFile: archiveFile, path: zipPath, error: getErrorMessage(err) });
336335
reject(new Error(errMessage));
337336
}
338337
});
@@ -381,17 +380,17 @@ function getCollapsedOperations(userOperations) {
381380
}
382381

383382
const operations = [];
384-
for (const [ path, operation ] of pathOperationMap.entries()) {
385-
operations.push(...getOperationsForPath(path, operation));
383+
for (const [ zipPath, operation ] of pathOperationMap.entries()) {
384+
operations.push(...getOperationsForPath(zipPath, operation));
386385
}
387386
return operations;
388387
}
389388

390-
function getOperationsForPath(path, operation) {
389+
function getOperationsForPath(zipPath, operation) {
391390
const results = [ operation ];
392-
if (operation.op === 'add' && path.endsWith('/')) {
391+
if (operation.op === 'add' && zipPath.endsWith('/')) {
393392
// Insert this operation ahead of the add operation.
394-
results.unshift({ op: 'remove', path: path });
393+
results.unshift({ op: 'remove', path: zipPath });
395394
}
396395
return results;
397396
}

electron/app/js/project.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ async function checkAddModelFile(targetWindow, filePath) {
587587
// copy
588588
const wktWindow = require('./wktWindow');
589589
const modelsPath = _getDefaultModelsPath(targetWindow);
590-
const projectDir = _getProjectDirectory(targetWindow);
591590
const targetDir = path.join(projectDir, modelsPath);
592591
try {
593592
await mkdir(targetDir, {recursive: true});

electron/app/js/wdtArchive.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function getEntryTypes() {
9696
async function chooseArchiveEntry(targetWindow, entryType) {
9797
const typeDetail = getEntryTypes()[entryType];
9898
if(!typeDetail) {
99-
throw('Unknown archive entry type: ' + entryType);
99+
throw new Error(`Unknown archive entry type: ${entryType}`);
100100
}
101101

102102
// the full file system path, ex. /home/me/abc.jar
@@ -127,7 +127,7 @@ async function chooseArchiveEntry(targetWindow, entryType) {
127127
break;
128128
default:
129129
// note: emptyDir subtype is currently handled on client side
130-
throw('Unrecognized archive entry subtype: ' + subtype);
130+
throw new Error(`Unrecognized archive entry subtype: ${subtype}`);
131131
}
132132

133133
return {filePath: filePath, archivePath: archivePath, archiveUpdatePath: archiveUpdatePath, childPaths: childPaths};
@@ -155,7 +155,7 @@ async function chooseArchiveFileEntry(targetWindow, typeDetail) {
155155
}
156156

157157
const wktWindow = require('./wktWindow');
158-
return await wktWindow.chooseFromFileSystem(targetWindow, options);
158+
return wktWindow.chooseFromFileSystem(targetWindow, options);
159159
}
160160

161161
async function chooseArchiveDirEntry(targetWindow, typeDetail) {
@@ -172,7 +172,7 @@ async function chooseArchiveDirEntry(targetWindow, typeDetail) {
172172
};
173173

174174
const wktWindow = require('./wktWindow');
175-
return await wktWindow.chooseFromFileSystem(targetWindow, options);
175+
return wktWindow.chooseFromFileSystem(targetWindow, options);
176176
}
177177

178178
// get a list of paths for all the files and folders in the specified directory.
@@ -187,13 +187,13 @@ async function _addDirectoryPaths(directory, paths, pathPrefix) {
187187
const dirContents = await fsPromises.readdir(directory, {withFileTypes: true});
188188
for (const entry of dirContents) {
189189
let name = entry.name;
190-
let path = pathPrefix ? pathPrefix + '/' + name : name;
191-
let fullPath = entry.isDirectory() ? path + '/' : path;
190+
let entryPath = pathPrefix ? pathPrefix + '/' + name : name;
191+
let fullPath = entry.isDirectory() ? entryPath + '/' : entryPath;
192192
paths.push(fullPath);
193193

194194
if(entry.isDirectory()) {
195195
const subdirectory = directory + '/' + name;
196-
await _addDirectoryPaths(subdirectory, paths, path);
196+
await _addDirectoryPaths(subdirectory, paths, entryPath);
197197
}
198198
}
199199
}

electron/app/js/wdtPrepareModel.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const fsUtils = require('./fsUtils');
1515
const { getLogger } = require('./wktLogging');
1616
const { getPrepareModelShellScript, getWdtCustomConfigDirectory, isWdtErrorExitCode } = require('./wktTools');
1717
const { getModelFileContent } = require('./project');
18+
const errorUtils = require('./errorUtils');
1819

1920
const _secretsFileName = 'k8s_secrets.json';
2021
const _wkoDomainSpecFileName = 'wko-domain.yaml';
@@ -289,13 +290,13 @@ async function getJsonSecretsContent(outputDirectory) {
289290
resolve(formatSecretsData(jsonContent));
290291
} catch (err) {
291292
const error = new Error(i18n.t('prepare-model-secrets-file-parse-error-message',
292-
{ fileName: secretsFileName, error: err.message || err }));
293+
{ fileName: secretsFileName, error: errorUtils.getErrorMessage(err) }));
293294
error.cause = err;
294295
reject(err);
295296
}
296297
}).catch(err => {
297298
const error = new Error(i18n.t('prepare-model-secrets-file-read-error-message',
298-
{ fileName: secretsFileName, error: err.message || err }));
299+
{ fileName: secretsFileName, error: errorUtils.getErrorMessage(err) }));
299300
error.cause = err;
300301
reject(err);
301302
});
@@ -371,22 +372,17 @@ async function getWkoSpecContent(outputDirectory) {
371372
resolve(formatWkoDomainSpecData(yamlDoc));
372373
} catch (err) {
373374
const error = new Error(i18n.t('prepare-model-spec-file-parse-error-message',
374-
{ targetType: _wkoTargetTypeName, fileName: specFile, error: err.message || err }));
375+
{ targetType: _wkoTargetTypeName, fileName: specFile, error: errorUtils.getErrorMessage(err) }));
375376
error.cause = err;
376377
reject(error);
377378
}
378379
}).catch(err => {
379380
const error = new Error(i18n.t('prepare-model-spec-file-read-error-message',
380-
{ targetType: _wkoTargetTypeName, fileName: specFile, error: err.message || err }));
381+
{ targetType: _wkoTargetTypeName, fileName: specFile, error: errorUtils.getErrorMessage(err) }));
381382
error.cause = err;
382383
reject(error);
383384
});
384-
}).catch(err => {
385-
const error = new Error(i18n.t('prepare-model-spec-file-exists-error-message',
386-
{ targetType: _wkoTargetTypeName, fileName: specFile, error: err.message || err }));
387-
error.cause = err;
388-
reject(error);
389-
});
385+
}).catch(err => reject(getFileExistsErrorMessage(_wkoTargetTypeName, specFile, err)));
390386
});
391387
}
392388

@@ -429,7 +425,7 @@ async function getVzSpecContent(outputDirectory) {
429425
yamlDocs = jsYaml.loadAll(data, { filename: specFile, json: true });
430426
} catch (err) {
431427
const error = new Error(i18n.t('prepare-model-spec-file-parse-error-message',
432-
{ targetType: _vzTargetTypeName, fileName: specFile, error: err.message || err }));
428+
{ targetType: _vzTargetTypeName, fileName: specFile, error: errorUtils.getErrorMessage(err) }));
433429
error.cause = err;
434430
reject(error);
435431
}
@@ -441,19 +437,21 @@ async function getVzSpecContent(outputDirectory) {
441437
}
442438
}).catch(err => {
443439
const error = new Error(i18n.t('prepare-model-spec-file-read-error-message',
444-
{ targetType: _vzTargetTypeName, fileName: specFile, error: err.message || err }));
440+
{ targetType: _vzTargetTypeName, fileName: specFile, error: errorUtils.getErrorMessage(err) }));
445441
error.cause = err;
446442
reject(error);
447443
});
448-
}).catch(err => {
449-
const error = new Error(i18n.t('prepare-model-spec-file-exists-error-message',
450-
{ targetType: _wkoTargetTypeName, fileName: specFile, error: err.message || err }));
451-
error.cause = err;
452-
reject(error);
453-
});
444+
}).catch(err => reject(getFileExistsErrorMessage(_wkoTargetTypeName, specFile, err)));
454445
});
455446
}
456447

448+
function getFileExistsErrorMessage(targetType, fileName, err) {
449+
const error = new Error(i18n.t('prepare-model-spec-file-exists-error-message',
450+
{ targetType: targetType, fileName: fileName, error: errorUtils.getErrorMessage(err) }));
451+
error.cause = err;
452+
return error;
453+
}
454+
457455
function formatVzApplicationSpecData(specFile, yamlDocs) {
458456
const domainSpec = findVzDomainSpec(specFile, yamlDocs);
459457
const domainUID = domainSpec.domainUID;

electron/app/js/wktLogging.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class BufferedLoggerForStartup {
5959

6060
async function initializeLoggingSystem(wktMode, wktApp, tempDir) {
6161
if (_logger) {
62-
return new Promise(resolve => resolve(_logger));
62+
return Promise.resolve(_logger);
6363
} else if (_startupLogger) {
6464
return Promise.resolve(_startupLogger);
6565
}

electron/app/js/wktToolsInstaller.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,9 @@ async function installTool(ghReleaseObj, outputPath, directoryToDelete, proxyAge
242242
}).catch(err => reject(`Failed to extract ${archiveFileName}: ${err}`));
243243
} else {
244244
console.log(`preparing to open .tar.gz file ${archiveFileName} in ${outputPath}`);
245-
try {
246-
openTarGzFile(archiveFileName, outputPath)
247-
.then(() => {
248-
deleteArchiveFile(archiveFileName).then(() => resolve());
249-
}).catch(err => reject(`Failed to extract ${archiveFileName}: ${err}`));
250-
} catch (err) {
251-
console.log(err);
252-
}
245+
openTarGzFile(archiveFileName, outputPath).then(() => {
246+
deleteArchiveFile(archiveFileName).then(() => resolve());
247+
}).catch(err => reject(`Failed to extract ${archiveFileName}: ${err}`));
253248
}
254249
}).catch(err => reject(`Failed to remove ${directoryToDelete}: ${err}`));
255250
}).catch(err => reject(`Failed to download ${archiveAssetUrl} to ${archiveFileName}: ${err}`));
@@ -350,6 +345,5 @@ module.exports = {
350345
installWitRelease,
351346
getWdtLatestReleaseName,
352347
getWitLatestReleaseName,
353-
getWkoLatestReleaseImageName,
354-
openTarGzFile // TODO -remove me
348+
getWkoLatestReleaseImageName
355349
};

electron/app/locales/en/electron.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
"helm-install-ingress-failed-error-message": "Unable to install Helm release {{name}} in Kubernetes namespace {{namespace}} using Helm chart {{helmChart}}: {{error}}",
256256
"helm-install-wko-failed-error-message": "Unable to install Helm release {{name}} in Kubernetes namespace {{namespace}} using Helm chart {{helmChart}}: {{error}}",
257257
"helm-upgrade-wko-failed-error-message": "Unable to upgrade Helm release {{name}} in Kubernetes namespace {{namespace}} using Helm chart {{helmChart}}: {{error}}",
258-
"helm-list-failed-error-message": "Helm list failed {{error}}",
258+
"helm-list-failed-error-message": "Helm list --all-namespaces failed: {{error}}",
259259
"helm-write-values-file-failed-error-message": "Unable to run helm install due to an error writing the data to a temporary file: {{error}}",
260260
"helm-install-ingress-controller-failed-error-message": "Unable to install Ingress Controller {{controllerName}} in Kubernetes namespace {{namespace}}: {{error}}",
261261

0 commit comments

Comments
 (0)