Files
threshold/internal/auth/ldap/user_entry_search_conf.go
shadowdaoandClaude Sonnet 5.5 962d708fdd Rename Go module paths to repo.anhonesthost.net/CyberCoveLLC/threshold
Rename root, api and sdk module paths (imports, go.mod, go_package,
ldflags, build scripts, buf configs) and regenerate protobuf/gateway
code with the project's pinned toolchain. Wire identifiers unchanged.
api gets a local replace for sdk; root/api/sdk require v0.1.0.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-12 10:33:41 -07:00

79 lines
2.5 KiB
Go

// Copyright IBM Corp. 2020, 2026
// SPDX-License-Identifier: BUSL-1.1
package ldap
import (
"context"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/auth/ldap/store"
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
"google.golang.org/protobuf/proto"
)
const userEntrySearchConfTableName = "auth_ldap_user_entry_search"
// UserEntrySearchConf represent a set of optional configuration fields used to
// search for user entries. It is assigned to an LDAP AuthMethod and
// updates/deletes to that AuthMethod are cascaded to its UserEntrySearchConf.
// UserEntrySearchConf are value objects of an AuthMethod, therefore there's no
// need for oplog metadata, since only the AuthMethod will have metadata because
// it's the root aggregate.
type UserEntrySearchConf struct {
*store.UserEntrySearchConf
tableName string
}
// NewUserEntrySearchConf creates a new in memory NewUserEntrySearchConf.
// Supported options are: WithUserDn, WithUserAttr, WithUserFilter and all other
// options are ignored.
func NewUserEntrySearchConf(ctx context.Context, authMethodId string, opt ...Option) (*UserEntrySearchConf, error) {
const op = "ldap.NewUserEntrySearchConf"
opts, err := getOpts(opt...)
if err != nil {
return nil, errors.Wrap(ctx, err, op)
}
switch {
case authMethodId == "":
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing auth method id")
case opts.withUserDn == "" && opts.withUserAttr == "" && opts.withUserFilter == "":
return nil, errors.New(ctx, errors.InvalidParameter, op, "you must supply either dn, attr, or filter")
}
return &UserEntrySearchConf{
UserEntrySearchConf: &store.UserEntrySearchConf{
LdapMethodId: authMethodId,
UserDn: opts.withUserDn,
UserAttr: opts.withUserAttr,
UserFilter: opts.withUserFilter,
},
}, nil
}
// allocUserEntrySearchConf makes an empty one in memory
func allocUserEntrySearchConf() *UserEntrySearchConf {
return &UserEntrySearchConf{
UserEntrySearchConf: &store.UserEntrySearchConf{},
}
}
// clone a UserEntrySearchConf
func (uc *UserEntrySearchConf) clone() *UserEntrySearchConf {
cp := proto.Clone(uc.UserEntrySearchConf)
return &UserEntrySearchConf{
UserEntrySearchConf: cp.(*store.UserEntrySearchConf),
}
}
// TableName returns the table name
func (uc *UserEntrySearchConf) TableName() string {
if uc.tableName != "" {
return uc.tableName
}
return userEntrySearchConfTableName
}
// SetTableName sets the table name.
func (uc *UserEntrySearchConf) SetTableName(n string) {
uc.tableName = n
}