Some checks failed
DCO action / DCO (pull_request) Successful in 59s
Vulncheck / Vulncheck (pull_request) Successful in 1m4s
Pre-commit hooks / Pre-commit (pull_request) Successful in 1m55s
Build / Build Components (pull_request) Successful in 2m4s
Tests and linters / Staticcheck (pull_request) Successful in 2m38s
Tests and linters / Lint (pull_request) Successful in 3m16s
Tests and linters / Run gofumpt (pull_request) Successful in 3m54s
Tests and linters / Tests (pull_request) Successful in 4m12s
Tests and linters / gopls check (pull_request) Successful in 4m31s
Tests and linters / Tests with -race (pull_request) Successful in 4m38s
OCI image / Build container images (push) Failing after 18s
Vulncheck / Vulncheck (push) Successful in 1m2s
Pre-commit hooks / Pre-commit (push) Successful in 1m39s
Build / Build Components (push) Successful in 1m45s
Tests and linters / Staticcheck (push) Successful in 2m18s
Tests and linters / Run gofumpt (push) Successful in 2m46s
Tests and linters / Lint (push) Successful in 3m5s
Tests and linters / Tests with -race (push) Successful in 3m23s
Tests and linters / Tests (push) Successful in 3m52s
Tests and linters / gopls check (push) Successful in 4m18s
Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
53 lines
1.8 KiB
Go
53 lines
1.8 KiB
Go
package request
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
frostfsidcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/frostfsid"
|
|
apechain "git.frostfs.info/TrueCloudLab/policy-engine/pkg/chain"
|
|
commonschema "git.frostfs.info/TrueCloudLab/policy-engine/schema/common"
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
)
|
|
|
|
// FormFrostfsIDRequestProperties forms frostfsid specific request properties like user-claim tags and group ID.
|
|
func FormFrostfsIDRequestProperties(ctx context.Context, frostFSIDClient frostfsidcore.SubjectProvider, pk *keys.PublicKey) (map[string]string, error) {
|
|
reqProps := make(map[string]string)
|
|
subj, err := frostFSIDClient.GetSubjectExtended(ctx, pk.GetScriptHash())
|
|
if err != nil {
|
|
if !strings.Contains(err.Error(), frostfsidcore.SubjectNotFoundErrorMessage) {
|
|
return nil, fmt.Errorf("get subject error: %w", err)
|
|
}
|
|
return reqProps, nil
|
|
}
|
|
for k, v := range subj.KV {
|
|
propertyKey := fmt.Sprintf(commonschema.PropertyKeyFormatFrostFSIDUserClaim, k)
|
|
reqProps[propertyKey] = v
|
|
}
|
|
|
|
groups := make([]string, len(subj.Groups))
|
|
for i, group := range subj.Groups {
|
|
groups[i] = strconv.FormatInt(group.ID, 10)
|
|
}
|
|
reqProps[commonschema.PropertyKeyFrostFSIDGroupID] = apechain.FormCondSliceContainsValue(groups)
|
|
|
|
return reqProps, nil
|
|
}
|
|
|
|
// Groups return the actor's group ids from frostfsid contract.
|
|
func Groups(ctx context.Context, frostFSIDClient frostfsidcore.SubjectProvider, pk *keys.PublicKey) ([]string, error) {
|
|
subj, err := frostFSIDClient.GetSubjectExtended(ctx, 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
|
|
}
|