Skip to content

Commit

Permalink
Merge pull request #115 from gfanton/feat/bump-ipfs-16
Browse files Browse the repository at this point in the history
  • Loading branch information
gfanton authored Nov 15, 2022
2 parents e9658b4 + 007f41d commit b503985
Show file tree
Hide file tree
Showing 44 changed files with 867 additions and 509 deletions.
17 changes: 8 additions & 9 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ jobs:
strategy:
matrix:
golang:
- 1.17.x
- 1.18.x
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.golang }}
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.1.0
uses: golangci/golangci-lint-action@v3.3.0
with:
go-version: ${{ matrix.golang }}
version: v1.44.2
version: v1.50.1
args: --timeout=10m
# only-new-issues: true


go-tests-on-linux:
runs-on: ubuntu-latest
strategy:
matrix:
golang:
- 1.16.x
- 1.17.x
#- tip
- 1.18.x
- 1.19.x
env:
OS: ubuntu-latest
GOLANG: ${{ matrix.golang }}
Expand Down Expand Up @@ -84,9 +84,8 @@ jobs:
strategy:
matrix:
golang:
- 1.16.x
- 1.17.x
#- tip
- 1.18.x
- 1.19.x
env:
OS: macos-latest
GOLANG: ${{ matrix.golang }}
Expand Down
8 changes: 2 additions & 6 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@ linters:
enable:
- goconst
- misspell
- deadcode
- misspell
- structcheck
- errcheck
- unused
- varcheck
- staticcheck
- unconvert
- gofmt
#- goimports # disabling goimports while we can't configure it to ignore vendors (github.com/whyrusleeping/go-logging seems to be badly formated)
- golint
- goimports
- revive
- ineffassign
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
golang 1.18
29 changes: 14 additions & 15 deletions accesscontroller/ipfs/accesscontroller_ipfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
cid "github.com/ipfs/go-cid"
cbornode "github.com/ipfs/go-ipld-cbor"
coreapi "github.com/ipfs/interface-go-ipfs-core"
"github.com/pkg/errors"
"github.com/polydawn/refmt/obj/atlas"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -50,7 +49,7 @@ func (i *ipfsAccessController) CanAppend(entry logac.LogEntry, p identityprovide
}
}

return errors.New("not allowed")
return fmt.Errorf("not allowed")
}

