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.
refactor into lib/remote-settings module
- Loading branch information
1 parent
5b1269b
commit 68f6ac6
Showing
2 changed files
with
64 additions
and
41 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"use strict"; | ||
|
||
const got = require("got"); | ||
const AppConstants = require("../app-constants"); | ||
|
||
|
||
const BREACHES_COLLECTION = "fxmonitor-breaches"; | ||
const FX_RS_COLLECTION = `${AppConstants.FX_REMOTE_SETTINGS_WRITER_SERVER}/buckets/main-workspace/collections/${BREACHES_COLLECTION}`; | ||
const FX_RS_RECORDS = `${FX_RS_COLLECTION}/records`; | ||
const FX_RS_BEARER_TOKEN = AppConstants.FX_REMOTE_SETTINGS_BEARER_TOKEN; | ||
|
||
const RemoteSettings = { | ||
|
||
async whichBreachesAreNotInRemoteSettingsYet(breaches) { | ||
const fxRSRecords = await got(FX_RS_RECORDS, { | ||
json: true, | ||
headers: { | ||
"authorization": `Bearer ${FX_RS_BEARER_TOKEN}`, | ||
}, | ||
}); | ||
const remoteSettingsBreachesSet = new Set( | ||
fxRSRecords.body.data.map(b => b.Name) | ||
); | ||
|
||
return breaches.filter( ({Name}) => !remoteSettingsBreachesSet.has(Name) ); | ||
}, | ||
|
||
async postNewBreachToBreachesCollection(data) { | ||
// Create the record | ||
await got.post(FX_RS_RECORDS, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
"authorization": `Bearer ${FX_RS_BEARER_TOKEN}`, | ||
}, | ||
body: JSON.stringify({data: data}), | ||
}); | ||
}, | ||
|
||
async requestReviewOnBreachesCollection() { | ||
await got.patch(FX_RS_COLLECTION, { | ||
headers: { | ||
"Content-Type": "application/json", | ||
"authorization": `Bearer ${FX_RS_BEARER_TOKEN}`, | ||
}, | ||
body: JSON.stringify({data: {status: "to-review"}}), | ||
}); | ||
}, | ||
}; | ||
|
||
|
||
module.exports = RemoteSettings; |
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