Files
threshold/internal/session/session_target_address.go
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

70 lines
2.0 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package session
import (
"context"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
)
const (
defaultSessionTargetAddressTableName = "session_target_address"
)
// SessionTargetAddress contains information about a user's session with a target that has a direct network address association.
type SessionTargetAddress struct {
// SessionId of the session
SessionId string `json:"session_id,omitempty" gorm:"primary_key"`
// TargetId of the session
TargetId string `json:"target_id,omitempty" gorm:"default:null"`
tableName string `gorm:"-"`
}
// NewSessionTargetAddress creates a new in memory session target address.
func NewSessionTargetAddress(ctx context.Context, sessionId, targetId string) (*SessionTargetAddress, error) {
const op = "sesssion.NewSessionTargetAddress"
if sessionId == "" {
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing session id")
}
if targetId == "" {
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing target id")
}
sta := &SessionTargetAddress{
SessionId: sessionId,
TargetId: targetId,
}
return sta, nil
}
// TableName returns the tablename to override the default gorm table name
func (s *SessionTargetAddress) TableName() string {
if s.tableName != "" {
return s.tableName
}
return defaultSessionTargetAddressTableName
}
// 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 (s *SessionTargetAddress) SetTableName(n string) {
s.tableName = n
}
// AllocSessionTargetAddress will allocate a SessionTargetAddress
func AllocSessionTargetAddress() *SessionTargetAddress {
return &SessionTargetAddress{}
}
// Clone creates a clone of the SessionTargetAddress
func (s *SessionTargetAddress) Clone() any {
clone := &SessionTargetAddress{
SessionId: s.SessionId,
TargetId: s.TargetId,
}
return clone
}