Skip to content

Commit 0618323

Browse files
nchevobbeahoneiser
authored andcommitted
Update script for ingestion.
The script will be run passing it login and password ENV variables, but the script only takes a simple token at the moment. This patch changes this so we only take login/password variables, and we update the ENV variable names to make it explicit that they're about RemoteSettings.
1 parent 0111f18 commit 0618323

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
},
77
"devDependencies": {
88
"@mdn/browser-compat-data": "latest",
9+
"btoa": "1.2.1",
910
"node-fetch": "^3.2.0"
1011
}
11-
}
12+
}

update_remote_settings_records.mjs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
/* global process */
66

77
// This script consumes the following env variables:
8-
// - AUTHORIZATION (mandatory): Raw authorization header (e.g. `AUTHORIZATION='Bearer XXXXXXXXXXXXX'`)
9-
// - SERVER (mandatory): Writer server URL (eg. https://settings-writer.stage.mozaws.net/v1)
10-
// - ENVIRONMENT (optional): dev, stage, prod. When set to `dev`, the script will approve its own changes.
11-
// - DRY_RUN (optional): If set to 1, no changes will be made to the collection, this will
8+
// - FX_REMOTE_SETTINGS_WRITER_USER (mandatory): User
9+
// - FX_REMOTE_SETTINGS_WRITER_PASS (mandatory): Password
10+
// - FX_REMOTE_SETTINGS_WRITER_SERVER (mandatory): Writer server URL (eg. https://settings-writer.stage.mozaws.net/v1)
11+
// - FX_REMOTE_SETTINGS_ENVIRONMENT (optional): dev, stage, prod. When set to `dev`, the script will approve its own changes.
12+
// - FX_REMOTE_SETTINGS_DRY_RUN (optional): If set to 1, no changes will be made to the collection, this will
1213
// only log the actions that would be done.
13-
1414
// This node script fetches `https://github.com/mdn/browser-compat-data/tree/main/browsers`
1515
// and updates records from the associated collection in RemoteSettings.
1616
// In the future, it will also handle https://github.com/mdn/browser-compat-data/tree/main/css.
1717

1818
import fetch from "node-fetch";
19+
import btoa from "btoa";
1920

2021
// Use the legacy wrapper to support all Node 12+ versions.
2122
// If we only support Node 16+, can be updated to:
@@ -27,34 +28,44 @@ const SUCCESS_RET_VALUE = 0;
2728
const FAILURE_RET_VALUE = 1;
2829
const VALID_ENVIRONMENTS = ["dev", "stage", "prod"];
2930

30-
if (!process.env.AUTHORIZATION) {
31-
console.error(`AUTHORIZATION environment variable needs to be set`);
31+
if (
32+
!process.env.FX_REMOTE_SETTINGS_WRITER_USER ||
33+
!process.env.FX_REMOTE_SETTINGS_WRITER_PASS
34+
) {
35+
console.error(
36+
`Both FX_REMOTE_SETTINGS_WRITER_USER and FX_REMOTE_SETTINGS_WRITER_PASS environment variables need to be set`
37+
);
3238
process.exit(FAILURE_RET_VALUE);
3339
}
3440

35-
if (!process.env.SERVER) {
36-
console.error(`SERVER environment variable needs to be set`);
41+
if (!process.env.FX_REMOTE_SETTINGS_WRITER_SERVER) {
42+
console.error(
43+
`FX_REMOTE_SETTINGS_WRITER_SERVER environment variable needs to be set`
44+
);
3745
process.exit(FAILURE_RET_VALUE);
3846
}
3947

4048
if (
41-
process.env.ENVIRONMENT &&
49+
process.env.FX_REMOTE_SETTINGS_ENVIRONMENT &&
4250
!VALID_ENVIRONMENTS.includes(process.env.ENVIRONMENT)
4351
) {
4452
console.error(
45-
`ENVIRONMENT environment variable needs to be set to one of the following values: ${VALID_ENVIRONMENTS.join(
53+
`FX_REMOTE_SETTINGS_ENVIRONMENT environment variable needs to be set to one of the following values: ${VALID_ENVIRONMENTS.join(
4654
", "
4755
)}`
4856
);
4957
process.exit(FAILURE_RET_VALUE);
5058
}
5159

52-
const rsBrowsersCollectionEndpoint = `${process.env.SERVER}/buckets/main-workspace/collections/devtools-compatibility-browsers`;
60+
const rsBrowsersCollectionEndpoint = `${process.env.FX_REMOTE_SETTINGS_WRITER_SERVER}/buckets/main-workspace/collections/devtools-compatibility-browsers`;
5361
const rsBrowsersRecordsEndpoint = `${rsBrowsersCollectionEndpoint}/records`;
54-
const isDryRun = process.env.DRY_RUN == "1";
62+
const isDryRun = process.env.FX_REMOTE_SETTINGS_DRY_RUN == "1";
63+
5564
const headers = {
5665
"Content-Type": "application/json",
57-
Authorization: process.env.AUTHORIZATION,
66+
Authorization: `Basic ${btoa(
67+
`${process.env.FX_REMOTE_SETTINGS_WRITER_USER}:${process.env.FX_REMOTE_SETTINGS_WRITER_PASS}`
68+
)}`,
5869
};
5970

6071
update()
@@ -147,7 +158,7 @@ async function update() {
147158
const refreshedRecords = await getRSRecords();
148159
console.log("Browsers data synced ✅\nRefreshed records:");
149160
console.table(refreshedRecords);
150-
if (process.env.ENVIRONMENT === "dev") {
161+
if (process.env.FX_REMOTE_SETTINGS_ENVIRONMENT === "dev") {
151162
await approveChanges();
152163
} else {
153164
await requestReview();

0 commit comments

Comments
 (0)