From a1f7615b7e97c47a194715ede85189b61a34c84c Mon Sep 17 00:00:00 2001 From: Airat Arifullin Date: Thu, 20 Jun 2024 14:50:17 +0300 Subject: [PATCH] [#1190] ape: Introduce `Groups` util function to retrieve actor's groupIDs Signed-off-by: Airat Arifullin --- pkg/ape/request/frostfsid.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/pkg/ape/request/frostfsid.go b/pkg/ape/request/frostfsid.go index fa620e58c..c0413678d 100644 --- a/pkg/ape/request/frostfsid.go +++ b/pkg/ape/request/frostfsid.go @@ -34,3 +34,19 @@ func FormFrostfsIDRequestProperties(frostFSIDClient frostfsidcore.SubjectProvide return reqProps, nil } + +// Groups return the actor's group ids from frostfsid contract. +func Groups(frostFSIDClient frostfsidcore.SubjectProvider, pk *keys.PublicKey) ([]string, error) { + subj, err := frostFSIDClient.GetSubjectExtended(pk.GetScriptHash()) + if err != nil { + if !strings.Contains(err.Error(), frostfsidcore.SubjectNotFoundErrorMessage) { + return nil, fmt.Errorf("get subject error: %w", err) + } + return []string{}, nil + } + groups := make([]string, len(subj.Groups)) + for i, group := range subj.Groups { + groups[i] = strconv.FormatInt(group.ID, 10) + } + return groups, nil +}