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

chore(placement): switch to BSA #10011

Merged
merged 3 commits into from
Dec 1, 2023
Merged
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
4 changes: 2 additions & 2 deletions .github/workflows/prod-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,15 +355,15 @@ jobs:
--set-env-vars="ORIGIN_PLAY=mdnplay.dev" \
--set-env-vars="SOURCE_CONTENT=https://storage.googleapis.com/${{ vars.GCP_BUCKET_NAME }}/main/" \
--set-env-vars="SOURCE_API=https://api.developer.mozilla.org/" \
--set-env-vars="BSA_ENABLED=true" \
--set-env-vars="SENTRY_DSN=${{ secrets.SENTRY_DSN_CLOUD_FUNCTION }}" \
--set-env-vars="SENTRY_ENVIRONMENT=prod" \
--set-env-vars="SENTRY_TRACES_SAMPLE_RATE=${{ vars.SENTRY_TRACES_SAMPLE_RATE }}" \
--set-env-vars="SENTRY_RELEASE=${{ github.sha }}" \
--set-secrets="KEVEL_SITE_ID=projects/${{ secrets.GCP_PROJECT_NAME }}/secrets/prod-kevel-site-id/versions/latest" \
--set-secrets="KEVEL_NETWORK_ID=projects/${{ secrets.GCP_PROJECT_NAME }}/secrets/prod-kevel-network-id/versions/latest" \
--set-secrets="SIGN_SECRET=projects/${{ secrets.GCP_PROJECT_NAME }}/secrets/prod-sign-secret/versions/latest" \
--set-secrets="CARBON_ZONE_KEY=projects/${{ secrets.GCP_PROJECT_NAME }}/secrets/prod-carbon-zone-key/versions/latest" \
--set-secrets="CARBON_FALLBACK_ENABLED=projects/${{ secrets.GCP_PROJECT_NAME }}/secrets/prod-fallback-enabled/versions/latest" \
--set-secrets="BSA_ZONE_KEYS=projects/${{ secrets.GCP_PROJECT_NAME }}/secrets/prod-bsa-zone-keys/versions/latest" \
2>&1 | sed "s/^/[$region] /" &
pids+=($!)
done
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/stage-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,6 @@ jobs:
--set-env-vars="SOURCE_CONTENT=https://storage.googleapis.com/${{ vars.GCP_BUCKET_NAME }}/main/" \
--set-env-vars="SOURCE_API=https://api.developer.allizom.org/" \
--set-env-vars="BSA_ENABLED=true" \
--set-env-vars="BSA_URL_PREFIX=https://developer.allizom.org/fr/" \
--set-env-vars="SENTRY_DSN=${{ secrets.SENTRY_DSN_CLOUD_FUNCTION }}" \
--set-env-vars="SENTRY_ENVIRONMENT=stage" \
--set-env-vars="SENTRY_TRACES_SAMPLE_RATE=${{ vars.SENTRY_TRACES_SAMPLE_RATE }}" \
Expand Down
3 changes: 0 additions & 3 deletions cloud-function/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ The placement handler uses the following environment variables:
- `KEVEL_NETWORK_ID` (default: `0`) - Required for serving placements via Kevel.
- `SIGN_SECRET` (default: `""`) - Required for serving placements.
- `BSA_ZONE_KEYS` (default: `""`) - Required for serving placements via BSA.
- `BSA_URL_PREFIX`(default: "https://localhost") - Where to show BSA placements
if enabled. Formatted like :
"placementname1:zonekey1;placementkey2:zonekey2...".
- `BSA_ENABLED` (default: `"false"`) - Whether to use placements via BSA.

You can override the defaults by adding a `.env` file with `KEY=value` lines.
2 changes: 0 additions & 2 deletions cloud-function/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ export const SIGN_SECRET = process.env["SIGN_SECRET"] ?? "";
export const BSA_ZONE_KEYS = Object.fromEntries(
(process.env["BSA_ZONE_KEYS"] ?? "").split(";").map((k) => k.split(":"))
);
export const BSA_URL_PREFIX =
process.env["BSA_URL_PREFIX"] ?? "https://localhost";
export const BSA_ENABLED = Boolean(
JSON.parse(process.env["BSA_ENABLED"] || "false")
);
Expand Down
8 changes: 2 additions & 6 deletions cloud-function/src/handlers/proxy-pong.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { BSA_ENABLED, BSA_URL_PREFIX } from "../env.js";
import { BSA_ENABLED } from "../env.js";
import { proxyBSA } from "./proxy-bsa.js";
import { proxyKevel } from "./proxy-kevel.js";

import type { Request, Response } from "express";

export async function proxyPong(req: Request, res: Response) {
if (BSA_ENABLED) {
const referrer = req.get("referrer") || "";
const version = Number(req.query["version"]) || 1;
if (referrer.startsWith(BSA_URL_PREFIX) || version === 2) {
return proxyBSA(req, res);
}
return proxyBSA(req, res);
}
return proxyKevel(req, res);
}
Loading