Skip to content

Commit f226bc7

Browse files
authored
fix(deps): fix sonar issues (#2127)
* fix(deps): fix sonar issues fix sonar issues 2126 * fix(deps): remove sonar issues remove sonar issues 2126 * fix(deps): remove sonar issues remove sonar issues 2126
1 parent 2a2891d commit f226bc7

File tree

4 files changed

+91
-70
lines changed

4 files changed

+91
-70
lines changed

packages/cli/src/generators/cdk/index.ts

Lines changed: 69 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import fetch from 'node-fetch';
2-
import {existsSync, mkdirSync} from 'node:fs';
2+
import { existsSync, mkdirSync } from 'node:fs';
33
import {
44
appendFile,
55
readFile,
@@ -15,9 +15,9 @@ import {
1515
Project,
1616
PropertyAssignmentStructure,
1717
} from 'ts-morph';
18-
import {BaseGenerator} from '../../base-generator';
19-
import {IacList} from '../../enum';
20-
import {CdkOptions} from '../../types';
18+
import { BaseGenerator } from '../../base-generator';
19+
import { IacList } from '../../enum';
20+
import { CdkOptions } from '../../types';
2121
const chalk = require('chalk'); //NOSONAR
2222

2323
/**
@@ -131,7 +131,7 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
131131
return filesToKeep.some(reqPath => filePath.startsWith(reqPath));
132132
};
133133

134-
const {owner, repo, tag, templateDir: dir} = this.remoteConfig;
134+
const { owner, repo, tag, templateDir: dir } = this.remoteConfig;
135135
/**
136136
* When the tar file is downloaded and extracted it creates a dir structure like
137137
* ${repo}-${tag}
@@ -146,7 +146,7 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
146146

147147
try {
148148
if (!existsSync(outputDir)) {
149-
mkdirSync(outputDir, {recursive: true});
149+
mkdirSync(outputDir, { recursive: true });
150150
}
151151

152152
const response = await fetch(url);
@@ -195,51 +195,61 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
195195

196196
async setupFiles() {
197197
this.log('🛠️ Configuring files to meet your requirements...');
198+
if (this.options.applicationClassName && this.options.relativePathToApp) {
199+
let appImport = '';
198200

199-
let appImport = '';
201+
const isDefaultExport = await this._isDefaultExport(
202+
this.options.applicationClassName,
203+
this.options.relativePathToApp,
204+
);
200205

201-
const isDefaultExport = await this._isDefaultExport(
202-
this.options.applicationClassName!,
203-
this.options.relativePathToApp!,
204-
);
206+
const appImportPath = this._getAppImportPath(
207+
this.options.relativePathToApp,
208+
);
205209

206-
const appImportPath = this._getAppImportPath(
207-
this.options.relativePathToApp!,
208-
);
210+
if (!isDefaultExport) {
211+
appImport = `import {${this.options.applicationClassName}} from '${appImportPath}'`;
212+
} else {
213+
appImport = `import ${this.options.applicationClassName} from '${appImportPath}`;
214+
}
209215

210-
if (!isDefaultExport) {
211-
appImport = `import {${this.options.applicationClassName}} from '${appImportPath}'`;
216+
await this._updateFile(
217+
this.destinationPath(
218+
`${this.options.dir}/${(this[this.options.iac!] as LambdaConfig).handlerFile
219+
}`,
220+
),
221+
'{{app_class_name_placeholder}}',
222+
this.options.applicationClassName,
223+
);
224+
225+
await this._updateFile(
226+
this.destinationPath(
227+
`${this.options.dir}/${(this[this.options.iac!] as LambdaConfig).handlerFile
228+
}`,
229+
),
230+
'{{app_import_placeholder}}',
231+
appImport,
232+
);
212233
} else {
213-
appImport = `import ${this.options.applicationClassName} from '${appImportPath}`;
234+
// Handle the case where applicationClassName or relativePathToApp is undefined
235+
this.log.error("Application class name or relative path to app is undefined.");
214236
}
215237

216-
await this._updateFile(
217-
this.destinationPath(
218-
`${this.options.dir}/${
219-
(this[this.options.iac!] as LambdaConfig).handlerFile
220-
}`,
221-
),
222-
'{{app_class_name_placeholder}}',
223-
this.options.applicationClassName!,
224-
);
225238

226-
await this._updateFile(
227-
this.destinationPath(
228-
`${this.options.dir}/${
229-
(this[this.options.iac!] as LambdaConfig).handlerFile
230-
}`,
231-
),
232-
'{{app_import_placeholder}}',
233-
appImport,
234-
);
235239
}
236240

237241
async updatePackageJsonName() {
238-
await this._updateFile(
239-
this.destinationPath(`${this.options.dir}/package.json`),
240-
'{{package_json_name_placeholder}}',
241-
this.options.packageJsonName!,
242-
);
242+
if (this.options.packageJsonName) {
243+
await this._updateFile(
244+
this.destinationPath(`${this.options.dir}/package.json`),
245+
'{{package_json_name_placeholder}}',
246+
this.options.packageJsonName,
247+
);
248+
} else {
249+
// Handle the case where applicationClassName or relativePathToApp is undefined
250+
this.log.error("packageJsonName is undefined.");
251+
}
252+
243253
}
244254

245255
async configureEnvs() {
@@ -248,19 +258,17 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
248258
const keysToCreate = await this._getEnvKeys(envFile);
249259
await this._appendEmptyKeysToEnv(
250260
this.destinationPath(
251-
`${this.options.dir}/${
252-
(this[this.options.iac!] as IacConfig).envSchemaFile
261+
`${this.options.dir}/${(this[this.options.iac!] as IacConfig).envSchemaFile
253262
}`,
254263
),
255264
keysToCreate,
256265
);
257266

258267
// Create entries for env variables in stack
259268
try {
260-
const {project, sourcefile} = this._parseTsFile(
269+
const { project, sourcefile } = this._parseTsFile(
261270
this.destinationPath(
262-
`${this.options.dir!}/${
263-
(this[this.options.iac!] as IacConfig).mainStackFile
271+
`${this.options.dir!}/${(this[this.options.iac!] as IacConfig).mainStackFile
264272
}`,
265273
),
266274
);
@@ -292,8 +300,7 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
292300
this.log.ok('Your files are ready for action! 🎉');
293301
} catch (error) {
294302
this.log.error(
295-
`Failed to update env vars of lambda stack in ${this.options.dir}/${
296-
(this[this.options.iac!] as IacConfig).mainStackFile
303+
`Failed to update env vars of lambda stack in ${this.options.dir}/${(this[this.options.iac!] as IacConfig).mainStackFile
297304
}.`,
298305
error,
299306
);
@@ -361,19 +368,25 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
361368
cwd: this.destinationRoot(),
362369
});
363370

364-
this.spawnCommandSync('npm', ['install'], {
365-
cwd: this.destinationPath(this.options.dir!),
366-
});
371+
if (this.options.dir) {
372+
this.spawnCommandSync('npm', ['install'], {
373+
cwd: this.destinationPath(this.options.dir),
374+
});
375+
} else {
376+
// Handle the case where applicationClassName or relativePathToApp is undefined
377+
this.log.error("dir is undefined.");
378+
}
379+
367380
}
368381

369382
async end() {
370-
const {owner, repo, templateDir: dir} = this.remoteConfig;
383+
const { owner, repo, templateDir: dir } = this.remoteConfig;
371384
this.log(`
372385
${chalk.green("🚀 Hooray! You're all set to launch your app.")}
373386
Next steps:
374387
1. Fill up the environment variables in your ${chalk.yellow(
375-
this.options.dir,
376-
)} directory.
388+
this.options.dir,
389+
)} directory.
377390
2. Build your app.
378391
3. Run ${chalk.blue(`cdktf deploy ${this.options.iac}`)} to deploy the iac.
379392
@@ -486,7 +499,7 @@ ${chalk.blue(`https://github.com/${owner}/${repo}/blob/main/${dir}/README.md`)}
486499
_parseTsFile(filePath: string) {
487500
const project = new Project();
488501
const sourcefile = project.addSourceFileAtPathIfExists(filePath);
489-
return {project, sourcefile};
502+
return { project, sourcefile };
490503
}
491504

492505
/**
@@ -526,9 +539,9 @@ ${chalk.blue(`https://github.com/${owner}/${repo}/blob/main/${dir}/README.md`)}
526539
encoding: BufferEncoding = 'utf-8',
527540
) {
528541
try {
529-
let data = await readFile(filePath, {encoding});
542+
let data = await readFile(filePath, { encoding });
530543
data = data.replace(new RegExp(placeholder, 'g'), replaceWith);
531-
await writeFile(filePath, data, {encoding});
544+
await writeFile(filePath, data, { encoding });
532545
} catch (error) {
533546
if (error instanceof Error) {
534547
this.log.error(error.message);

packages/core/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export function addTenantId(
7878
const encryptedTenantId = req.headers['tenant-id'];
7979
const decryptedTenantId = CryptoJS.AES.decrypt(
8080
encryptedTenantId as string,
81-
secretKey as string,
81+
secretKey,
8282
).toString(CryptoJS.enc.Utf8);
8383
reqResponse['tenant-id'] = decryptedTenantId;
8484
}

services/task-service/src/commands/create-task.ts

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,18 +126,22 @@ export class CreateTaskCommand implements ICommand {
126126
return;
127127
}
128128
const promises = tasks.map(async dbTask => {
129-
const result = await workflowCtrl.startWorkflow(
130-
workflow.id!,
131-
new ExecuteWorkflowDto({
132-
input: {
133-
taskId: dbTask.id,
134-
},
135-
}),
136-
);
137-
await userTaskService.updateList(dbTask.id!, result['id']);
138-
await taskRepo.updateById(dbTask.id!, {
139-
externalId: result['id'],
140-
});
129+
if (workflow.id) {
130+
const result = await workflowCtrl.startWorkflow(
131+
workflow.id!,
132+
new ExecuteWorkflowDto({
133+
input: {
134+
taskId: dbTask.id,
135+
},
136+
}),
137+
);
138+
await userTaskService.updateList(dbTask.id!, result['id']);
139+
await taskRepo.updateById(dbTask.id!, {
140+
externalId: result['id'],
141+
});
142+
} else {
143+
this.logger.debug(`No workflow found for key ${workflowKey}`);
144+
}
141145
});
142146
await Promise.all(promises);
143147
}

services/task-service/src/services/event-processor.service.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,13 @@ export class EventProcessorService implements IEventProcessor {
8383
});
8484
if (!workflow) {
8585
this.logger.debug(`No workflow found for key ${workflowKey}`);
86+
} else if (!workflow.id) {
87+
this.logger.debug(
88+
`Workflow found for key ${workflowKey}, but it has no id`,
89+
);
8690
} else {
8791
await workflowCtrl.startWorkflow(
88-
workflow.id!,
92+
workflow.id,
8993
new ExecuteWorkflowDto({
9094
input: payload,
9195
}),

0 commit comments

Comments
 (0)