Skip to content

Commit

Permalink
Move same eos logic in a common package
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed Jan 31, 2022
1 parent 0d5b15a commit 2be4212
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
32 changes: 7 additions & 25 deletions pkg/eosclient/eosbinary/eosbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,42 +48,24 @@ const (
userACLEvalKey = "eval.useracl"
)

const (
// SystemAttr is the system extended attribute.
SystemAttr eosclient.AttrType = iota
// UserAttr is the user extended attribute.
UserAttr
)

func serializeAttribute(a *eosclient.Attribute) string {
return fmt.Sprintf("%s.%s=%s", attrTypeToString(a.Type), a.Key, a.Val)
}

func attrTypeToString(at eosclient.AttrType) string {
switch at {
case SystemAttr:
case eosclient.SystemAttr:
return "sys"
case UserAttr:
case eosclient.UserAttr:
return "user"
default:
return "invalid"
}
}

func attrStringToType(t string) (eosclient.AttrType, error) {
switch t {
case "sys":
return SystemAttr, nil
case "user":
return UserAttr, nil
default:
return 0, errtypes.InternalError("attr type not existing")
}
}

func isValidAttribute(a *eosclient.Attribute) bool {
// validate that an attribute is correct.
if (a.Type != SystemAttr && a.Type != UserAttr) || a.Key == "" {
if (a.Type != eosclient.SystemAttr && a.Type != eosclient.UserAttr) || a.Key == "" {
return false
}
return true
Expand Down Expand Up @@ -312,7 +294,7 @@ func (c *Client) AddACL(ctx context.Context, auth, rootAuth eosclient.Authorizat
sysACL = a.CitrineSerialize()
}
sysACLAttr := &eosclient.Attribute{
Type: SystemAttr,
Type: eosclient.SystemAttr,
Key: lwShareAttrKey,
Val: sysACL,
}
Expand All @@ -330,7 +312,7 @@ func (c *Client) AddACL(ctx context.Context, auth, rootAuth eosclient.Authorizat
} else {
args = append(args, "--user")
userACLAttr := &eosclient.Attribute{
Type: SystemAttr,
Type: eosclient.SystemAttr,
Key: userACLEvalKey,
Val: "1",
}
Expand Down Expand Up @@ -376,7 +358,7 @@ func (c *Client) RemoveACL(ctx context.Context, auth, rootAuth eosclient.Authori
sysACL = a.CitrineSerialize()
}
sysACLAttr := &eosclient.Attribute{
Type: SystemAttr,
Type: eosclient.SystemAttr,
Key: lwShareAttrKey,
Val: sysACL,
}
Expand Down Expand Up @@ -588,7 +570,7 @@ func deserializeAttribute(attrStr string) (*eosclient.Attribute, error) {
if len(type2key) != 2 {
return nil, errtypes.InternalError("wrong attr format to deserialize")
}
t, err := attrStringToType(type2key[0])
t, err := eosclient.AttrStringToType(type2key[0])
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/eosclient/eosgrpc/eosgrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ import (
"syscall"

"github.com/cs3org/reva/pkg/appctx"
"github.com/cs3org/reva/pkg/eosclient"

"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 @@ -642,7 +641,7 @@ func getAttribute(key, val string) (*eosclient.Attribute, error) {
if len(type2key) != 2 {
return nil, errtypes.InternalError("wrong attr format to deserialize")
}
t, err := eos.AttrStringToType(type2key[0])
t, err := eosclient.AttrStringToType(type2key[0])
if err != nil {
return nil, err
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/eosclient/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package eosclient

import "github.com/cs3org/reva/pkg/errtypes"

const (
// SystemAttr is the system extended attribute.
SystemAttr AttrType = iota
// UserAttr is the user extended attribute.
UserAttr
)

// AttrStringToType converts a string to an AttrType
func AttrStringToType(t string) (AttrType, error) {
switch t {
case "sys":
return SystemAttr, nil
case "user":
return UserAttr, nil
default:
return 0, errtypes.InternalError("attr type not existing")
}
}

0 comments on commit 2be4212

Please sign in to comment.