Skip to content

Commit

Permalink
Revert "fix(web): load cesium token from separate file" (#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
lavalse authored Mar 29, 2024
1 parent 332a2e0 commit f412c05
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 19 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/cron_ion_token_test.yml
Original file line number Diff line number Diff line change
@@ -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 }}"
2 changes: 1 addition & 1 deletion .github/workflows/deploy_web_nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion web/cesium_ion_token.txt

This file was deleted.

17 changes: 0 additions & 17 deletions web/src/services/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -94,18 +89,6 @@ export default async function loadConfig() {
window.REEARTH_CONFIG = config;
}

async function loadCesiumIonToken(): Promise<string> {
// 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;
}
Expand Down

0 comments on commit f412c05

Please sign in to comment.