github.com/cs3org/reva/v2@v2.27.7/pkg/eosclient/utils.go (about)

     1  // Copyright 2018-2021 CERN
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  //
    15  // In applying this license, CERN does not waive the privileges and immunities
    16  // granted to it by virtue of its status as an Intergovernmental Organization
    17  // or submit itself to any jurisdiction.
    18  
    19  package eosclient
    20  
    21  import (
    22  	"fmt"
    23  
    24  	"github.com/cs3org/reva/v2/pkg/errtypes"
    25  )
    26  
    27  const (
    28  	// SystemAttr is the system extended attribute.
    29  	SystemAttr AttrType = iota
    30  	// UserAttr is the user extended attribute.
    31  	UserAttr
    32  )
    33  
    34  // AttrStringToType converts a string to an AttrType
    35  func AttrStringToType(t string) (AttrType, error) {
    36  	switch t {
    37  	case "sys":
    38  		return SystemAttr, nil
    39  	case "user":
    40  		return UserAttr, nil
    41  	default:
    42  		return 0, errtypes.InternalError("attr type not existing")
    43  	}
    44  }
    45  
    46  // AttrTypeToString converts a type to a string representation.
    47  func AttrTypeToString(at AttrType) string {
    48  	switch at {
    49  	case SystemAttr:
    50  		return "sys"
    51  	case UserAttr:
    52  		return "user"
    53  	default:
    54  		return "invalid"
    55  	}
    56  }
    57  
    58  // GetKey returns the key considering the type of attribute.
    59  func (a *Attribute) GetKey() string {
    60  	return fmt.Sprintf("%s.%s", AttrTypeToString(a.Type), a.Key)
    61  }