Rename root, api and sdk module paths (imports, go.mod, go_package, ldflags, build scripts, buf configs) and regenerate protobuf/gateway code with the project's pinned toolchain. Wire identifiers unchanged. api gets a local replace for sdk; root/api/sdk require v0.1.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package auth
|
|
|
|
import (
|
|
"context"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/perms"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/types/action"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/types/resource"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/sdk/pbs/controller/api/resources/scopes"
|
|
"github.com/hashicorp/go-secure-stdlib/strutil"
|
|
"google.golang.org/protobuf/types/known/structpb"
|
|
)
|
|
|
|
// CalculateAuthorizedCollectionActions returns authorized actions for the given
|
|
// inputs.
|
|
//
|
|
// NOTE: Eventually we should unit test this, but for now every service handler
|
|
// is validating the results of this (as it was pulled out of the service
|
|
// handlers).
|
|
func CalculateAuthorizedCollectionActions(ctx context.Context,
|
|
authResults VerifyResults,
|
|
mapToRange map[resource.Type]action.ActionSet,
|
|
scopeInfo *scopes.ScopeInfo, pin string,
|
|
) (map[string]*structpb.ListValue, error) {
|
|
res := &perms.Resource{
|
|
ScopeId: scopeInfo.GetId(),
|
|
Pin: pin,
|
|
ParentScopeId: scopeInfo.GetParentScopeId(),
|
|
}
|
|
// Range over the defined collections and check permissions against those
|
|
// collections.
|
|
var ret map[string]*structpb.ListValue
|
|
for k, v := range mapToRange {
|
|
res.Type = k
|
|
acts := authResults.FetchActionSetForType(ctx, k, v, WithResource(res)).Strings()
|
|
if len(acts) > 0 {
|
|
if ret == nil {
|
|
ret = make(map[string]*structpb.ListValue)
|
|
}
|
|
lv, err := structpb.NewList(strutil.StringListToInterfaceList(acts))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
ret[k.PluralString()] = lv
|
|
}
|
|
}
|
|
return ret, nil
|
|
}
|