Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker step to run ruby script to generate legacy websites-with-shared-credential-backends.json #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# Apple removed `websites-with-shared-credential-backends.json` from the tree in favour of a new file format.
# We currently don't support the new file format. In the meantime, we can use the
# `convert-shared-credential-to-legacy-format.rb` script from apple to generate the legacy file.
ARG RELATED_REALMS_LEGACY_FILE=websites-with-shared-credential-backends.json

FROM ruby:3.3 as related-realms-legacy-generator

RUN git clone https://github.com/apple/password-manager-resources

WORKDIR /password-manager-resources

ARG RELATED_REALMS_LEGACY_FILE
RUN ./tools/convert-shared-credential-to-legacy-format.rb $RELATED_REALMS_LEGACY_FILE
# Remove all other files, we only care about `RELATED_REALMS_LEGACY_FILE`
RUN mv $RELATED_REALMS_LEGACY_FILE / && rm -rf /password-manager-resources

FROM node:20-slim

# add a non-privileged user for running the application
Expand All @@ -16,7 +32,8 @@ RUN npm install && \
COPY ./update-script.js /app
COPY ./app-constants.js /app
COPY ./version.json /app/version.json

COPY --from=related-realms-legacy-generator /$RELATED_REALMS_LEGACY_FILE /app/$RELATED_REALMS_LEGACY_FILE
USER app

ARG RELATED_REALMS_LEGACY_FILE
ENV RELATED_REALMS_LEGACY_FILE=$RELATED_REALMS_LEGACY_FILE
CMD ["node", "/app/update-script.js"]
3 changes: 2 additions & 1 deletion app-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ require("dotenv").config();
const environmentVariables = [
"SERVER",
"AUTHORIZATION",
]
"RELATED_REALMS_LEGACY_FILE",
];

const AppConstants = {};

Expand Down
5 changes: 3 additions & 2 deletions update-script.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const KintoClient = require("kinto-http").default;
const btoa = require("btoa");
const fs = require('fs/promises');
const fetch = require("node-fetch");
const AppConstants = require("./app-constants");

Expand All @@ -11,7 +12,7 @@ const AUTHORIZATION = AppConstants.AUTHORIZATION;
/** @type {String} */
const SERVER_ADDRESS = AppConstants.SERVER;
const BUCKET = "main-workspace";
const RELATED_REALMS_API_ENDPOINT = "https://api.github.com/repos/apple/password-manager-resources/contents/quirks/websites-with-shared-credential-backends.json";
const RELATED_REALMS_LEGACY_FILE = AppConstants.RELATED_REALMS_LEGACY_FILE;
const PASSWORD_RULES_API_ENDPOINT = "https://api.github.com/repos/apple/password-manager-resources/contents/quirks/password-rules.json";

/**
Expand Down Expand Up @@ -175,7 +176,7 @@ const createAndUpdateRulesRecords = async (client, bucket) => {
*/
const createAndUpdateRelatedRealmsRecords = async (client, bucket) => {
let { data: relatedRealmsData } = await client.bucket(bucket).collection(RELATED_REALMS_COLLECTION_ID).listRecords();
let realmsGithubRecords = await getSourceRecords(RELATED_REALMS_API_ENDPOINT);
let realmsGithubRecords = JSON.parse(await fs.readFile(RELATED_REALMS_LEGACY_FILE, 'utf8'));
let id = relatedRealmsData[0]?.id;
// If there is no ID from Remote Settings, we need to create a new record in the related realms collection
if (!id) {
Expand Down