diff --git a/pkg/eosclient/eosbinary/eosbinary.go b/pkg/eosclient/eosbinary/eosbinary.go index 2e8735cec0..71c8ee3bfc 100644 --- a/pkg/eosclient/eosbinary/eosbinary.go +++ b/pkg/eosclient/eosbinary/eosbinary.go @@ -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 @@ -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, } @@ -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", } @@ -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, } @@ -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 } diff --git a/pkg/eosclient/eosgrpc/eosgrpc.go b/pkg/eosclient/eosgrpc/eosgrpc.go index 25e9d6ace6..a6e1f729c7 100644 --- a/pkg/eosclient/eosgrpc/eosgrpc.go +++ b/pkg/eosclient/eosgrpc/eosgrpc.go @@ -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" @@ -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 } diff --git a/pkg/eosclient/utils.go b/pkg/eosclient/utils.go new file mode 100644 index 0000000000..8b04ebfb99 --- /dev/null +++ b/pkg/eosclient/utils.go @@ -0,0 +1,40 @@ +// Copyright 2018-2021 CERN +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// In applying this license, CERN does not waive the privileges and immunities +// granted to it by virtue of its status as an Intergovernmental Organization +// or submit itself to any jurisdiction. + +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") + } +}