Skip to content

Commit

Permalink
feat: add handing of Infura credentials (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
banciur authored Apr 8, 2022
1 parent 4da0b6c commit b8083cf
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
8 changes: 7 additions & 1 deletion md/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,15 @@ Will pin `QmHash` to Pinata and Infura.

Infura is a freemium pinning service that doesn't require any additional setup.
It's the default one used. Please bear in mind that Infura is a free service, so
there is probably a rate-limiting.
there is probably a rate-limiting.

Env variables are optional for users that want to use their own Infura account.


- Usage: `-p infura`
- Environment variables
- `IPFS_DEPLOY_INFURA__PROJECT_ID=<Infura Project ID>`
- `IPFS_DEPLOY_INFURA__PROJECT_SECRET=<nfura Project Secret>`

### [DAppNode](https://dappnode.io)

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"ipfs-http-client": "^50.1.0",
"it-all": "^1.0.6",
"lodash.isempty": "^4.4.0",
"lodash.isstring": "^4.0.1",
"open": "^8.4.0",
"terminal-link": "^2.1.1",
"trammel": "^5.0.0",
Expand All @@ -87,6 +88,7 @@
},
"devDependencies": {
"@types/lodash.isempty": "^4.4.6",
"@types/lodash.isstring": "^4.0.1",
"@types/proxyquire": "^1.3.28",
"aegir": "^33.2.0",
"proxyquire": "^2.1.3"
Expand Down
4 changes: 4 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ const options = {
},

pinningServicesCredentials: {
infura: {
projectId: argv.infura && argv.infura.projectId,
projectSecret: argv.infura && argv.infura.projectSecret
},
pinata: {
apiKey: argv.pinata && argv.pinata.apiKey,
secretApiKey: argv.pinata && argv.pinata.secretApiKey
Expand Down
21 changes: 18 additions & 3 deletions src/pinners/infura.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
'use strict'

const isString = require('lodash.isstring')
const IpfsNode = require('./ipfs-node')

/**
* @typedef {import('ipfs-http-client').Options} IpfsOptions
* @typedef {import('./types').InfuraOptions} InfuraOptions
*/

class Infura extends IpfsNode {
constructor () {
super({
/**
* @param {InfuraOptions} options
*/
constructor ({ projectId, projectSecret }) {
/** @type {IpfsOptions} */
const options = {
host: 'ipfs.infura.io',
port: 5001,
protocol: 'https'
})
}
if ([projectId, projectSecret].every(isString)) {
const authorization = 'Basic ' + Buffer.from(projectId + ':' + projectSecret).toString('base64')
options.headers = { authorization }
}
super(options)
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/pinners/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export interface IPFSClusterOptions {
password: string
}

export interface InfuraOptions {
projectId?: string
projectSecret?: string
}

export interface PinataOptions {
apiKey: string
secretApiKey: string
Expand Down

0 comments on commit b8083cf

Please # to comment.