diff --git a/pkg/args/args.go b/pkg/args/args.go index eddb9cc..3cee3ce 100644 --- a/pkg/args/args.go +++ b/pkg/args/args.go @@ -4,6 +4,7 @@ package args import ( + "errors" "fmt" "iter" "sort" @@ -18,6 +19,8 @@ import ( "github.com/ucan-wg/go-ucan/pkg/policy/literal" ) +var ErrNotFound = errors.New("key not found in meta") + // Args are the Command's arguments when an invocation Token is processed by the executor. // This also serves as a way to construct the underlying IPLD data with minimum allocations // and transformations, while hiding the IPLD complexity from the caller. @@ -36,6 +39,16 @@ func New() *Args { } } +// GetNode retrieves a value as a raw IPLD node. +// Returns ErrNotFound if the given key is missing. +func (a *Args) GetNode(key string) (ipld.Node, error) { + v, ok := a.Values[key] + if !ok { + return nil, ErrNotFound + } + return v, nil +} + // Add inserts a key/value pair in the Args set. // // Accepted types for val are any CBOR compatible type, or directly IPLD values. diff --git a/pkg/args/readonly.go b/pkg/args/readonly.go index 3cb8428..62c6587 100644 --- a/pkg/args/readonly.go +++ b/pkg/args/readonly.go @@ -10,6 +10,10 @@ type ReadOnly struct { args *Args } +func (r ReadOnly) GetNode(key string) (ipld.Node, error) { + return r.args.GetNode(key) +} + func (r ReadOnly) Iter() iter.Seq2[string, ipld.Node] { return r.args.Iter() } diff --git a/pkg/meta/meta.go b/pkg/meta/meta.go index 4ce89a9..3c54738 100644 --- a/pkg/meta/meta.go +++ b/pkg/meta/meta.go @@ -121,7 +121,6 @@ func (m *Meta) GetEncryptedBytes(key string, encryptionKey []byte) ([]byte, erro // GetNode retrieves a value as a raw IPLD node. // Returns ErrNotFound if the given key is missing. -// Returns datamodel.ErrWrongKind if the value has the wrong type. func (m *Meta) GetNode(key string) (ipld.Node, error) { v, ok := m.Values[key] if !ok {