diff --git a/internal/session/ids.go b/internal/session/ids.go index 2b1dc07fbd..4b32cd84d8 100644 --- a/internal/session/ids.go +++ b/internal/session/ids.go @@ -7,8 +7,11 @@ import ( ) const ( + // SessionPrefix for session PK ids SessionPrefix = "s" - StatePrefix = "ss" + + // StatePrefix for state PK ids + StatePrefix = "ss" ) func newId() (string, error) { diff --git a/internal/session/repository.go b/internal/session/repository.go index 1cd9c0c77b..66021882c3 100644 --- a/internal/session/repository.go +++ b/internal/session/repository.go @@ -17,7 +17,7 @@ type Cloneable interface { Clone() interface{} } -// Repository is the target database repository +// Repository is the session database repository type Repository struct { reader db.Reader writer db.Writer diff --git a/internal/session/session.go b/internal/session/session.go index 57f6359944..d280eec1c4 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -12,17 +12,26 @@ import ( ) const ( - DefaultSessionTableName = "session" + defaultSessionTableName = "session" ) +// ComposedOf defines the boundary data that is referenced to compose a session. type ComposedOf struct { - UserId string - HostId string - TargetId string - HostSetId string + // UserId of the session + UserId string + // HostId of the session + HostId string + // TargetId of the session + TargetId string + // HostSetId of the session + HostSetId string + // AuthTokenId of the session AuthTokenId string - ScopeId string + // ScopeId of the session + ScopeId string } + +// Session contains information about a user's session with a target type Session struct { *store.Session tableName string `gorm:"-"` @@ -110,7 +119,7 @@ func (s *Session) TableName() string { if s.tableName != "" { return s.tableName } - return DefaultSessionTableName + return defaultSessionTableName } // SetTableName sets the tablename and satisfies the ReplayableMessage diff --git a/internal/session/session_test.go b/internal/session/session_test.go index ae618a2665..d4d47a88a5 100644 --- a/internal/session/session_test.go +++ b/internal/session/session_test.go @@ -231,7 +231,7 @@ func TestSession_Clone(t *testing.T) { func TestSession_SetTableName(t *testing.T) { t.Parallel() - defaultTableName := DefaultSessionTableName + defaultTableName := defaultSessionTableName tests := []struct { name string setNameTo string diff --git a/internal/session/state.go b/internal/session/state.go index df3a5e9aa3..2339a3e1e3 100644 --- a/internal/session/state.go +++ b/internal/session/state.go @@ -10,9 +10,10 @@ import ( ) const ( - DefaultStateTableName = "session_state" + defaultStateTableName = "session_state" ) +// Status of the session's state type Status string const ( @@ -22,10 +23,12 @@ const ( StatusClosed Status = "closed" ) +// String representation of the state's status func (s Status) String() string { return string(s) } +// State of the session type State struct { *store.State tableName string `gorm:"-"` @@ -79,7 +82,7 @@ func (s *State) TableName() string { if s.tableName != "" { return s.tableName } - return DefaultStateTableName + return defaultStateTableName } // SetTableName sets the tablename and satisfies the ReplayableMessage diff --git a/internal/session/state_test.go b/internal/session/state_test.go index 3bbc3a9621..33580372b3 100644 --- a/internal/session/state_test.go +++ b/internal/session/state_test.go @@ -185,7 +185,7 @@ func TestState_Clone(t *testing.T) { func TestState_SetTableName(t *testing.T) { t.Parallel() - defaultTableName := DefaultStateTableName + defaultTableName := defaultStateTableName tests := []struct { name string setNameTo string diff --git a/internal/session/term_reason.go b/internal/session/term_reason.go index 9b8d51768f..48ee52ac8f 100644 --- a/internal/session/term_reason.go +++ b/internal/session/term_reason.go @@ -6,6 +6,7 @@ import ( "github.com/hashicorp/boundary/internal/db" ) +// TerminationReason of the session type TerminationReason string const ( @@ -17,6 +18,7 @@ const ( SystemError TerminationReason = "system error" ) +// String representation of the termination reason func (r TerminationReason) String() string { return string(r) } diff --git a/internal/session/testing.go b/internal/session/testing.go index e505d037e5..5b02ad6ded 100644 --- a/internal/session/testing.go +++ b/internal/session/testing.go @@ -16,6 +16,7 @@ import ( "github.com/stretchr/testify/require" ) +// TestState creates a test state for the sessionId in the repository. func TestState(t *testing.T, conn *gorm.DB, sessionId string, state Status) *State { t.Helper() require := require.New(t) @@ -27,6 +28,7 @@ func TestState(t *testing.T, conn *gorm.DB, sessionId string, state Status) *Sta return s } +// TestSession creates a test session composed of c in the repository. func TestSession(t *testing.T, conn *gorm.DB, c ComposedOf, opt ...Option) *Session { t.Helper() require := require.New(t) @@ -41,12 +43,15 @@ func TestSession(t *testing.T, conn *gorm.DB, c ComposedOf, opt ...Option) *Sess return s } +// TestDefaultSession creates a test session in the repository using defaults. func TestDefaultSession(t *testing.T, conn *gorm.DB, wrapper wrapping.Wrapper, iamRepo *iam.Repository, opt ...Option) *Session { t.Helper() composedOf := TestSessionParams(t, conn, wrapper, iamRepo) return TestSession(t, conn, composedOf) } +// TestSessionParams returns an initialized ComposedOf which can be used to +// create a session in the repository. func TestSessionParams(t *testing.T, conn *gorm.DB, wrapper wrapping.Wrapper, iamRepo *iam.Repository) ComposedOf { t.Helper() ctx := context.Background()