Skip to content

Commit

Permalink
feat: Use IFPS gateways instead of ipfs shell (#502)
Browse files Browse the repository at this point in the history
* fix: No not use ipfs shell to download ipfs files.

* fix: Upload context file to testbed
  • Loading branch information
x1m3 authored Oct 9, 2023
1 parent caa6e8a commit 54c52c1
Show file tree
Hide file tree
Showing 15 changed files with 48 additions and 26 deletions.
5 changes: 2 additions & 3 deletions cmd/notifications/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"syscall"

vault "github.com/hashicorp/vault/api"
"github.com/iden3/go-schema-processor/v2/loaders"
shell "github.com/ipfs/go-ipfs-api"

"github.com/polygonid/sh-id-platform/internal/buildinfo"
"github.com/polygonid/sh-id-platform/internal/config"
Expand All @@ -19,6 +17,7 @@ import (
"github.com/polygonid/sh-id-platform/internal/db"
"github.com/polygonid/sh-id-platform/internal/gateways"
"github.com/polygonid/sh-id-platform/internal/kms"
"github.com/polygonid/sh-id-platform/internal/loader"
"github.com/polygonid/sh-id-platform/internal/log"
"github.com/polygonid/sh-id-platform/internal/providers"
"github.com/polygonid/sh-id-platform/internal/redis"
Expand Down Expand Up @@ -132,7 +131,7 @@ func newCredentialsService(cfg *config.Configuration, storage *db.Storage, cache
rhsp := reverse_hash.NewRhsPublisher(nil, false)

// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loaders.NewDocumentLoader(shell.NewShell(cfg.IPFS.GatewayURL), cfg.IPFS.GatewayURL)
schemaLoader := loader.NewDocumentLoader(cfg.IPFS.GatewayURL)

mtService := services.NewIdentityMerkleTrees(mtRepository)
qrService := services.NewQrStoreService(cachex)
Expand Down
5 changes: 2 additions & 3 deletions cmd/pending_publisher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
vault "github.com/hashicorp/vault/api"
"github.com/iden3/go-schema-processor/v2/loaders"
shell "github.com/ipfs/go-ipfs-api"

"github.com/polygonid/sh-id-platform/internal/buildinfo"
"github.com/polygonid/sh-id-platform/internal/config"
Expand All @@ -21,6 +19,7 @@ import (
"github.com/polygonid/sh-id-platform/internal/db"
"github.com/polygonid/sh-id-platform/internal/gateways"
"github.com/polygonid/sh-id-platform/internal/kms"
"github.com/polygonid/sh-id-platform/internal/loader"
"github.com/polygonid/sh-id-platform/internal/log"
"github.com/polygonid/sh-id-platform/internal/providers"
"github.com/polygonid/sh-id-platform/internal/redis"
Expand Down Expand Up @@ -75,7 +74,7 @@ func main() {
}(storage)

// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loaders.NewDocumentLoader(shell.NewShell(cfg.IPFS.GatewayURL), cfg.IPFS.GatewayURL)
schemaLoader := loader.NewDocumentLoader(cfg.IPFS.GatewayURL)

var vaultCli *vault.Client
var vaultErr error
Expand Down
5 changes: 2 additions & 3 deletions cmd/platform/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
"github.com/go-chi/cors"
redis2 "github.com/go-redis/redis/v8"
vault "github.com/hashicorp/vault/api"
"github.com/iden3/go-schema-processor/v2/loaders"
proof "github.com/iden3/merkletree-proof"
shell "github.com/ipfs/go-ipfs-api"

"github.com/polygonid/sh-id-platform/internal/api"
"github.com/polygonid/sh-id-platform/internal/buildinfo"
Expand All @@ -27,6 +25,7 @@ import (
"github.com/polygonid/sh-id-platform/internal/gateways"
"github.com/polygonid/sh-id-platform/internal/health"
"github.com/polygonid/sh-id-platform/internal/kms"
"github.com/polygonid/sh-id-platform/internal/loader"
"github.com/polygonid/sh-id-platform/internal/log"
"github.com/polygonid/sh-id-platform/internal/providers"
"github.com/polygonid/sh-id-platform/internal/providers/blockchain"
Expand Down Expand Up @@ -75,7 +74,7 @@ func main() {
cachex := cache.NewRedisCache(rdb)

// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loaders.NewDocumentLoader(shell.NewShell(cfg.IPFS.GatewayURL), cfg.IPFS.GatewayURL)
schemaLoader := loader.NewDocumentLoader(cfg.IPFS.GatewayURL)

var vaultCli *vault.Client
var vaultErr error
Expand Down
5 changes: 2 additions & 3 deletions cmd/platform_ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import (
"github.com/iden3/go-iden3-auth/v2/pubsignals"
"github.com/iden3/go-iden3-auth/v2/state"
"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/iden3/go-schema-processor/v2/loaders"
proof "github.com/iden3/merkletree-proof"
shell "github.com/ipfs/go-ipfs-api"

"github.com/polygonid/sh-id-platform/internal/api_ui"
"github.com/polygonid/sh-id-platform/internal/buildinfo"
Expand All @@ -34,6 +32,7 @@ import (
"github.com/polygonid/sh-id-platform/internal/gateways"
"github.com/polygonid/sh-id-platform/internal/health"
"github.com/polygonid/sh-id-platform/internal/kms"
"github.com/polygonid/sh-id-platform/internal/loader"
"github.com/polygonid/sh-id-platform/internal/log"
"github.com/polygonid/sh-id-platform/internal/providers"
"github.com/polygonid/sh-id-platform/internal/providers/blockchain"
Expand Down Expand Up @@ -82,7 +81,7 @@ func main() {
cachex := cache.NewRedisCache(rdb)

// TODO: Cache only if cfg.APIUI.SchemaCache == true
schemaLoader := loaders.NewDocumentLoader(shell.NewShell(cfg.IPFS.GatewayURL), cfg.IPFS.GatewayURL)
schemaLoader := loader.NewDocumentLoader(cfg.IPFS.GatewayURL)

var vaultCli *vault.Client
var vaultErr error
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@


{
"@context": [
{
"@protected": true,
"@version": 1.1,
"id": "@id",
"type": "@type",
"testNewType": {
"@context": {
"@propagate": true,
"@protected": true,
"polygon-vocab": "urn:uuid:0a8092e3-7100-4068-ba67-fae502cc6e7b#",
"xsd": "http://www.w3.org/2001/XMLSchema#",
"testNewTypeInt": {
"@id": "polygon-vocab:testNewTypeInt",
"@type": "xsd:integer"
}
},
"@id": "urn:uuid:412d4b27-bae2-4c26-ac57-bacc141010d6"
}
}
]
}
5 changes: 2 additions & 3 deletions internal/api/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import (
"github.com/go-chi/chi/v5"
"github.com/hashicorp/vault/api"
"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/iden3/go-schema-processor/v2/loaders"
"github.com/iden3/iden3comm/v2"
shell "github.com/ipfs/go-ipfs-api"
"github.com/piprate/json-gold/ld"

"github.com/polygonid/sh-id-platform/internal/config"
Expand All @@ -20,6 +18,7 @@ import (
"github.com/polygonid/sh-id-platform/internal/db/tests"
"github.com/polygonid/sh-id-platform/internal/errors"
"github.com/polygonid/sh-id-platform/internal/kms"
"github.com/polygonid/sh-id-platform/internal/loader"
"github.com/polygonid/sh-id-platform/internal/log"
"github.com/polygonid/sh-id-platform/internal/providers"
"github.com/polygonid/sh-id-platform/pkg/cache"
Expand Down Expand Up @@ -84,7 +83,7 @@ func TestMain(m *testing.M) {

cfg.ServerUrl = "https://testing.env/"

schemaLoader = loaders.NewDocumentLoader(shell.NewShell(ipfsGatewayURL), "")
schemaLoader = loader.NewDocumentLoader(ipfsGatewayURL)

m.Run()
}
Expand Down
4 changes: 1 addition & 3 deletions internal/api_ui/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
"github.com/go-chi/chi/v5"
vaultApi "github.com/hashicorp/vault/api"
"github.com/iden3/go-iden3-core/v2/w3c"
"github.com/iden3/go-schema-processor/v2/loaders"
"github.com/iden3/iden3comm/v2"
shell "github.com/ipfs/go-ipfs-api"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -88,7 +86,7 @@ func TestMain(m *testing.M) {

cfg.ServerUrl = "https://testing.env/"

schemaLoader = loaders.NewDocumentLoader(shell.NewShell(ipfsGatewayURL), "")
schemaLoader = loader.NewDocumentLoader(ipfsGatewayURL)

m.Run()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

const (
CIConfigPath = "/home/runner/work/sh-id-platform/sh-id-platform/" // CIConfigPath variable contain the CI configuration path
ipfsGateway = "https://ipfs.io"
ipfsGateway = "https://cloudflare-ipfs.com"
)

// Configuration holds the project configuration
Expand Down
4 changes: 1 addition & 3 deletions internal/core/services/tests/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"testing"

"github.com/hashicorp/vault/api"
"github.com/iden3/go-schema-processor/v2/loaders"
shell "github.com/ipfs/go-ipfs-api"

"github.com/polygonid/sh-id-platform/internal/config"
"github.com/polygonid/sh-id-platform/internal/db"
Expand Down Expand Up @@ -76,7 +74,7 @@ func TestMain(m *testing.M) {
}
cachex = cache.NewMemoryCache()

docLoader = loaders.NewDocumentLoader(shell.NewShell(ipfsGatewayURL), "")
docLoader = loader.NewDocumentLoader(ipfsGatewayURL)

m.Run()
}
Expand Down
6 changes: 3 additions & 3 deletions internal/jsonschema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"context"
"testing"

"github.com/iden3/go-schema-processor/v2/loaders"
shell "github.com/ipfs/go-ipfs-api"
"github.com/stretchr/testify/assert"

"github.com/polygonid/sh-id-platform/internal/loader"
)

func TestValidateCredentialSubject(t *testing.T) {
const ipfsGatewayURL = "http://127.0.0.1:8080"
ctx := context.Background()
ld := loaders.NewDocumentLoader(shell.NewShell(ipfsGatewayURL), "")
ld := loader.NewDocumentLoader(ipfsGatewayURL)

type config struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion internal/loader/ipfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestIpfsCID(t *testing.T) {
},
},
{
url: "https://gateway.ipfs.io/ipfs/QmUrDHtC3fGYg1CqWzrgbxU5tXeQa4y323h277m6hXX84k",
url: "https://cloudflare-ipfs.com/ipfs/QmUrDHtC3fGYg1CqWzrgbxU5tXeQa4y323h277m6hXX84k",
expected: expected{
cid: "",
err: errors.New("invalid ipfs url"),
Expand Down
6 changes: 6 additions & 0 deletions internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package loader

import (
"github.com/iden3/go-schema-processor/processor"
"github.com/iden3/go-schema-processor/v2/loaders"
"github.com/piprate/json-gold/ld"
)

Expand All @@ -15,3 +16,8 @@ type Loader interface {

// Factory defines the interface that a loader constructor should satisfy
type Factory func(url string) Loader

// NewDocumentLoader returns a new ld.DocumentLoader that will use http ipfs gateway to download documents
func NewDocumentLoader(ipfsGateway string) ld.DocumentLoader {
return loaders.NewDocumentLoader(nil, ipfsGateway)
}

0 comments on commit 54c52c1

Please sign in to comment.