Files
threshold/internal/server/repository.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

67 lines
1.7 KiB
Go
Raw Normal View History

2020-08-12 00:40:39 -04:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
2023-02-02 17:15:17 -08:00
2022-06-20 18:20:17 -07:00
package server
2020-08-12 00:40:39 -04:00
import (
"context"
2022-05-24 15:08:02 -07:00
"reflect"
2020-08-12 00:40:39 -04:00
"time"
"github.com/hashicorp/boundary/internal/db"
2021-01-21 16:27:20 -05:00
"github.com/hashicorp/boundary/internal/errors"
2020-08-19 16:47:18 -04:00
"github.com/hashicorp/boundary/internal/kms"
2020-08-12 00:40:39 -04:00
)
const (
// DefaultLiveness is a default used for various timing parameters, such as
// grace period for status updates, server liveness, etc.
DefaultLiveness = 15 * time.Second
2020-08-12 00:40:39 -04:00
)
2022-06-20 18:20:17 -07:00
// Repository is the server database repository
2020-08-12 00:40:39 -04:00
type Repository struct {
2020-08-19 16:47:18 -04:00
reader db.Reader
writer db.Writer
kms *kms.Kms
// defaultLimit provides a default for limiting the number of results returned from the repo
defaultLimit int
2020-08-12 00:40:39 -04:00
}
2022-06-20 18:20:17 -07:00
// NewRepository creates a new server Repository. Supports the options: WithLimit
2020-08-12 00:40:39 -04:00
// which sets a default limit on results returned by repo operations.
func NewRepository(ctx context.Context, r db.Reader, w db.Writer, kms *kms.Kms, opt ...Option) (*Repository, error) {
2022-06-20 18:20:17 -07:00
const op = "server.NewRepository"
2020-08-12 00:40:39 -04:00
if r == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil reader")
2020-08-12 00:40:39 -04:00
}
if w == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil writer")
2020-08-12 00:40:39 -04:00
}
2020-08-19 16:47:18 -04:00
if kms == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "nil kms")
2020-08-12 00:40:39 -04:00
}
2022-09-02 14:32:41 -04:00
opts := GetOpts(opt...)
if opts.withLimit == 0 {
// zero signals the boundary defaults should be used.
opts.withLimit = db.DefaultLimit
}
2020-08-12 00:40:39 -04:00
return &Repository{
reader: r,
writer: w,
kms: kms,
defaultLimit: opts.withLimit,
2020-08-12 00:40:39 -04:00
}, nil
}
2022-05-24 15:08:02 -07:00
2022-10-25 18:29:38 -05:00
func isNil(i any) bool {
2022-05-24 15:08:02 -07:00
if i == nil {
return true
}
switch reflect.TypeOf(i).Kind() {
case reflect.Ptr, reflect.Map, reflect.Array, reflect.Chan, reflect.Slice:
return reflect.ValueOf(i).IsNil()
}
return false
}