mirror of https://github.com/hashicorp/boundary
parent
00dfea1244
commit
58d9d42a88
@ -0,0 +1,32 @@
|
||||
begin;
|
||||
|
||||
create table session_credential_static (
|
||||
session_id wt_public_id not null
|
||||
constraint session_fkey
|
||||
references session (public_id)
|
||||
on delete cascade
|
||||
on update cascade,
|
||||
credential_static_id wt_public_id
|
||||
constraint credential_static_fkey
|
||||
references credential_static (public_id)
|
||||
on delete cascade
|
||||
on update cascade,
|
||||
credential_purpose text not null
|
||||
constraint credential_purpose_fkey
|
||||
references credential_purpose_enm (name)
|
||||
on delete restrict
|
||||
on update cascade,
|
||||
primary key(session_id, credential_static_id, credential_purpose),
|
||||
create_time wt_timestamp
|
||||
);
|
||||
comment on table session_credential_dynamic is
|
||||
'session_credential_static is a join table between the session and static credential tables. '
|
||||
'It also contains the credential purpose the relationship represents.';
|
||||
|
||||
create trigger default_create_time_column before insert on session_credential_static
|
||||
for each row execute procedure default_create_time();
|
||||
|
||||
create trigger immutable_columns before update on session_credential_static
|
||||
for each row execute procedure immutable_columns('session_id', 'credential_static_id', 'credential_purpose', 'create_time');
|
||||
|
||||
commit;
|
||||
@ -0,0 +1,45 @@
|
||||
package session
|
||||
|
||||
import (
|
||||
cred "github.com/hashicorp/boundary/internal/credential"
|
||||
)
|
||||
|
||||
// A StaticCredential represents the relationship between a session, a
|
||||
// credential and the purpose of the credential.
|
||||
type StaticCredential struct {
|
||||
SessionId string `json:"session_id,omitempty" gorm:"primary_key"`
|
||||
CredentialPurpose string `json:"credential_purpose,omitempty" gorm:"primary_key"`
|
||||
CredentialStaticId string `json:"credential_id,omitempty" gorm:"default:null"`
|
||||
|
||||
tableName string `gorm:"-"`
|
||||
}
|
||||
|
||||
// NewStaticCredential creates a new in memory Credential representing the
|
||||
// relationship between session a credential and the purpose of the credential.
|
||||
func NewStaticCredential(id string, purpose cred.Purpose) *StaticCredential {
|
||||
return &StaticCredential{
|
||||
CredentialStaticId: id,
|
||||
CredentialPurpose: string(purpose),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *StaticCredential) clone() *StaticCredential {
|
||||
return &StaticCredential{
|
||||
SessionId: c.SessionId,
|
||||
CredentialPurpose: c.CredentialPurpose,
|
||||
CredentialStaticId: c.CredentialStaticId,
|
||||
}
|
||||
}
|
||||
|
||||
// TableName returns the table name.
|
||||
func (c *StaticCredential) TableName() string {
|
||||
if c.tableName != "" {
|
||||
return c.tableName
|
||||
}
|
||||
return "session_credential_static"
|
||||
}
|
||||
|
||||
// SetTableName sets the table name.
|
||||
func (c *StaticCredential) SetTableName(n string) {
|
||||
c.tableName = n
|
||||
}
|
||||
Loading…
Reference in new issue