Skip to content

Commit

Permalink
Merge pull request #2377 from IntersectMBO/feat/1616-support-ipfs-in-…
Browse files Browse the repository at this point in the history
…govtool

feat(#1616): add support for ipfs in metadata validation service
  • Loading branch information
MSzalowski authored Nov 18, 2024
2 parents 1d96a73 + a12a948 commit ac6ba3d
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build-and-deploy-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-and-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-and-deploy-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-and-deploy-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion govtool/metadata-validation/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
PORT=3000
PORT=3000
IPFS_GATEWAY=https://ipfs.some.gateway
IPFS_PROJECT_ID=ipfsprojectid
3 changes: 3 additions & 0 deletions govtool/metadata-validation/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
FROM node:lts-hydrogen

ARG IPFS_GATEWAY
ARG IPFS_PROJECT_ID

WORKDIR /dist

COPY package*.json ./
Expand Down
2 changes: 2 additions & 0 deletions govtool/metadata-validation/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 22 additions & 7 deletions govtool/metadata-validation/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,30 @@ export class AppService {
let metadata: Record<string, unknown>;
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;
Expand Down
2 changes: 2 additions & 0 deletions scripts/govtool/config/templates/docker-compose.yml.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ services:
image: <REPO_URL>/metadata-validation:${METADATA_VALIDATION_TAG}
environment:
- PORT=3000
- IPFS_GATEWAY=${IPFS_GATEWAY}
- IPFS_PROJECT_ID=${IPFS_PROJECT_ID}
logging: *logging
restart: always
healthcheck:
Expand Down
2 changes: 2 additions & 0 deletions scripts/govtool/metadata-validation.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ac6ba3d

Please sign in to comment.