Files
threshold/internal/server/worker_storage_bucket.go
T
shadowdaoandClaude Sonnet 5.5 962d708fdd Rename Go module paths to repo.anhonesthost.net/CyberCoveLLC/threshold
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>
2026-10-12 10:33:41 -07:00

104 lines
3.5 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/storage/storagebucketcredential"
"repo.anhonesthost.net/CyberCoveLLC/threshold/sdk/pbs/controller/api/resources/plugins"
"repo.anhonesthost.net/CyberCoveLLC/threshold/sdk/pbs/controller/api/resources/storagebuckets"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/wrapperspb"
)
const UpsertWorkerStorageBucketJobName = "upsert_worker_storage_bucket"
type WorkerStorageBucket struct {
WorkerId string
Buckets []*storagebuckets.StorageBucket
}
type UpdateStorageBucketCredential struct {
PublicId string `gorm:"primary_key"`
StorageBucketCredentialId string
ScopeId string
Name string
Description string
BucketName string
BucketPrefix string
WorkerFilter string
Attributes []byte
PluginId string
PluginName string
PluginDescription string
KeyId string
CtSecrets []byte
Version uint32
}
// TableName returns the table name for gorm
func (owsbc *UpdateStorageBucketCredential) TableName() string {
return "update_worker_storage_bucket_credential"
}
// ToPluginStorageBucket re-formats an storage bucket into the proto used for storage plugin requests
func ToPluginStorageBucket(ctx context.Context, usb *UpdateStorageBucketCredential, wrapper wrapping.Wrapper) (*storagebuckets.StorageBucket, error) {
const op = "server.ToPluginStorageBucket"
switch {
case usb == nil:
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil update storage bucket credential")
}
sb := &storagebuckets.StorageBucket{
Id: usb.PublicId,
StorageBucketCredentialId: usb.StorageBucketCredentialId,
ScopeId: usb.ScopeId,
PluginId: usb.PluginId,
Description: wrapperspb.String(usb.Description),
BucketName: usb.BucketName,
BucketPrefix: usb.BucketPrefix,
WorkerFilter: usb.WorkerFilter,
Plugin: &plugins.PluginInfo{
Id: usb.PluginId,
Name: usb.PluginName,
Description: usb.PluginDescription,
},
Version: usb.Version,
}
if usb.Attributes != nil {
attrs := &structpb.Struct{}
if err := proto.Unmarshal(usb.Attributes, attrs); err != nil {
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to unmarshal attributes"))
}
sb.Attributes = attrs
}
if usb.CtSecrets != nil {
allocFn, ok := storagebucketcredential.SubtypeRegistry.AllocFunc(storagebucketcredential.ManagedSecretSubtype)
if !ok {
return nil, errors.New(ctx, errors.InvalidParameter, op, "unable to allocate storage bucket credential")
}
sbc := allocFn()
sbc.SetKeyId(usb.KeyId)
sbc.SetStorageBucketId(usb.PublicId)
sbc.SetCtSecrets(usb.CtSecrets)
if sbc.Decrypt(ctx, wrapper) != nil {
return nil, errors.New(ctx, errors.Decrypt, op, "error decrypting secrets")
}
secrets := &structpb.Struct{}
if err := proto.Unmarshal(sbc.GetSecrets(), secrets); err != nil {
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to unmarshal secrets"))
}
sb.Secrets = secrets
}
return sb, nil
}