-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: 32 alllow to anonymize csv files (init) (#332)
* chore(general): added csv keyword * chore: added dbzar command * chore: add papaparse * chore: parse ent * chore: move * chore: move files * chore: add hooks * chore: move files * chore: move * chore: fix * chore: move get-processor * chore: fix tests locally * chore: move collections * chore: move get-collections * chore: rename * chore: change databases * chore: rename enum * chore: rename * chore: lint fix * chore: set debug for dev * chore: milestone
- Loading branch information
Showing
29 changed files
with
228 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
MONGO_DB_URI=mongodb://root:example@localhost | ||
POSTGRES_DB_URI=postgresql://postgres:example@localhost/test | ||
MARIADB_DB_URI=mariadb://example:[email protected]/test | ||
NODE_ENV=development | ||
NODE_ENV=development | ||
DEBUG="dbzar,dbzar:*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
mongodbMemoryServerOptions: { | ||
binary: { | ||
version: '6.0.6', | ||
skipMD5: true, | ||
}, | ||
autoStart: false, | ||
instance: {}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
"mongodb", | ||
"mariadb", | ||
"mysql", | ||
"csv", | ||
"mock", | ||
"fake" | ||
], | ||
|
@@ -93,6 +94,7 @@ | |
"mysql": "^2.18.1", | ||
"node-emoji": "^2.1.0", | ||
"ora": "5.4.1", | ||
"papaparse": "^5.4.1", | ||
"pg": "^8.7.1" | ||
}, | ||
"packageManager": "[email protected]" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/cli/commands/anon-db/anon-db-command.ts → src/cli/commands/anon-db/anon-db.command.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import {extname} from 'path'; | ||
import {type Command} from 'commander'; | ||
import {createLogger} from '../../../services/loggers/debug-logger'; | ||
|
||
const logger = createLogger(__filename); | ||
|
||
export async function anonFileAction(this: Command) { | ||
logger('processing file'); | ||
|
||
const [filePath] = this.args; | ||
logger(`filePath = ${filePath}`); | ||
|
||
if (filePath) { | ||
const extension = extname(filePath)?.slice(1).toLowerCase(); | ||
|
||
if (extension === 'csv') { | ||
logger('parsing csv file'); | ||
} | ||
} else { | ||
throw new Error('no file path'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import {Command} from 'commander'; | ||
import {anonFileAction} from './anon-file.action'; | ||
|
||
export const anonFileCommand = new Command('anon-file'); | ||
|
||
anonFileCommand | ||
.description('Anonymize a single file') | ||
.argument('[filePath]', 'file path') | ||
.action(anonFileAction); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/processors/mariadb/mariadb-processor.ts → ...rs/databases/mariadb/mariadb-processor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...s/mongo/__tests__/mongo-processor.spec.ts → ...s/mongo/__tests__/mongo-processor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
src/processors/mongo/mongo-processor.ts → ...essors/databases/mongo/mongo-processor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/processors/databases/postgres/__tests__/postgres-processor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import {type Knex} from 'knex'; | ||
import {newDb} from 'pg-mem'; | ||
import {MaskAnonymizer} from '../../../../anonymizers/mask/mask-anonymizer'; | ||
import {type Anonymizer} from '../../../../anonymizers/types'; | ||
import {PostgresProcessor} from '../postgres/postgres-processor'; | ||
|
||
describe('PostgresProcessor', () => { | ||
let knex: Knex; | ||
|
||
beforeEach(async () => { | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
knex = newDb().adapters.createKnex(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await knex.destroy(); | ||
}); | ||
|
||
it('should process a single doc', async () => { | ||
await knex.schema.createTable('users', (table) => { | ||
table.increments('id'); | ||
table.string('firstName'); | ||
}); | ||
|
||
await knex('users').insert({firstName: 'John'}); | ||
|
||
const selectedRows1 = await knex('users').select('firstName'); | ||
expect(selectedRows1[0].firstName).toBe('John'); | ||
|
||
const spy1 = jest | ||
.spyOn(knex.client, 'destroy') | ||
.mockImplementationOnce(async () => { | ||
// Do nothing | ||
}); | ||
const spy2 = jest | ||
.spyOn(PostgresProcessor.prototype as any, 'buildClient') | ||
.mockImplementationOnce(() => knex); | ||
|
||
// Anonymize the db | ||
const processor: PostgresProcessor = new PostgresProcessor( | ||
'postgresql://localhost', | ||
); | ||
|
||
const anonymizer: Anonymizer = new MaskAnonymizer(); | ||
await processor.processColumn('users', 'firstName', anonymizer); | ||
|
||
spy1.mockRestore(); | ||
spy2.mockRestore(); | ||
|
||
// Check again | ||
const selectedRows2 = await knex('users').select('firstName'); | ||
expect(selectedRows2[0].firstName).toBe('****'); | ||
}); | ||
|
||
it('should process multiple rows', async () => { | ||
await knex.schema.createTable('users', (table) => { | ||
table.increments('id'); | ||
table.string('firstName'); | ||
}); | ||
|
||
await knex('users').insert([{firstName: 'test1'}, {firstName: 'test2'}]); | ||
|
||
const spy1 = jest | ||
.spyOn(knex.client, 'destroy') | ||
.mockImplementationOnce(async () => { | ||
// Do nothing | ||
}); | ||
const spy2 = jest | ||
.spyOn(PostgresProcessor.prototype as any, 'buildClient') | ||
.mockImplementationOnce(() => knex); | ||
|
||
// Anonymize the db | ||
const processor: PostgresProcessor = new PostgresProcessor( | ||
'postgresql://localhost', | ||
); | ||
|
||
const anonymizer: Anonymizer = new MaskAnonymizer(); | ||
await processor.processColumn('users', 'firstName', anonymizer); | ||
|
||
spy1.mockRestore(); | ||
spy2.mockRestore(); | ||
|
||
// Check again | ||
const selectedRows2 = await knex('users').select('firstName'); | ||
expect(selectedRows2[0].firstName).toBe('*****'); | ||
expect(selectedRows2[1].firstName).toBe('*****'); | ||
}); | ||
}); |
5 changes: 3 additions & 2 deletions
5
...gres/__tests__/postgres-processor.spec.ts → ...gres/__tests__/postgres-processor.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
...processors/postgres/postgres-processor.ts → ...s/postgres/postgres/postgres-processor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/processors/types/collection.ts → src/processors/databases/types/collection.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/processors/utils/get-collections.ts → ...essors/databases/utils/get-collections.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.