Skip to content

Commit

Permalink
Merge pull request #29 from ucan-wg/feat/reorganize-packages
Browse files Browse the repository at this point in the history
feat: reorganize packages
  • Loading branch information
smoyer64 authored Sep 24, 2024
2 parents 6161f2e + 93dd3ef commit 4a65550
Show file tree
Hide file tree
Showing 37 changed files with 61 additions and 22 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/ucan-wg/go-ucan/capability/command"
"github.com/ucan-wg/go-ucan/pkg/command"
)

func TestTop(t *testing.T) {
Expand Down
18 changes: 17 additions & 1 deletion pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ package meta

import (
"errors"
"fmt"
"reflect"

"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/node/basicnode"
)

var ErrUnsupported = errors.New("failure adding unsupported type to meta")

var ErrNotFound = errors.New("key-value not found in meta")

// Meta is a container for meta key-value pairs in a UCAN token.
Expand Down Expand Up @@ -113,8 +117,20 @@ func (m *Meta) Add(key string, val any) error {
case datamodel.Node:
m.Values[key] = val
default:
panic("invalid value type")
return fmt.Errorf("%w: %s", ErrUnsupported, fqtn(val))
}
m.Keys = append(m.Keys, key)
return nil
}

func fqtn(val any) string {
var name string

t := reflect.TypeOf(val)
for t.Kind() == reflect.Pointer {
name += "*"
t = t.Elem()
}

return name + t.PkgPath() + "." + t.Name()
}
23 changes: 23 additions & 0 deletions pkg/meta/meta_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package meta_test

import (
"testing"

"github.com/stretchr/testify/require"
"github.com/ucan-wg/go-ucan/pkg/meta"
"gotest.tools/v3/assert"
)

func TestMeta_Add(t *testing.T) {
t.Parallel()

type Unsupported struct{}

t.Run("error if not primative or Node", func(t *testing.T) {
t.Parallel()

err := (&meta.Meta{}).Add("invalid", &Unsupported{})
require.ErrorIs(t, err, meta.ErrUnsupported)
assert.ErrorContains(t, err, "*github.com/ucan-wg/go-ucan/pkg/meta_test.Unsupported")
})
}
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion capability/policy/ipld.go → pkg/policy/ipld.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/ipld/go-ipld-prime/must"
"github.com/ipld/go-ipld-prime/node/basicnode"

"github.com/ucan-wg/go-ucan/capability/policy/selector"
"github.com/ucan-wg/go-ucan/pkg/policy/selector"
)

func FromIPLD(node datamodel.Node) (Policy, error) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion capability/policy/match.go → pkg/policy/match.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/ipld/go-ipld-prime/datamodel"
"github.com/ipld/go-ipld-prime/must"

"github.com/ucan-wg/go-ucan/capability/policy/selector"
"github.com/ucan-wg/go-ucan/pkg/policy/selector"
)

// Match determines if the IPLD node matches the policy document.
Expand Down
4 changes: 2 additions & 2 deletions capability/policy/match_test.go → pkg/policy/match_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/ipld/go-ipld-prime/node/basicnode"
"github.com/stretchr/testify/require"

"github.com/ucan-wg/go-ucan/capability/policy/literal"
"github.com/ucan-wg/go-ucan/capability/policy/selector"
"github.com/ucan-wg/go-ucan/pkg/policy/literal"
"github.com/ucan-wg/go-ucan/pkg/policy/selector"
)

func TestMatch(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion capability/policy/policy.go → pkg/policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package policy
import (
"github.com/ipld/go-ipld-prime"

"github.com/ucan-wg/go-ucan/capability/policy/selector"
"github.com/ucan-wg/go-ucan/pkg/policy/selector"
)

const (
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ucan-wg/go-ucan/capability/policy/selector"
"github.com/ucan-wg/go-ucan/pkg/policy/selector"
)

// TestSupported Forms runs tests against the Selector according to the
Expand Down
4 changes: 2 additions & 2 deletions delegation/delegation.go → tokens/delegation/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p/core/crypto"

"github.com/ucan-wg/go-ucan/capability/command"
"github.com/ucan-wg/go-ucan/capability/policy"
"github.com/ucan-wg/go-ucan/did"
"github.com/ucan-wg/go-ucan/pkg/command"
"github.com/ucan-wg/go-ucan/pkg/meta"
"github.com/ucan-wg/go-ucan/pkg/policy"
)

// Token is an immutable type that holds the fields of a UCAN delegation.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/stretchr/testify/require"
"gotest.tools/v3/golden"

"github.com/ucan-wg/go-ucan/capability/command"
"github.com/ucan-wg/go-ucan/capability/policy"
"github.com/ucan-wg/go-ucan/delegation"
"github.com/ucan-wg/go-ucan/did"
"github.com/ucan-wg/go-ucan/pkg/command"
"github.com/ucan-wg/go-ucan/pkg/policy"
"github.com/ucan-wg/go-ucan/tokens/delegation"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion delegation/ipld.go → tokens/delegation/ipld.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/libp2p/go-libp2p/core/crypto"

"github.com/ucan-wg/go-ucan/did"
"github.com/ucan-wg/go-ucan/internal/envelope"
"github.com/ucan-wg/go-ucan/tokens/internal/envelope"
)

// ToSealed wraps the delegation token in an envelope, generates the
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion delegation/schema.go → tokens/delegation/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/ipld/go-ipld-prime/node/bindnode"
"github.com/ipld/go-ipld-prime/schema"

"github.com/ucan-wg/go-ucan/internal/envelope"
"github.com/ucan-wg/go-ucan/pkg/meta"
"github.com/ucan-wg/go-ucan/tokens/internal/envelope"
)

// [Tag] is the string used as a key within the SigPayload that identifies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/stretchr/testify/require"
"gotest.tools/v3/golden"

"github.com/ucan-wg/go-ucan/delegation"
"github.com/ucan-wg/go-ucan/internal/envelope"
"github.com/ucan-wg/go-ucan/tokens/delegation"
"github.com/ucan-wg/go-ucan/tokens/internal/envelope"
)

//go:embed delegation.ipldsch
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
"gotest.tools/v3/golden"

"github.com/ucan-wg/go-ucan/internal/envelope"
"github.com/ucan-wg/go-ucan/tokens/internal/envelope"
)

func TestCidFromBytes(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/ipld/go-ipld-prime/schema"
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/stretchr/testify/require"
"github.com/ucan-wg/go-ucan/internal/envelope"
"github.com/ucan-wg/go-ucan/tokens/internal/envelope"
"gotest.tools/v3/golden"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
"github.com/libp2p/go-libp2p/core/crypto"

"github.com/ucan-wg/go-ucan/did"
"github.com/ucan-wg/go-ucan/internal/varsig"
"github.com/ucan-wg/go-ucan/tokens/internal/varsig"
)

const varsigHeaderKey = "h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ucan-wg/go-ucan/internal/envelope"
"github.com/ucan-wg/go-ucan/tokens/internal/envelope"
"gotest.tools/v3/golden"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/libp2p/go-libp2p/core/crypto/pb"
"github.com/stretchr/testify/assert"

"github.com/ucan-wg/go-ucan/internal/varsig"
"github.com/ucan-wg/go-ucan/tokens/internal/varsig"
)

func TestDecode(t *testing.T) {
Expand Down

0 comments on commit 4a65550

Please sign in to comment.