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"
|
|
|
|
|
"fmt"
|
|
|
|
|
|
2026-10-12 10:33:41 -07:00
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
2024-02-13 09:17:41 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// lookupAliasByValue returns the Alias for the provided value. Returns nil, nil
|
|
|
|
|
// if no Alias is found for the provided value. No Options are currently supported
|
|
|
|
|
func (r *Repository) lookupAliasByValue(ctx context.Context, value string) (*Alias, error) {
|
|
|
|
|
const op = "alias.(Repository).LookupAliasByValue"
|
|
|
|
|
if value == "" {
|
|
|
|
|
return nil, errors.New(ctx, errors.InvalidParameter, op, "value is empty")
|
|
|
|
|
}
|
|
|
|
|
a := allocAlias()
|
|
|
|
|
if err := r.reader.LookupWhere(ctx, a, "value = $1", []any{value}); err != nil {
|
|
|
|
|
if errors.IsNotFoundError(err) {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
|
|
|
|
return nil, errors.Wrap(ctx, err, op, errors.WithMsg(fmt.Sprintf("failed for %q", value)))
|
|
|
|
|
}
|
|
|
|
|
return a, nil
|
|
|
|
|
}
|