2026-04-06 15:48:37 +05:30
|
|
|
// Copyright IBM Corp. 2020, 2026
|
2023-02-02 17:15:17 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2020-09-16 12:02:02 -04:00
|
|
|
package session
|
|
|
|
|
|
|
|
|
|
import (
|
2023-06-06 17:09:08 -04:00
|
|
|
"context"
|
|
|
|
|
|
2026-10-12 10:33:41 -07:00
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/globals"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
2020-09-16 12:02:02 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
// StatePrefix for state PK ids
|
|
|
|
|
StatePrefix = "ss"
|
|
|
|
|
|
|
|
|
|
// ConnectionPrefix for connection PK ids
|
|
|
|
|
ConnectionPrefix = "sc"
|
|
|
|
|
|
|
|
|
|
// ConnectionStatePrefix for connection state PK ids
|
|
|
|
|
ConnectionStatePrefix = "scs"
|
|
|
|
|
)
|
|
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newId(ctx context.Context) (string, error) {
|
2021-02-03 16:25:56 -08:00
|
|
|
const op = "session.newId"
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.SessionPrefix)
|
2020-09-16 12:02:02 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, op)
|
2020-09-16 12:02:02 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newStateId(ctx context.Context) (string, error) {
|
2021-02-03 16:25:56 -08:00
|
|
|
const op = "session.newStateId"
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, StatePrefix)
|
2020-09-16 12:02:02 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, op)
|
2020-09-16 12:02:02 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newConnectionId(ctx context.Context) (string, error) {
|
2021-02-03 16:25:56 -08:00
|
|
|
const op = "session.newConnectionId"
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, ConnectionPrefix)
|
2020-09-16 12:02:02 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, op)
|
2020-09-16 12:02:02 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newConnectionStateId(ctx context.Context) (string, error) {
|
2021-02-03 16:25:56 -08:00
|
|
|
const op = "session.newConnectionStateId"
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, ConnectionStatePrefix)
|
2020-09-16 12:02:02 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, op)
|
2020-09-16 12:02:02 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|