diff --git a/.github/workflows/build-and-deploy-beta.yml b/.github/workflows/build-and-deploy-beta.yml index 9c94c7fba..eb9e05763 100644 --- a/.github/workflows/build-and-deploy-beta.yml +++ b/.github/workflows/build-and-deploy-beta.yml @@ -60,6 +60,8 @@ jobs: USERSNAP_SPACE_API_KEY: ${{ secrets.USERSNAP_SPACE_API_KEY }} IS_PROPOSAL_DISCUSSION_FORUM_ENABLED: ${{ inputs.isProposalDiscussionForumEnabled == 'enabled' }} PDF_API_URL: ${{ secrets.PDF_API_URL}} + IPFS_GATEWAY: ${{ secrets.IPFS_GATEWAY }} + IPFS_PROJECT_ID: ${{ secrets.IPFS_PROJECT_ID }} steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/.github/workflows/build-and-deploy-dev.yml b/.github/workflows/build-and-deploy-dev.yml index 372840230..f80a3b91b 100644 --- a/.github/workflows/build-and-deploy-dev.yml +++ b/.github/workflows/build-and-deploy-dev.yml @@ -60,6 +60,8 @@ jobs: USERSNAP_SPACE_API_KEY: ${{ secrets.USERSNAP_SPACE_API_KEY }} IS_PROPOSAL_DISCUSSION_FORUM_ENABLED: ${{ inputs.isProposalDiscussionForumEnabled == 'enabled' }} PDF_API_URL: ${{ secrets.PDF_API_URL }} + IPFS_GATEWAY: ${{ secrets.IPFS_GATEWAY }} + IPFS_PROJECT_ID: ${{ secrets.IPFS_PROJECT_ID }} steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/.github/workflows/build-and-deploy-staging.yml b/.github/workflows/build-and-deploy-staging.yml index 27d10fdb0..bbd68afc3 100644 --- a/.github/workflows/build-and-deploy-staging.yml +++ b/.github/workflows/build-and-deploy-staging.yml @@ -63,6 +63,8 @@ jobs: USERSNAP_SPACE_API_KEY: ${{ secrets.USERSNAP_SPACE_API_KEY }} IS_PROPOSAL_DISCUSSION_FORUM_ENABLED: ${{github.event_name == 'push' && 'true' || inputs.isProposalDiscussionForumEnabled == 'enabled'}} PDF_API_URL: ${{ secrets.PDF_API_URL}} + IPFS_GATEWAY: ${{ secrets.IPFS_GATEWAY }} + IPFS_PROJECT_ID: ${{ secrets.IPFS_PROJECT_ID }} steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/.github/workflows/build-and-deploy-test.yml b/.github/workflows/build-and-deploy-test.yml index 64cc7a89f..201f18799 100644 --- a/.github/workflows/build-and-deploy-test.yml +++ b/.github/workflows/build-and-deploy-test.yml @@ -63,6 +63,8 @@ jobs: USERSNAP_SPACE_API_KEY: ${{ secrets.USERSNAP_SPACE_API_KEY }} IS_PROPOSAL_DISCUSSION_FORUM_ENABLED: ${{github.event_name == 'push' && 'true' || inputs.isProposalDiscussionForumEnabled == 'enabled'}} PDF_API_URL: ${{ secrets.PDF_API_URL}} + IPFS_GATEWAY: ${{ secrets.IPFS_GATEWAY }} + IPFS_PROJECT_ID: ${{ secrets.IPFS_PROJECT_ID }} steps: - name: Checkout code uses: actions/checkout@v4 diff --git a/CHANGELOG.md b/CHANGELOG.md index feca40ce6..4e2216979 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ changes. - Add support for displaying Motion of No Confidence Governance Action [Issue 1597](https://github.com/IntersectMBO/govtool/issues/1597) - Add support for displaying Update committee/threshold Governance Action [Issue 1598](https://github.com/IntersectMBO/govtool/issues/1598) - Add support for displaying New Constitution and/or Guardrails Script Governance Action [Issue 1599](https://github.com/IntersectMBO/govtool/issues/1598) +- Add support for ipfs in metadata validation service [Issue 1616](https://github.com/IntersectMBO/govtool/issues/1616) ### Fixed diff --git a/govtool/metadata-validation/.env.example b/govtool/metadata-validation/.env.example index c0c68b1ca..3cf07604c 100644 --- a/govtool/metadata-validation/.env.example +++ b/govtool/metadata-validation/.env.example @@ -1 +1,3 @@ -PORT=3000 \ No newline at end of file +PORT=3000 +IPFS_GATEWAY=https://ipfs.some.gateway +IPFS_PROJECT_ID=ipfsprojectid diff --git a/govtool/metadata-validation/Dockerfile b/govtool/metadata-validation/Dockerfile index 5835d6e8e..a245abc71 100644 --- a/govtool/metadata-validation/Dockerfile +++ b/govtool/metadata-validation/Dockerfile @@ -1,5 +1,8 @@ FROM node:lts-hydrogen +ARG IPFS_GATEWAY +ARG IPFS_PROJECT_ID + WORKDIR /dist COPY package*.json ./ diff --git a/govtool/metadata-validation/docker-compose.yml b/govtool/metadata-validation/docker-compose.yml index bdf965762..e27b9b1e6 100644 --- a/govtool/metadata-validation/docker-compose.yml +++ b/govtool/metadata-validation/docker-compose.yml @@ -8,6 +8,8 @@ services: container_name: metadata-validation environment: - PORT=${PORT} + - IPFS_GATEWAY=${IPFS_GATEWAY} + - IPFS_PROJECT_ID=${IPFS_PROJECT_ID} ports: - ${PORT}:${PORT} volumes: diff --git a/govtool/metadata-validation/src/app.service.ts b/govtool/metadata-validation/src/app.service.ts index a948ef173..8955db611 100644 --- a/govtool/metadata-validation/src/app.service.ts +++ b/govtool/metadata-validation/src/app.service.ts @@ -22,15 +22,30 @@ export class AppService { let metadata: Record; let standard = paramStandard; + const isIPFS = url.startsWith('ipfs://'); + if (isIPFS) { + url = `${process.env.IPFS_GATEWAY}/${url.slice(7)}`; + } + try { const { data: rawData } = await firstValueFrom( - this.httpService.get(url).pipe( - finalize(() => Logger.log(`Fetching ${url} completed`)), - catchError((error) => { - Logger.error(error, JSON.stringify(error)); - throw MetadataValidationStatus.URL_NOT_FOUND; - }), - ), + this.httpService + .get(url, { + headers: { + 'Content-Type': 'application/json', + ...(isIPFS && + process.env.IPFS_PROJECT_ID && { + project_id: process.env.IPFS_PROJECT_ID, + }), + }, + }) + .pipe( + finalize(() => Logger.log(`Fetching ${url} completed`)), + catchError((error) => { + Logger.error(error, JSON.stringify(error)); + throw MetadataValidationStatus.URL_NOT_FOUND; + }), + ), ); let parsedData; diff --git a/scripts/govtool/config/templates/docker-compose.yml.tpl b/scripts/govtool/config/templates/docker-compose.yml.tpl index 653312e82..80b64cafc 100644 --- a/scripts/govtool/config/templates/docker-compose.yml.tpl +++ b/scripts/govtool/config/templates/docker-compose.yml.tpl @@ -187,6 +187,8 @@ services: image: /metadata-validation:${METADATA_VALIDATION_TAG} environment: - PORT=3000 + - IPFS_GATEWAY=${IPFS_GATEWAY} + - IPFS_PROJECT_ID=${IPFS_PROJECT_ID} logging: *logging restart: always healthcheck: diff --git a/scripts/govtool/metadata-validation.mk b/scripts/govtool/metadata-validation.mk index d9ab1a150..fb3352c59 100644 --- a/scripts/govtool/metadata-validation.mk +++ b/scripts/govtool/metadata-validation.mk @@ -13,6 +13,8 @@ metadata_validation_image_tag := $(shell git log -n 1 --format="%H" -- $(root_di build-metadata-validation: docker-login $(call check_image_on_ecr,metadata-validation,$(metadata_validation_image_tag)) || \ $(docker) build --tag "$(repo_url)/metadata-validation:$(metadata_validation_image_tag)" \ + --build-arg IPFS_GATEWAY="$${IPFS_GATEWAY}" \ + --build-arg IPFS_PROJECT_ID="$${IPFS_PROJECT_ID}" \ $(root_dir)/govtool/metadata-validation .PHONY: push-metadata-validation