Made GetScopeByKeyPrefix function as a private method of the FileConnector

This commit is contained in:
Roman Perekhod
2024-12-10 10:08:30 +01:00
parent 8006b5d25e
commit 8d1f990abd
3 changed files with 23 additions and 25 deletions
@@ -1,24 +0,0 @@
package helpers
import (
"fmt"
"strings"
auth "github.com/cs3org/go-cs3apis/cs3/auth/provider/v1beta1"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/golang/protobuf/proto"
)
// GetScopeByKeyPrefix returns the scope from the AccessToken Scope map by key prefix
func GetScopeByKeyPrefix(scopes map[string]*auth.Scope, keyPrefix string, m proto.Message) error {
for k, v := range scopes {
if strings.HasPrefix(k, keyPrefix) && v.Resource.Decoder == "json" {
err := utils.UnmarshalJSONToProtoV1(v.Resource.Value, m)
if err != nil {
return fmt.Errorf("can't unmarshal public share from scope: %w", err)
}
return nil
}
}
return fmt.Errorf("scope %s not found", keyPrefix)
}