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>
82 lines
2.8 KiB
Go
82 lines
2.8 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package server
|
|
|
|
import (
|
|
"context"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db/timestamp"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/oplog"
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/server/store"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// Ensure WorkerSessionInfoRequest implements interfaces
|
|
var (
|
|
_ db.VetForWriter = (*WorkerSessionInfoRequest)(nil)
|
|
_ oplog.ReplayableMessage = (*WorkerSessionInfoRequest)(nil)
|
|
)
|
|
|
|
// WorkerSessionInfoRequest contains the last time a worker daemon sent a status update for session information.
|
|
type WorkerSessionInfoRequest struct {
|
|
*store.WorkerSessionInfoRequest
|
|
tableName string `gorm:"-"`
|
|
}
|
|
|
|
// NewWorkerSessionInfoRequest create a new instance of a worker session information request.
|
|
// The LastStatusTime field is set to the current time.
|
|
func NewWorkerSessionInfoRequest(workerId string) *WorkerSessionInfoRequest {
|
|
return &WorkerSessionInfoRequest{
|
|
WorkerSessionInfoRequest: &store.WorkerSessionInfoRequest{
|
|
WorkerId: workerId,
|
|
LastRequestTime: timestamp.Now(),
|
|
},
|
|
}
|
|
}
|
|
|
|
// WorkerSessionInfoRequest creates an empty in-memory instance of a worker session information request.
|
|
func AllocWorkerSessionInfoRequest() *WorkerSessionInfoRequest {
|
|
return &WorkerSessionInfoRequest{
|
|
WorkerSessionInfoRequest: &store.WorkerSessionInfoRequest{},
|
|
}
|
|
}
|
|
|
|
func (w *WorkerSessionInfoRequest) Clone() *WorkerSessionInfoRequest {
|
|
cp := proto.Clone(w.WorkerSessionInfoRequest)
|
|
return &WorkerSessionInfoRequest{
|
|
WorkerSessionInfoRequest: cp.(*store.WorkerSessionInfoRequest),
|
|
}
|
|
}
|
|
|
|
// VetForWrite implements db.VetForWrite() interface and validates the worker storage bucket credential state
|
|
func (w *WorkerSessionInfoRequest) VetForWrite(ctx context.Context, _ db.Reader, opType db.OpType, _ ...db.Option) error {
|
|
const op = "server.(WorkerSessionInfoRequest).VetForWrite"
|
|
switch {
|
|
case w == nil:
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing worker session info request")
|
|
case w.WorkerId == "":
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing worker id")
|
|
case w.LastRequestTime == nil:
|
|
return errors.New(ctx, errors.InvalidParameter, op, "missing last request timestamp")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// TableName returns the tablename to override the default gorm table name
|
|
func (w *WorkerSessionInfoRequest) TableName() string {
|
|
if w.tableName != "" {
|
|
return w.tableName
|
|
}
|
|
return "server_worker_session_info_request"
|
|
}
|
|
|
|
// SetTableName sets the tablename and satisfies the ReplayableMessage
|
|
// interface. If the caller attempts to set the name to "" the name will be
|
|
// reset to the default name.
|
|
func (w *WorkerSessionInfoRequest) SetTableName(n string) {
|
|
w.tableName = n
|
|
}
|