Skip to content

Commit

Permalink
change updatebreaches.js from Bearer to Basic auth
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed Apr 25, 2019
1 parent dfb7823 commit 69813d8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
3 changes: 2 additions & 1 deletion app-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const kEnvironmentVariables = [
"FXA_ENABLED",
"FXA_SETTINGS_URL",
"FX_REMOTE_SETTINGS_WRITER_SERVER",
"FX_REMOTE_SETTINGS_BEARER_TOKEN",
"FX_REMOTE_SETTINGS_WRITER_USER",
"FX_REMOTE_SETTINGS_WRITER_PASS",
"MOZLOG_FMT",
"MOZLOG_LEVEL",
"OAUTH_AUTHORIZATION_URI",
Expand Down
27 changes: 11 additions & 16 deletions lib/remote-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ 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 FX_RS_WRITER_USER = AppConstants.FX_REMOTE_SETTINGS_WRITER_USER;
const FX_RS_WRITER_PASS = AppConstants.FX_REMOTE_SETTINGS_WRITER_PASS;

const RemoteSettings = {

async whichBreachesAreNotInRemoteSettingsYet(breaches) {
const fxRSRecords = await got(FX_RS_RECORDS, {
json: true,
headers: {
"authorization": `Bearer ${FX_RS_BEARER_TOKEN}`,
},
auth: `${FX_RS_WRITER_USER}:${FX_RS_WRITER_PASS}`,
});
const remoteSettingsBreachesSet = new Set(
fxRSRecords.body.data.map(b => b.Name)
Expand All @@ -26,23 +25,19 @@ const RemoteSettings = {
},

async postNewBreachToBreachesCollection(data) {
const auth = `${FX_RS_WRITER_USER}:${FX_RS_WRITER_PASS}`;

// 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}),
return await got.post(FX_RS_RECORDS, {
json: true, auth, body: { 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"}}),
const auth = `${FX_RS_WRITER_USER}:${FX_RS_WRITER_PASS}`;

return await got.patch(FX_RS_COLLECTION, {
json: true, auth, body: { data: {status: "to-review"} },
});
},
};
Expand Down
5 changes: 3 additions & 2 deletions scripts/updatebreaches.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ const RemoteSettings = require("../lib/remote-settings");


if (
!AppConstants.FX_REMOTE_SETTINGS_BEARER_TOKEN ||
!AppConstants.FX_REMOTE_SETTINGS_WRITER_USER ||
!AppConstants.FX_REMOTE_SETTINGS_WRITER_PASS ||
!AppConstants.FX_REMOTE_SETTINGS_WRITER_SERVER
) {
console.error("updatebreaches requires FX_RS_BEARER_TOKEN.");
console.error("updatebreaches requires FX_REMOTE_SETTINGS_WRITER_SERVER, FX_REMOTE_SETTINGS_WRITER_USER, FX_REMOTE_SETTINGS_WRITER_PASS.");
process.exit(1);
}

Expand Down

0 comments on commit 69813d8

Please sign in to comment.