diff --git a/.github/workflows/cron_ion_token_test.yml b/.github/workflows/cron_ion_token_test.yml new file mode 100644 index 0000000000..2b8bc4f595 --- /dev/null +++ b/.github/workflows/cron_ion_token_test.yml @@ -0,0 +1,38 @@ +name: Update Cesium Ion access token (test) +on: + schedule: + - cron: "0 0 2 * *" + workflow_dispatch: +env: + GCS_DOMAIN: gs://test.reearth.dev + REEARTH_CONFIG_FILENAME: reearth_config.json +jobs: + update_ion_token: + runs-on: ubuntu-latest + steps: + - uses: google-github-actions/auth@v0 + with: + credentials_json: ${{ secrets.GCP_SA_KEY }} + - name: Set up Cloud SDK + uses: google-github-actions/setup-gcloud@v0 + - name: Download reearth config + run: gsutil cp "${{ env.GCS_DOMAIN }}/${{ env.REEARTH_CONFIG_FILENAME }}" . + - name: Get Cesium Ion token + id: ion_token + run: | + ION_TOKEN=$(\ + curl https://raw.githubusercontent.com/CesiumGS/cesium/main/packages/engine/Source/Core/Ion.js \ + | node -e "console.log(\ + require('fs')\ + .readFileSync(process.stdin.fd)\ + .toString()\ + .match(/const defaultAccessToken =(\n| ).*\"(.*)\";/)[2]\ + )"\ + ) + echo "token=${ION_TOKEN}" >> $GITHUB_OUTPUT + - name: Update Ion token in reearth config + run: | + echo $(cat ${{ env.REEARTH_CONFIG_FILENAME }} | jq -r '.cesiumIonAccessToken |= "${{ steps.ion_token.outputs.token }}"') > ${{ env.REEARTH_CONFIG_FILENAME }} + echo $(cat ${{ env.REEARTH_CONFIG_FILENAME }}) + - name: Upload reearth config + run: gsutil -h "Cache-Control:no-store" cp reearth_config.json "${{ env.GCS_DOMAIN }}/${{ env.REEARTH_CONFIG_FILENAME }}" diff --git a/.github/workflows/deploy_web_nightly.yml b/.github/workflows/deploy_web_nightly.yml index 3bd93c5f22..1de1836829 100644 --- a/.github/workflows/deploy_web_nightly.yml +++ b/.github/workflows/deploy_web_nightly.yml @@ -26,4 +26,4 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} - run: tar -xvf reearth-web_nightly.tar.gz - name: rsync - run: gsutil -m -h "Cache-Control:no-store" rsync -x "^reearth_config\\.json$|^cesium_ion_token\\.txt$" -dr reearth-web/ $GCS_DEST + run: gsutil -m -h "Cache-Control:no-store" rsync -x "^reearth_config\\.json$" -dr reearth-web/ $GCS_DEST \ No newline at end of file diff --git a/web/cesium_ion_token.txt b/web/cesium_ion_token.txt deleted file mode 100644 index 567712f1b6..0000000000 --- a/web/cesium_ion_token.txt +++ /dev/null @@ -1 +0,0 @@ -eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2MThmZGJiNi1kMDRlLTQ4ZGMtYjU0Ny0yNTljMjM1NzliN2MiLCJpZCI6MjU5LCJpYXQiOjE3MDkzMDQzNjZ9.7gsbNN-OaPZJ7QwMDB2vdF2geQDd8lMBAEK77_5Qol4 \ No newline at end of file diff --git a/web/src/services/config/index.ts b/web/src/services/config/index.ts index f4f1d2441f..a71f3605ae 100644 --- a/web/src/services/config/index.ts +++ b/web/src/services/config/index.ts @@ -66,11 +66,6 @@ export default async function loadConfig() { ...(await (await fetch("/reearth_config.json")).json()), }; - const cesiumIonToken = await loadCesiumIonToken(); - if (cesiumIonToken) { - config.cesiumIonAccessToken = cesiumIonToken; - } - const authInfo = getAuthInfo(config); if (authInfo?.cognito && authInfo.authProvider === "cognito") { configureCognito(authInfo.cognito); @@ -94,18 +89,6 @@ export default async function loadConfig() { window.REEARTH_CONFIG = config; } -async function loadCesiumIonToken(): Promise { - // updating config JSON by CI/CD sometimes can break the config file, so separate files - try { - const res = await fetch("/cesium_ion_token.txt"); - const token = await res.text(); - return token.trim(); - } catch (e) { - // ignore - } - return ""; -} - export function config(): Config | undefined { return window.REEARTH_CONFIG; }