2026-04-06 15:48:37 +05:30
|
|
|
// Copyright IBM Corp. 2020, 2026
|
2024-02-13 09:17:41 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
|
|
|
|
package alias
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2026-10-12 10:33:41 -07:00
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/kms"
|
2024-02-13 09:17:41 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// A Repository stores and retrieves the persistent types in the alias
|
|
|
|
|
// package. It is not safe to use a repository concurrently.
|
|
|
|
|
type Repository struct {
|
|
|
|
|
reader db.Reader
|
|
|
|
|
writer db.Writer
|
|
|
|
|
kms *kms.Kms
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewRepository creates a new Repository. The returned repository should
|
|
|
|
|
// only be used for one transaction and it is not safe for concurrent go
|
|
|
|
|
// routines to access it.
|
|
|
|
|
func NewRepository(ctx context.Context, r db.Reader, w db.Writer, kms *kms.Kms) (*Repository, error) {
|
|
|
|
|
const op = "alias.NewRepository"
|
|
|
|
|
switch {
|
|
|
|
|
case r == nil:
|
|
|
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "db.Reader")
|
|
|
|
|
case w == nil:
|
|
|
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "db.Writer")
|
|
|
|
|
case kms == nil:
|
|
|
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "kms")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return &Repository{
|
|
|
|
|
reader: r,
|
|
|
|
|
writer: w,
|
|
|
|
|
kms: kms,
|
|
|
|
|
}, nil
|
|
|
|
|
}
|