Skip to content

Commit

Permalink
GetAttr implementation in eosgrpc
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Jan 14, 2022
1 parent 273718c commit d1cd5fc
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/cs3org/reva/pkg/eosclient"

erpc "github.com/cs3org/reva/pkg/eosclient/eosgrpc/eos_grpc"
eos "github.com/cs3org/reva/pkg/eosclient/utils"
"github.com/cs3org/reva/pkg/errtypes"
"github.com/cs3org/reva/pkg/logger"
"github.com/cs3org/reva/pkg/storage/utils/acl"
Expand Down Expand Up @@ -617,8 +618,40 @@ func (c *Client) UnsetAttr(ctx context.Context, auth eosclient.Authorization, at
}

// GetAttr returns the attribute specified by key
func (c *Client) GetAttr(ctx context.Context, auth eosclient.Authorization, name, path string) (*eosclient.Attribute, error) {
return nil, errtypes.NotSupported("GetAttr function not yet implemented")
func (c *Client) GetAttr(ctx context.Context, auth eosclient.Authorization, key, path string) (*eosclient.Attribute, error) {
info, err := c.GetFileInfoByPath(ctx, auth, path)
if err != nil {
return nil, err
}

for k, v := range info.Attrs {
if k == key {
attr, err := getAttribute(k, v)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("eosgrpc: cannot parse attribute key=%s value=%s", k, v))
}
return attr, nil
}
}
return nil, errtypes.NotFound(fmt.Sprintf("key %s not found", key))
}

func getAttribute(key, val string) (*eosclient.Attribute, error) {
// key is in the form sys.forced.checksum
type2key := strings.SplitN(key, ".", 2) // type2key = ["sys", "forced.checksum"]
if len(type2key) != 2 {
return nil, errtypes.InternalError("wrong attr format to deserialize")
}
t, err := eos.AttrStringToType(type2key[0])
if err != nil {
return nil, err
}
attr := &eosclient.Attribute{
Type: t,
Key: type2key[1],
Val: val,
}
return attr, nil
}

// GetFileInfoByPath returns the FilInfo at the given path
Expand Down

0 comments on commit d1cd5fc

Please sign in to comment.