mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-30 06:40:05 +00:00
FEAT: pii
This commit is contained in:
@@ -34,8 +34,12 @@ import {
|
||||
GetNimbusDashboardsRequest,
|
||||
GetRlsRulesRequest,
|
||||
} from '@dadosfera/protospack-v2/dist/lib/Catalog/interfaces/messages';
|
||||
import { readFileSync } from 'fs';
|
||||
import { writeFileSync } from 'fs';
|
||||
import path from 'path';
|
||||
import { HtmlParser } from 'src/utils/FileParser/html-parser';
|
||||
import { PiiDto } from './dtos/pii.dto';
|
||||
import { CsvParser } from 'src/utils/FileParser/csv-parser';
|
||||
import { PDFParser } from 'src/utils/FileParser/pdf-parser';
|
||||
|
||||
class CatalogService implements OnModuleInit {
|
||||
catalogReadService: ReadService.CatalogReadServices;
|
||||
@@ -82,49 +86,47 @@ class CatalogService implements OnModuleInit {
|
||||
)}.dadosfera.ai`;
|
||||
}
|
||||
|
||||
async getPiiReporter(metadata: Metadata) {
|
||||
const {
|
||||
data
|
||||
} = await lastValueFrom(
|
||||
this.catalogWriteService.GetPiiReporter({}, metadata)
|
||||
)
|
||||
async getPiiReporter(metadata: Metadata, type: "html"| "csv") {
|
||||
try {
|
||||
const {
|
||||
data
|
||||
} = await lastValueFrom(
|
||||
this.catalogWriteService.GetPiiReporter({}, metadata)
|
||||
)
|
||||
this.logger.info("Finish grpc call")
|
||||
|
||||
// 3. Ler o template HTML
|
||||
const templatePath = path.join(
|
||||
__dirname,
|
||||
'../../../src/template/pii-reporter.html',
|
||||
);
|
||||
|
||||
const result = data.map((props) => ({
|
||||
...props,
|
||||
pii_rules: this.formatPiiRules(JSON.parse(props.pii_rules)),
|
||||
}));
|
||||
this.logger.info("templatePath: " + templatePath);
|
||||
|
||||
// 3. Ler o template HTML
|
||||
const templatePath = path.join(
|
||||
__dirname,
|
||||
'../../../src/template/pii-reporter.html',
|
||||
);
|
||||
const templateSource = readFileSync(templatePath, 'utf8');
|
||||
|
||||
// 4. Compilar o template
|
||||
const template = Handlebars.compile(templateSource);
|
||||
|
||||
// 5. Aplicar os dados ao template
|
||||
return template({
|
||||
dados: result,
|
||||
dataGeracao: new Date().toLocaleString('pt-BR'),
|
||||
});
|
||||
}
|
||||
|
||||
private formatPiiRules(
|
||||
data: Record<
|
||||
string,
|
||||
{
|
||||
avg_score: number;
|
||||
max_score: number;
|
||||
if (type === "html") {
|
||||
const htmlParser = new HtmlParser<PiiDto>(templatePath);
|
||||
return htmlParser.parse(data);
|
||||
} else if (type === "csv") {
|
||||
const csvParser = new CsvParser<PiiDto>();
|
||||
return await csvParser.parse(data)
|
||||
} else if (type === "pdf") {
|
||||
const htmlParser = new HtmlParser<PiiDto>(templatePath);
|
||||
const pdfParser = new PDFParser();
|
||||
const pdf = await pdfParser.parse(htmlParser.parse(data));
|
||||
const pdfPath = path.join(
|
||||
__dirname,
|
||||
'../../../src/template/teste.pdf',
|
||||
);
|
||||
writeFileSync(pdfPath, pdf);
|
||||
return pdf
|
||||
}
|
||||
>,
|
||||
) {
|
||||
return Object.keys(data)
|
||||
.filter((key) => {
|
||||
return data[key].max_score > 0.7;
|
||||
})
|
||||
.join(', ');
|
||||
|
||||
throw new Error("Unsupported Type: " + type)
|
||||
|
||||
} catch (error) {
|
||||
this.logger.error(error);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async createDataAsset(data: Messages.CreateDataAssetRequest, metadata) {
|
||||
|
||||
Reference in New Issue
Block a user