change updatebreaches.js from Bearer to Basic auth

This commit is contained in:
Luke Crouch 2019-04-23 14:47:02 -05:00
Родитель dfb7823776
Коммит 69813d817f
3 изменённых файлов: 16 добавлений и 19 удалений

Просмотреть файл

@ -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",

Просмотреть файл

@ -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)
@ -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"} },
});
},
};

Просмотреть файл

@ -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);
}