2026-04-06 15:48:37 +05:30
|
|
|
// Copyright IBM Corp. 2020, 2026
|
2021-06-22 22:26:26 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-02-02 17:15:17 -08:00
|
|
|
|
2021-06-22 22:26:26 -04:00
|
|
|
package session
|
|
|
|
|
|
|
|
|
|
import (
|
2026-10-12 10:33:41 -07:00
|
|
|
cred "repo.anhonesthost.net/CyberCoveLLC/threshold/internal/credential"
|
2021-06-22 22:26:26 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// A DynamicCredential represents the relationship between a session, a
|
|
|
|
|
// credential, and the credential library where the credential was
|
|
|
|
|
// retrieved plus the purpose of the credential.
|
|
|
|
|
type DynamicCredential struct {
|
|
|
|
|
SessionId string `json:"session_id,omitempty" gorm:"primary_key"`
|
|
|
|
|
LibraryId string `json:"library_id,omitempty" gorm:"primary_key"`
|
|
|
|
|
CredentialPurpose string `json:"credential_purpose,omitempty" gorm:"primary_key"`
|
|
|
|
|
CredentialId string `json:"credential_id,omitempty" gorm:"default:null"`
|
|
|
|
|
|
|
|
|
|
tableName string `gorm:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewDynamicCredential creates a new in memory Credential representing the
|
|
|
|
|
// relationship between session and a credential library.
|
2021-12-17 11:25:30 -08:00
|
|
|
func NewDynamicCredential(libraryId string, purpose cred.Purpose) *DynamicCredential {
|
2021-06-22 22:26:26 -04:00
|
|
|
return &DynamicCredential{
|
|
|
|
|
LibraryId: libraryId,
|
|
|
|
|
CredentialPurpose: string(purpose),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func allocCredential() *DynamicCredential {
|
|
|
|
|
return &DynamicCredential{}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *DynamicCredential) clone() *DynamicCredential {
|
|
|
|
|
return &DynamicCredential{
|
|
|
|
|
SessionId: c.SessionId,
|
|
|
|
|
LibraryId: c.LibraryId,
|
|
|
|
|
CredentialPurpose: c.CredentialPurpose,
|
|
|
|
|
CredentialId: c.CredentialId,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TableName returns the table name.
|
|
|
|
|
func (c *DynamicCredential) TableName() string {
|
|
|
|
|
if c.tableName != "" {
|
|
|
|
|
return c.tableName
|
|
|
|
|
}
|
|
|
|
|
return "session_credential_dynamic"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetTableName sets the table name.
|
|
|
|
|
func (c *DynamicCredential) SetTableName(n string) {
|
|
|
|
|
c.tableName = n
|
|
|
|
|
}
|