Skip to content

Commit

Permalink
Merge branch 'sourcefuse:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
prernagp authored Jul 9, 2024
2 parents 3b498ef + 1131668 commit 2fa6e8a
Show file tree
Hide file tree
Showing 13 changed files with 346 additions and 110 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
16 changes: 15 additions & 1 deletion services/audit-service/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "Audit Service",
"version": "1.0.0",
"description": "Audit logging microservice",
"description": "Audit logging Microservice",
"contact": {
"name": "Sourcefuse"
}
Expand Down Expand Up @@ -544,6 +544,20 @@
},
"actedOn": {
"type": "string"
},
"actedOnList": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "string"
}
},
"actionGroupList": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "string"
}
}
},
"additionalProperties": false,
Expand Down
36 changes: 31 additions & 5 deletions services/audit-service/openapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ headingLevel: 2

> Scroll down for code samples, example requests and responses. Select a language for code samples from the tabs above or the mobile navigation menu.
Audit logging microservice
Audit logging Microservice

Base URLs:

Expand All @@ -46,7 +46,13 @@ const inputBody = '{
},
"deleted": true,
"entityId": "string",
"actedOn": "string"
"actedOn": "string",
"actedOnList": [
"string"
],
"actionGroupList": [
"string"
]
}';
const headers = {
'Content-Type':'application/json',
Expand Down Expand Up @@ -77,7 +83,13 @@ const inputBody = {
},
"deleted": true,
"entityId": "string",
"actedOn": "string"
"actedOn": "string",
"actedOnList": [
"string"
],
"actionGroupList": [
"string"
]
};
const headers = {
'Content-Type':'application/json',
Expand Down Expand Up @@ -116,7 +128,13 @@ fetch('/audit-logs/archive',
},
"deleted": true,
"entityId": "string",
"actedOn": "string"
"actedOn": "string",
"actedOnList": [
"string"
],
"actionGroupList": [
"string"
]
}
```

Expand Down Expand Up @@ -953,7 +971,13 @@ AuditLogWithRelations
},
"deleted": true,
"entityId": "string",
"actedOn": "string"
"actedOn": "string",
"actedOnList": [
"string"
],
"actionGroupList": [
"string"
]
}

```
Expand All @@ -970,6 +994,8 @@ CustomFilter
|deleted|boolean|false|none|none|
|entityId|string|false|none|none|
|actedOn|string|false|none|none|
|actedOnList|[string]|false|none|none|
|actionGroupList|[string]|false|none|none|

<h2 id="tocS_loopback.Count">loopback.Count</h2>
<!-- backwards compatibility -->
Expand Down
Loading

0 comments on commit 2fa6e8a

Please sign in to comment.