-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #250 from cisagov/DJ_extract_cyhy_data_WIP
Save hosts and tickets to datalake
- Loading branch information
Showing
10 changed files
with
347 additions
and
16 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
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,28 @@ | ||
import { plainToClass } from 'class-transformer'; | ||
import { Host, connectToDatalake } from '../../models'; | ||
|
||
export default async (host: Host): Promise<string> => { | ||
console.log(`Starting to save host ${host.ipString} to datalake`); | ||
await connectToDatalake(); | ||
const hostUpdatedValues = Object.keys(host) | ||
.map((key) => { | ||
if (['id'].indexOf(key) > -1) return ''; | ||
else if (key === 'organization') return 'organizationId'; | ||
else if (key === 'ip') return 'ipId'; | ||
return host[key] !== null ? key : ''; | ||
}) | ||
.filter((key) => key !== ''); | ||
const host_id: string = ( | ||
await Host.createQueryBuilder() | ||
.insert() | ||
.values(host) | ||
.orUpdate({ | ||
conflict_target: ['id'], | ||
overwrite: hostUpdatedValues | ||
}) | ||
.returning('id') | ||
.execute() | ||
).identifiers[0].id; | ||
|
||
return host_id; | ||
}; |
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,35 @@ | ||
import { plainToClass } from 'class-transformer'; | ||
import { | ||
Ticket, | ||
DL_Organization, | ||
Cidr, | ||
Location, | ||
connectToDatalake | ||
} from '../../models'; | ||
|
||
export default async (ticket: Ticket): Promise<string> => { | ||
console.log(`Starting to save Ticket to datalake`); | ||
await connectToDatalake(); | ||
const ticketUpdatedValues = Object.keys(ticket) | ||
.map((key) => { | ||
if (['id'].indexOf(key) > -1) return ''; | ||
else if (key === 'organization') return 'organizationId'; | ||
else if (key === 'ip') return 'ipId'; | ||
else if (key === 'cve') return 'cveId'; | ||
return ticket[key] !== null ? key : ''; | ||
}) | ||
.filter((key) => key !== ''); | ||
const ticket_id: string = ( | ||
await Ticket.createQueryBuilder() | ||
.insert() | ||
.values(ticket) | ||
.orUpdate({ | ||
conflict_target: ['id'], | ||
overwrite: ticketUpdatedValues | ||
}) | ||
.returning('id') | ||
.execute() | ||
).identifiers[0].id; | ||
|
||
return ticket_id; | ||
}; |
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,32 @@ | ||
import { plainToClass } from 'class-transformer'; | ||
import { | ||
TicketEvent, | ||
DL_Organization, | ||
Cidr, | ||
Location, | ||
connectToDatalake | ||
} from '../../models'; | ||
|
||
export default async (ticket_event: TicketEvent): Promise<string> => { | ||
await connectToDatalake(); | ||
const ticketEventUpdatedValues = Object.keys(ticket_event) | ||
.map((key) => { | ||
if (['eventTimestamp', 'action', 'ticket'].indexOf(key) > -1) return ''; | ||
else if (key === 'vulnScan') return 'vulnScanId'; | ||
return ticket_event[key] !== null ? key : ''; | ||
}) | ||
.filter((key) => key !== ''); | ||
const ticket_event_id: string = ( | ||
await TicketEvent.createQueryBuilder() | ||
.insert() | ||
.values(ticket_event) | ||
.orUpdate({ | ||
conflict_target: ['eventTimestamp', 'action', 'ticketId'], | ||
overwrite: ticketEventUpdatedValues | ||
}) | ||
.returning('id') | ||
.execute() | ||
).identifiers[0].id; | ||
|
||
return ticket_event_id; | ||
}; |
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
Oops, something went wrong.