mirror of https://github.com/hashicorp/boundary
parent
760671f223
commit
bca7c371d8
@ -0,0 +1,69 @@
|
||||
package session
|
||||
|
||||
import "github.com/hashicorp/boundary/internal/errors"
|
||||
|
||||
const (
|
||||
defaultSessionHostSetHostTableName = "session_host_set_host"
|
||||
)
|
||||
|
||||
// SessionHostSetHost contains information about a user's session with a target that has a host source association.
|
||||
type SessionHostSetHost struct {
|
||||
// SessionId of the session
|
||||
SessionId string `json:"session_id,omitempty" gorm:"primary_key"`
|
||||
// HostSetId of the session
|
||||
HostSetId string `json:"host_set_id,omitempty" gorm:"default:null"`
|
||||
// HostId of the session
|
||||
HostId string `json:"host_id,omitempty" gorm:"default:null"`
|
||||
|
||||
tableName string `gorm:"-"`
|
||||
}
|
||||
|
||||
// NewSessionHostSetHost creates a new in memory session to host set & host association.
|
||||
func NewSessionHostSetHost(sessionId, hostSetId, hostId string) (*SessionHostSetHost, error) {
|
||||
const op = "session.NewSessionHostSetHost"
|
||||
if sessionId == "" {
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing session id")
|
||||
}
|
||||
if hostSetId == "" {
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing host set id")
|
||||
}
|
||||
if hostId == "" {
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing host id")
|
||||
}
|
||||
shs := &SessionHostSetHost{
|
||||
SessionId: sessionId,
|
||||
HostSetId: hostSetId,
|
||||
HostId: hostId,
|
||||
}
|
||||
return shs, nil
|
||||
}
|
||||
|
||||
// TableName returns the tablename to override the default gorm table name
|
||||
func (s *SessionHostSetHost) TableName() string {
|
||||
if s.tableName != "" {
|
||||
return s.tableName
|
||||
}
|
||||
return defaultSessionHostSetHostTableName
|
||||
}
|
||||
|
||||
// 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 *SessionHostSetHost) SetTableName(n string) {
|
||||
s.tableName = n
|
||||
}
|
||||
|
||||
// AllocSessionHostSet will allocate a SessionHostSetHost
|
||||
func AllocSessionHostSetHost() *SessionHostSetHost {
|
||||
return &SessionHostSetHost{}
|
||||
}
|
||||
|
||||
// Clone creates a clone of the SessionHostSetHost
|
||||
func (s *SessionHostSetHost) Clone() any {
|
||||
clone := &SessionHostSetHost{
|
||||
SessionId: s.SessionId,
|
||||
HostSetId: s.HostSetId,
|
||||
HostId: s.HostId,
|
||||
}
|
||||
return clone
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package session
|
||||
|
||||
import "github.com/hashicorp/boundary/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(sessionId, targetId string) (*SessionTargetAddress, error) {
|
||||
const op = "sesssion.NewSessionTargetAddress"
|
||||
if sessionId == "" {
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing session id")
|
||||
}
|
||||
if targetId == "" {
|
||||
return nil, errors.NewDeprecated(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
|
||||
}
|
||||
Loading…
Reference in new issue