Skip to content

fix: update IPFS tasks to use environment variables from .env files #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

SaeeDawod
Copy link

@SaeeDawod SaeeDawod commented Mar 13, 2025

Summary by Sourcery

Update IPFS tasks to utilize environment variables from .env files, removing the need to fetch them from an external service, and simplify the IPFS client creation process.

Bug Fixes:

  • Fix the IPFS tasks to correctly use environment variables from .env files instead of fetching them from an external service.

Enhancements:

  • Simplify the IPFS client creation by directly using the SettleMint IPFS API endpoint from the .env file.

@SaeeDawod SaeeDawod requested a review from bl0up March 13, 2025 15:21
Copy link

sourcery-ai bot commented Mar 13, 2025

Reviewer's Guide by Sourcery

The pull request refactors IPFS task scripts to utilize environment variables from .env files, removing the need for dynamic environment fetching and simplifying the configuration process.

Class diagram for IPFS task refactoring

classDiagram
    class IPFSTask {
        +pinToNFTStorage(blob: Blob)
        +ipfsUpload(content: Buffer | Record<string, any>, pin?: true)
    }
    class IPFSCIDTask {
        +setAction(ipfspath: string)
    }
    class Environment {
        +nftStorageToken: String
        +btpIpfs: String
        +settlemintAccessToken: String
    }
    IPFSTask --> Environment : uses
    IPFSCIDTask --> Environment : uses
    note for Environment "Environment variables are now loaded from .env files"
Loading

File-Level Changes

Change Details Files
Refactor to use environment variables from .env files for IPFS tasks.
  • Removed dynamic fetching of environment variables from external service.
  • Replaced BTP_IPFS with SETTLEMINT_IPFS_API_ENDPOINT from .env file.
  • Updated error handling to prompt for 'settlemint connect' if IPFS node is not configured.
  • Changed IPFS client creation to use the new environment variable.
  • Replaced BTP_SERVICE_TOKEN with SETTLEMINT_ACCESS_TOKEN for authentication.
tasks/ipfs-upload-file.ts
tasks/ipfs-cid.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@github-actions github-actions bot added the fix label Mar 13, 2025
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @SaeeDawod - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟡 Review instructions: 3 issues found
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +32 to 38
// Create IPFS client with the API endpoint
const ipfsClient = create({
url: baseUrl,
url: btpIpfs,
headers: {
'x-auth-token': process.env.BTP_SERVICE_TOKEN!,
'x-auth-token': process.env.SETTLEMINT_ACCESS_TOKEN!,
},
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Validate the presence of SETTLEMINT_ACCESS_TOKEN

Since this token is critical for creating a valid IPFS client, consider adding a check to ensure that SETTLEMINT_ACCESS_TOKEN is set to prevent potential runtime issues.

Suggested change
// Create IPFS client with the API endpoint
const ipfsClient = create({
url: baseUrl,
url: btpIpfs,
headers: {
'x-auth-token': process.env.BTP_SERVICE_TOKEN!,
'x-auth-token': process.env.SETTLEMINT_ACCESS_TOKEN!,
},
});
// Validate that SETTLEMINT_ACCESS_TOKEN environment variable is set
const settlemintAccessToken = process.env.SETTLEMINT_ACCESS_TOKEN;
if (!settlemintAccessToken) {
throw new Error("Environment variable SETTLEMINT_ACCESS_TOKEN is not set.");
}
// Create IPFS client with the API endpoint
const ipfsClient = create({
url: btpIpfs,
headers: {
'x-auth-token': settlemintAccessToken,
},
});

import { nftStorageToken } from '../hardhat.config';

// NFT Storage token - ideally this would be in config or .env
const nftStorageToken = process.env.NFT_STORAGE_TOKEN || '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (review_instructions): Using an empty string as a fallback for the NFT storage token could lead to silent failures.

If the token is missing, the code will continue execution with an empty string and only fail later when trying to use it. Consider throwing an error immediately if the environment variable is not set to prevent potential issues downstream.

Review instructions:

Path patterns: **/*.ts

Instructions:
Always write correct, up to date, bug free, fully functional and working, secure, performant and efficient code.

headers: {
'x-auth-token': process.env.BTP_SERVICE_TOKEN!,
'x-auth-token': process.env.SETTLEMINT_ACCESS_TOKEN!,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (review_instructions): Using the non-null assertion operator (!) could lead to runtime errors if the token is missing.

The code assumes SETTLEMINT_ACCESS_TOKEN will always be defined. If this environment variable is missing, this will cause a runtime error. Consider adding a check for this token's existence before creating the IPFS client, similar to how you check for the IPFS endpoint.

Review instructions:

Path patterns: **/*.ts

Instructions:
Always write correct, up to date, bug free, fully functional and working, secure, performant and efficient code.

headers: {
'x-auth-token': process.env.BTP_SERVICE_TOKEN!,
'x-auth-token': process.env.SETTLEMINT_ACCESS_TOKEN!,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (review_instructions): Using the non-null assertion operator (!) could lead to runtime errors if the token is missing.

The code assumes SETTLEMINT_ACCESS_TOKEN will always be defined. If this environment variable is missing, this will cause a runtime error. Consider adding a check for this token's existence before creating the IPFS client, similar to how you check for the IPFS endpoint.

Review instructions:

Path patterns: **/*.ts

Instructions:
Always write correct, up to date, bug free, fully functional and working, secure, performant and efficient code.

Copy link

📦 Packages

Package Install
Template Set bun add @settlemint/settlemint/solidity-token-erc721-generative-art@7.12.0-pre8aa8a8

@bl0up bl0up merged commit e5ba9eb into main Mar 14, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants