forked from mozilla/blurts-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb86a26
commit f09209e
Showing
4 changed files
with
56 additions
and
24 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,48 @@ | ||
"use strict"; | ||
|
||
const got = require("got"); | ||
|
||
const AppConstants = require("../app-constants"); | ||
const DBUtils = require("../db/utils"); | ||
const pkg = require("../package.json"); | ||
|
||
const HIBP_AUTH = `Bearer ${AppConstants.HIBP_API_TOKEN}`; | ||
const HIBP_USER_AGENT = `${pkg.name}/${pkg.version}`; | ||
|
||
|
||
async function handleBreachesResponse(response) { | ||
try { | ||
const breachesJSON = JSON.parse(response.body); | ||
|
||
for (const breach of breachesJSON) { | ||
await DBUtils.createBreach(breach.Name, breach); | ||
} | ||
} catch (error) { | ||
debugger; | ||
console.error(error); | ||
// We can `process.exit()` here since it's a CLI script. | ||
// eslint-disable-next-line no-process-exit | ||
process.exit(1); | ||
} | ||
} | ||
|
||
(async () => { | ||
try { | ||
const breachesResponse = await got( | ||
`${AppConstants.HIBP_API_ROOT}/breaches`, | ||
{ | ||
headers: { | ||
"User-Agent": HIBP_USER_AGENT, | ||
}, | ||
} | ||
); | ||
await handleBreachesResponse(breachesResponse); | ||
} catch (error) { | ||
console.error(error); | ||
// We can `process.exit()` here since it's a CLI script. | ||
// eslint-disable-next-line no-process-exit | ||
process.exit(1); | ||
} | ||
console.log("Done handling breaches response."); | ||
process.exit(); | ||
})(); |
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