Skip to content

Commit

Permalink
fix(deps): fix sonar issues (#2127)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Tyagi-Sunny committed Jul 3, 2024
1 parent 2a2891d commit f226bc7
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 70 deletions.
125 changes: 69 additions & 56 deletions packages/cli/src/generators/cdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fetch from 'node-fetch';
import {existsSync, mkdirSync} from 'node:fs';
import { existsSync, mkdirSync } from 'node:fs';
import {
appendFile,
readFile,
Expand All @@ -15,9 +15,9 @@ import {
Project,
PropertyAssignmentStructure,
} from 'ts-morph';
import {BaseGenerator} from '../../base-generator';
import {IacList} from '../../enum';
import {CdkOptions} from '../../types';
import { BaseGenerator } from '../../base-generator';
import { IacList } from '../../enum';
import { CdkOptions } from '../../types';
const chalk = require('chalk'); //NOSONAR

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

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

try {
if (!existsSync(outputDir)) {
mkdirSync(outputDir, {recursive: true});
mkdirSync(outputDir, { recursive: true });
}

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

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

let appImport = '';
const isDefaultExport = await this._isDefaultExport(
this.options.applicationClassName,
this.options.relativePathToApp,
);

const isDefaultExport = await this._isDefaultExport(
this.options.applicationClassName!,
this.options.relativePathToApp!,
);
const appImportPath = this._getAppImportPath(
this.options.relativePathToApp,
);

const appImportPath = this._getAppImportPath(
this.options.relativePathToApp!,
);
if (!isDefaultExport) {
appImport = `import {${this.options.applicationClassName}} from '${appImportPath}'`;
} else {
appImport = `import ${this.options.applicationClassName} from '${appImportPath}`;
}

if (!isDefaultExport) {
appImport = `import {${this.options.applicationClassName}} from '${appImportPath}'`;
await this._updateFile(
this.destinationPath(
`${this.options.dir}/${(this[this.options.iac!] as LambdaConfig).handlerFile
}`,
),
'{{app_class_name_placeholder}}',
this.options.applicationClassName,
);

await this._updateFile(
this.destinationPath(
`${this.options.dir}/${(this[this.options.iac!] as LambdaConfig).handlerFile
}`,
),
'{{app_import_placeholder}}',
appImport,
);
} else {
appImport = `import ${this.options.applicationClassName} from '${appImportPath}`;
// Handle the case where applicationClassName or relativePathToApp is undefined
this.log.error("Application class name or relative path to app is undefined.");
}

await this._updateFile(
this.destinationPath(
`${this.options.dir}/${
(this[this.options.iac!] as LambdaConfig).handlerFile
}`,
),
'{{app_class_name_placeholder}}',
this.options.applicationClassName!,
);

await this._updateFile(
this.destinationPath(
`${this.options.dir}/${
(this[this.options.iac!] as LambdaConfig).handlerFile
}`,
),
'{{app_import_placeholder}}',
appImport,
);
}

async updatePackageJsonName() {
await this._updateFile(
this.destinationPath(`${this.options.dir}/package.json`),
'{{package_json_name_placeholder}}',
this.options.packageJsonName!,
);
if (this.options.packageJsonName) {
await this._updateFile(
this.destinationPath(`${this.options.dir}/package.json`),
'{{package_json_name_placeholder}}',
this.options.packageJsonName,
);
} else {
// Handle the case where applicationClassName or relativePathToApp is undefined
this.log.error("packageJsonName is undefined.");
}

}

async configureEnvs() {
Expand All @@ -248,19 +258,17 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
const keysToCreate = await this._getEnvKeys(envFile);
await this._appendEmptyKeysToEnv(
this.destinationPath(
`${this.options.dir}/${
(this[this.options.iac!] as IacConfig).envSchemaFile
`${this.options.dir}/${(this[this.options.iac!] as IacConfig).envSchemaFile
}`,
),
keysToCreate,
);

// Create entries for env variables in stack
try {
const {project, sourcefile} = this._parseTsFile(
const { project, sourcefile } = this._parseTsFile(
this.destinationPath(
`${this.options.dir!}/${
(this[this.options.iac!] as IacConfig).mainStackFile
`${this.options.dir!}/${(this[this.options.iac!] as IacConfig).mainStackFile
}`,
),
);
Expand Down Expand Up @@ -292,8 +300,7 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
this.log.ok('Your files are ready for action! 🎉');
} catch (error) {
this.log.error(
`Failed to update env vars of lambda stack in ${this.options.dir}/${
(this[this.options.iac!] as IacConfig).mainStackFile
`Failed to update env vars of lambda stack in ${this.options.dir}/${(this[this.options.iac!] as IacConfig).mainStackFile
}.`,
error,
);
Expand Down Expand Up @@ -361,19 +368,25 @@ export default class CdkGenerator extends BaseGenerator<CdkOptions> {
cwd: this.destinationRoot(),
});

this.spawnCommandSync('npm', ['install'], {
cwd: this.destinationPath(this.options.dir!),
});
if (this.options.dir) {
this.spawnCommandSync('npm', ['install'], {
cwd: this.destinationPath(this.options.dir),
});
} else {
// Handle the case where applicationClassName or relativePathToApp is undefined
this.log.error("dir is undefined.");
}

}

async end() {
const {owner, repo, templateDir: dir} = this.remoteConfig;
const { owner, repo, templateDir: dir } = this.remoteConfig;
this.log(`
${chalk.green("🚀 Hooray! You're all set to launch your app.")}
Next steps:
1. Fill up the environment variables in your ${chalk.yellow(
this.options.dir,
)} directory.
this.options.dir,
)} directory.
2. Build your app.
3. Run ${chalk.blue(`cdktf deploy ${this.options.iac}`)} to deploy the iac.
Expand Down Expand Up @@ -486,7 +499,7 @@ ${chalk.blue(`https://github.com/${owner}/${repo}/blob/main/${dir}/README.md`)}
_parseTsFile(filePath: string) {
const project = new Project();
const sourcefile = project.addSourceFileAtPathIfExists(filePath);
return {project, sourcefile};
return { project, sourcefile };
}

/**
Expand Down Expand Up @@ -526,9 +539,9 @@ ${chalk.blue(`https://github.com/${owner}/${repo}/blob/main/${dir}/README.md`)}
encoding: BufferEncoding = 'utf-8',
) {
try {
let data = await readFile(filePath, {encoding});
let data = await readFile(filePath, { encoding });
data = data.replace(new RegExp(placeholder, 'g'), replaceWith);
await writeFile(filePath, data, {encoding});
await writeFile(filePath, data, { encoding });
} catch (error) {
if (error instanceof Error) {
this.log.error(error.message);
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export function addTenantId(
const encryptedTenantId = req.headers['tenant-id'];
const decryptedTenantId = CryptoJS.AES.decrypt(
encryptedTenantId as string,
secretKey as string,
secretKey,
).toString(CryptoJS.enc.Utf8);
reqResponse['tenant-id'] = decryptedTenantId;
}
Expand Down
28 changes: 16 additions & 12 deletions services/task-service/src/commands/create-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,22 @@ export class CreateTaskCommand implements ICommand {
return;
}
const promises = tasks.map(async dbTask => {
const result = await workflowCtrl.startWorkflow(
workflow.id!,
new ExecuteWorkflowDto({
input: {
taskId: dbTask.id,
},
}),
);
await userTaskService.updateList(dbTask.id!, result['id']);
await taskRepo.updateById(dbTask.id!, {
externalId: result['id'],
});
if (workflow.id) {
const result = await workflowCtrl.startWorkflow(
workflow.id!,
new ExecuteWorkflowDto({
input: {
taskId: dbTask.id,
},
}),
);
await userTaskService.updateList(dbTask.id!, result['id']);
await taskRepo.updateById(dbTask.id!, {
externalId: result['id'],
});
} else {
this.logger.debug(`No workflow found for key ${workflowKey}`);
}
});
await Promise.all(promises);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ export class EventProcessorService implements IEventProcessor {
});
if (!workflow) {
this.logger.debug(`No workflow found for key ${workflowKey}`);
} else if (!workflow.id) {
this.logger.debug(
`Workflow found for key ${workflowKey}, but it has no id`,
);
} else {
await workflowCtrl.startWorkflow(
workflow.id!,
workflow.id,
new ExecuteWorkflowDto({
input: payload,
}),
Expand Down

0 comments on commit f226bc7

Please sign in to comment.