Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Remove authentication in bulk translation downloads (#1993)
Dhruv Bhanushalib4adc87c4e3c
diff --git a/.github/actions/build-docs/action.yml b/.github/actions/build-docs/action.ymlindex 5b70a0da1..e143d667c 100644--- a/.github/actions/build-docs/action.yml+++ b/.github/actions/build-docs/action.yml@@ -2,14 +2,6 @@ name: openverse/build-docsdescription: Build Openverse full-stack docsinputs:- glotpress_username:- required: true- description: The username for the GlotPress account for bulk download-- glotpress_password:- required: true- description: The password for the GlotPress account for bulk download-github_token:required: truedescription: GitHub token to use for issue link resolution in documentation@@ -29,9 +21,6 @@ runs:shell: bashrun: |just frontend/run i18n- env:- GLOTPRESS_USERNAME: ${{ inputs.glotpress_username }}- GLOTPRESS_PASSWORD: ${{ inputs.glotpress_password }}- name: Build Storybookshell: bashdiff --git a/.github/workflows/ci_cd.yml b/.github/workflows/ci_cd.ymlindex ad7e6dd19..8eef7966b 100644--- a/.github/workflows/ci_cd.yml+++ b/.github/workflows/ci_cd.yml@@ -191,9 +191,6 @@ jobs:run: |just frontend/run i18ncp .npmrc .pnpmfile.cjs pnpm-lock.yaml frontend/- env:- GLOTPRESS_USERNAME: ${{ secrets.MAKE_USERNAME }}- GLOTPRESS_PASSWORD: ${{ secrets.MAKE_LOGIN_PASSWORD }}- name: Setup Docker Buildxuses: docker/setup-buildx-action@v2@@ -497,9 +494,6 @@ jobs:- name: Run buildrun: just frontend/run build- env:- GLOTPRESS_USERNAME: ${{ secrets.MAKE_USERNAME }}- GLOTPRESS_PASSWORD: ${{ secrets.MAKE_LOGIN_PASSWORD }}nuxt-checks:name: Run Nuxt checks@@ -730,8 +724,6 @@ jobs:- name: Compile documentationuses: ./.github/actions/build-docswith:- glotpress_username: ${{ secrets.MAKE_USERNAME }}- glotpress_password: ${{ secrets.MAKE_LOGIN_PASSWORD }}github_token: ${{ secrets.GITHUB_TOKEN }}# Docs will be located at `/tmp/docs`.diff --git a/.github/workflows/weekly_updates.yml b/.github/workflows/weekly_updates.ymlindex e353d5ab2..f9c809117 100644--- a/.github/workflows/weekly_updates.yml+++ b/.github/workflows/weekly_updates.yml@@ -9,7 +9,7 @@ on:env:ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}MAKE_USERNAME: ${{ secrets.MAKE_USERNAME }}- MAKE_PASSWORD: ${{ secrets.MAKE_PASSWORD }}+ MAKE_PASSWORD: ${{ secrets.MAKE_PASSWORD }} # application password, not login passwordjobs:make_post:diff --git a/automations/js/src/last_week_tonight.mjs b/automations/js/src/last_week_tonight.mjsindex 52f0187b7..e4b4058a8 100644--- a/automations/js/src/last_week_tonight.mjs+++ b/automations/js/src/last_week_tonight.mjs@@ -18,7 +18,7 @@ import { escapeHtml } from './html.mjs'const pat = process.env.ACCESS_TOKEN/** the username for the Make site account making the post */const username = process.env.MAKE_USERNAME-/** the application password for the Make site */+/** the application password, not login password, for the Make site */const password = process.env.MAKE_PASSWORDif (!pat) {diff --git a/documentation/meta/ci_cd/actions.md b/documentation/meta/ci_cd/actions.mdindex 4b34624a3..b5fd8cf2c 100644--- a/documentation/meta/ci_cd/actions.md+++ b/documentation/meta/ci_cd/actions.md@@ -76,16 +76,3 @@ Builds the documentation, including this Sphinx site, the frontend Storybook andthe Tailwind config viewer and stores it at `/tmp/docs`. This compileddocumentation is deployed to an appropriate location by the[`emit-docs`](/meta/ci_cd/jobs/documentation.md#emit-docs) job.--**Inputs:**--A GlotPress username and password combination is needed to download all-[Openverse translations](https://translate.wordpress.org/projects/meta/openverse/)-in bulk from GlotPress.--```typescript-{- glotpress_username: string // required, use secret `MAKE_USERNAME`- glotpress_password: string // required, use secret `MAKE_LOGIN_PASSWORD`-}-```diff --git a/frontend/src/locales/scripts/bulk-download.js b/frontend/src/locales/scripts/bulk-download.jsindex 1cc5dfcb8..ea5ed88de 100644--- a/frontend/src/locales/scripts/bulk-download.js+++ b/frontend/src/locales/scripts/bulk-download.js@@ -2,62 +2,23 @@ const { pipeline } = require("stream/promises")const { createWriteStream } = require("fs")-const qs = require("qs")const AdmZip = require("adm-zip")const { writeLocaleFile } = require("./utils")const axios = require("./axios")const jed1xJsonToJson = require("./jed1x-json-to-json")-const LOGIN_URL = "https://login.wordpress.org/wp-login.php"const BULK_DOWNLOAD_URL ="https://translate.wordpress.org/exporter/meta/openverse/-do/"-/**- * Given a username and password, login to WordPress and get the authentication- * cookies from the `Set-Cookie` header.- *- * @param log {string} - the username to log in with- * @param pwd {string} - the password for the given username- * @return {Promise<string[]>} - the list of cookies in the `Set-Cookie` header- */-const getAuthCookies = async (log, pwd) => {- const res = await axios.post(- LOGIN_URL,- qs.stringify({- log,- pwd,- rememberme: "forever",- "wp-submit": "Log In",- redirect_to: "https://make.wordpress.org/",- }),- {- headers: { "content-type": "application/x-www-form-urlencoded" },- maxRedirects: 0,- validateStatus: () => true,- }- )- if (- res.status == 302 &&- res.headers["set-cookie"].join(" ").includes("wporg_logged_in")- ) {- return res.headers["set-cookie"].map((cookie) =>- cookie.substring(0, cookie.indexOf(";"))- )- }- throw new Error(`Authentication failed: server returned ${res.status}`)-}-/*** Fetch the ZIP of translations strings from GlotPress using the authentication* cookies to access the page.*- * @param cookies {string[]} - the cookies to authenticate the ZIP download* @return {Promise<string>}} - the path to the downloaded ZIP file*/-const fetchBulkJed1x = async (cookies) => {+const fetchBulkJed1x = async () => {const res = await axios.get(BULK_DOWNLOAD_URL, {- headers: { cookie: cookies.join(";") },params: { "export-format": "jed1x" },responseType: "stream",})@@ -92,23 +53,14 @@ const extractZip = async (zipPath) => {}/**- * Perform a bulk download of translation strings from GlotPress and extrat the+ * Perform a bulk download of translation strings from GlotPress and extract the* JSON files from the ZIP archive.** @return {Promise<boolean>} - whether the bulk download succeeded*/const bulkDownload = async () => {console.log("Performing bulk download.")- const username = process.env.GLOTPRESS_USERNAME- const password = process.env.GLOTPRESS_PASSWORD-- if (!(username && password)) {- console.log("Auth credentials not found, bulk download cancelled.")- throw new Error("Bulk download cancelled")- }-- const cookies = await getAuthCookies(username, password)- const zipPath = await fetchBulkJed1x(cookies)+ const zipPath = await fetchBulkJed1x()const translations = await extractZip(zipPath)console.log(`Successfully saved ${translations.length} translations.`)}