github.com/cs3org/reva/v2@v2.27.7/pkg/auth/scope/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 scope 20 21 import ( 22 "fmt" 23 "strings" 24 25 authpb "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1" 26 link "github.com/cs3org/go-cs3apis/cs3/sharing/link/v1beta1" 27 provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1" 28 "github.com/cs3org/reva/v2/pkg/errtypes" 29 "github.com/cs3org/reva/v2/pkg/utils" 30 ) 31 32 // FormatScope create a pretty print of the scope 33 func FormatScope(scopeType string, scope *authpb.Scope) (string, error) { 34 // TODO(gmgigi96): check decoder type 35 switch { 36 case strings.HasPrefix(scopeType, "user"): 37 // user scope 38 var ref provider.Reference 39 err := utils.UnmarshalJSONToProtoV1(scope.Resource.Value, &ref) 40 if err != nil { 41 return "", err 42 } 43 return fmt.Sprintf("%s %s", ref.String(), scope.Role.String()), nil 44 case strings.HasPrefix(scopeType, "publicshare"): 45 // public share 46 var pShare link.PublicShare 47 err := utils.UnmarshalJSONToProtoV1(scope.Resource.Value, &pShare) 48 if err != nil { 49 return "", err 50 } 51 return fmt.Sprintf("share:\"%s\" %s", pShare.Id.OpaqueId, scope.Role.String()), nil 52 case strings.HasPrefix(scopeType, "resourceinfo"): 53 var resInfo provider.ResourceInfo 54 err := utils.UnmarshalJSONToProtoV1(scope.Resource.Value, &resInfo) 55 if err != nil { 56 return "", err 57 } 58 return fmt.Sprintf("path:\"%s\" %s", resInfo.Path, scope.Role.String()), nil 59 default: 60 return "", errtypes.NotSupported("scope not yet supported") 61 } 62 }