func (i *ipfsAccessController) GetAuthorizedByRole(role string) ([]string, error) {
Expand All @@ -65,46 +64,46 @@ func (i *ipfsAccessController) GetAuthorizedByRole(role string) ([]string, error
}

func (i *ipfsAccessController) Grant(ctx context.Context, capability string, keyID string) error {
return errors.New("not implemented - does not exist in JS version")
return fmt.Errorf("not implemented - does not exist in JS version")
}

func (i *ipfsAccessController) Revoke(ctx context.Context, capability string, keyID string) error {
return errors.New("not implemented - does not exist in JS version")
return fmt.Errorf("not implemented - does not exist in JS version")
}

func (i *ipfsAccessController) Load(ctx context.Context, address string) error {
i.logger.Debug(fmt.Sprintf("reading IPFS access controller write access on hash %s", address))

c, err := cid.Decode(address)
if err != nil {
return errors.Wrap(err, "unable to parse cid")
return fmt.Errorf("unable to parse cid: %w", err)
}

res, err := io.ReadCBOR(ctx, i.ipfs, c)
if err != nil {
return errors.Wrap(err, "unable to load access controller manifest data")
return fmt.Errorf("unable to load access controller manifest data: %w", err)
}

manifest := &accesscontroller.Manifest{}
err = cbornode.DecodeInto(res.RawData(), manifest)
if err != nil {
return errors.Wrap(err, "unable to unmarshal access controller manifest data")
return fmt.Errorf("unable to unmarshal access controller manifest data: %w", err)
}

res, err = io.ReadCBOR(ctx, i.ipfs, manifest.Params.GetAddress())
if err != nil {
return errors.Wrap(err, "unable to load access controller data")
return fmt.Errorf("unable to load access controller data: %w", err)
}

writeAccessData := &cborWriteAccess{}
err = cbornode.DecodeInto(res.RawData(), writeAccessData)
if err != nil {
return errors.Wrap(err, "unable to unmarshal access controller data")
return fmt.Errorf("unable to unmarshal access controller data: %w", err)
}

var writeAccess []string
if err := json.Unmarshal([]byte(writeAccessData.Write), &writeAccess); err != nil {
return errors.Wrap(err, "unable to unmarshal json write access")
return fmt.Errorf("unable to unmarshal json write access: %w", err)
}

i.muWriteAccess.Lock()
Expand All @@ -120,12 +119,12 @@ func (i *ipfsAccessController) Save(ctx context.Context) (accesscontroller.Manif
i.muWriteAccess.RUnlock()

if err != nil {
return nil, errors.Wrap(err, "unable to serialize write access")
return nil, fmt.Errorf("unable to serialize write access: %w", err)
}

c, err := io.WriteCBOR(ctx, i.ipfs, &cborWriteAccess{Write: string(writeAccess)}, nil)
if err != nil {
return nil, errors.Wrap(err, "unable to save access controller")
return nil, fmt.Errorf("unable to save access controller: %w", err)
}

i.logger.Debug(fmt.Sprintf("saved IPFS access controller write access on hash %s", c.String()))
Expand All @@ -134,17 +133,17 @@ func (i *ipfsAccessController) Save(ctx context.Context) (accesscontroller.Manif
}

func (i *ipfsAccessController) Close() error {
return errors.New("not implemented - does not exist in JS version")
return fmt.Errorf("not implemented - does not exist in JS version")
}

// NewIPFSAccessController Returns an access controller for IPFS
func NewIPFSAccessController(_ context.Context, db iface.BaseOrbitDB, params accesscontroller.ManifestParams, options ...accesscontroller.Option) (accesscontroller.Interface, error) {
if params == nil {
return &ipfsAccessController{}, errors.New("an options object must be passed")
return &ipfsAccessController{}, fmt.Errorf("an options object must be passed")
}

if db == nil {
return &ipfsAccessController{}, errors.New("an OrbitDB instance is required")
return &ipfsAccessController{}, fmt.Errorf("an OrbitDB instance is required")
}

if len(params.GetAccess("write")) == 0 {
Expand Down
10 changes: 5 additions & 5 deletions accesscontroller/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package accesscontroller

import (
"context"
"fmt"
"strings"
"sync"

"berty.tech/go-ipfs-log/io"
cid "github.com/ipfs/go-cid"
cbornode "github.com/ipfs/go-ipld-cbor"
coreapi "github.com/ipfs/interface-go-ipfs-core"
"github.com/pkg/errors"
"github.com/polydawn/refmt/obj/atlas"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -160,7 +160,7 @@ func CreateManifest(ctx context.Context, ipfs coreapi.CoreAPI, controllerType st
func ResolveManifest(ctx context.Context, ipfs coreapi.CoreAPI, manifestAddress string, params ManifestParams) (*Manifest, error) {
if params.GetSkipManifest() {
if params.GetType() == "" {
return nil, errors.New("no manifest, access-controller type required")
return nil, fmt.Errorf("no manifest, access-controller type required")
}

manifest := &Manifest{
Expand All @@ -177,18 +177,18 @@ func ResolveManifest(ctx context.Context, ipfs coreapi.CoreAPI, manifestAddress

c, err := cid.Decode(manifestAddress)
if err != nil {
return nil, errors.Wrap(err, "unable to parse CID")
return nil, fmt.Errorf("unable to parse CID: %w", err)
}

node, err := io.ReadCBOR(ctx, ipfs, c)
if err != nil {
return nil, errors.Wrap(err, "unable to fetch manifest data")
return nil, fmt.Errorf("unable to fetch manifest data: %w", err)
}

manifest := &Manifest{}
err = cbornode.DecodeInto(node.RawData(), &manifest)
if err != nil {
return nil, errors.Wrap(err, "unable to unmarshal")
return nil, fmt.Errorf("unable to unmarshal: %w", err)
}

return manifest, nil
Expand Down
Loading

0 comments on commit b503985

Please sign in to comment.