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>
53 lines
1.7 KiB
Go
53 lines
1.7 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package server
|
|
|
|
import (
|
|
"context"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/util"
|
|
)
|
|
|
|
// AuthorizedWorkers contain authorized worker
|
|
// public ids and unmapped worker key ids
|
|
type AuthorizedWorkers struct {
|
|
WorkerPublicIds []string
|
|
UnmappedWorkerKeyIds []string
|
|
}
|
|
|
|
// VerifyKnownAndUnmappedWorkers verifies the connected worker ids and unmapped worker key ids are known to the controller
|
|
func VerifyKnownAndUnmappedWorkers(
|
|
ctx context.Context,
|
|
repo *Repository,
|
|
workerAuthRepo *WorkerAuthRepositoryStorage,
|
|
connectedWorkerIds,
|
|
unmappedWorkerKeyIds []string,
|
|
) (*AuthorizedWorkers, error) {
|
|
const op = "server.VerifyKnownAndUnmappedWorkers"
|
|
switch {
|
|
case util.IsNil(repo):
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "repository is required")
|
|
case util.IsNil(workerAuthRepo):
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "worker auth repository is required")
|
|
}
|
|
var authorizedDownstreams AuthorizedWorkers
|
|
if len(connectedWorkerIds) > 0 {
|
|
knownConnectedWorkers, err := repo.VerifyKnownWorkers(ctx, connectedWorkerIds)
|
|
if err != nil {
|
|
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error getting known connected worker ids"))
|
|
}
|
|
authorizedDownstreams.WorkerPublicIds = knownConnectedWorkers
|
|
}
|
|
|
|
if len(unmappedWorkerKeyIds) > 0 {
|
|
authorizedKeyIds, err := workerAuthRepo.FilterToAuthorizedWorkerKeyIds(ctx, unmappedWorkerKeyIds)
|
|
if err != nil {
|
|
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("error getting authorized unmapped worker key ids"))
|
|
}
|
|
authorizedDownstreams.UnmappedWorkerKeyIds = authorizedKeyIds
|
|
}
|
|
return &authorizedDownstreams, nil
|
|
}
|