diff --git a/internal/ldap/ldap.go b/internal/ldap/ldap.go index 7731c0e..0527c1c 100644 --- a/internal/ldap/ldap.go +++ b/internal/ldap/ldap.go @@ -3,15 +3,15 @@ package ldap import ( "strings" - "github.com/hashicorp/go-hclog" ldap "github.com/ps78674/ldapserver" ) // New returns a new ldap server instance -func New(l hclog.Logger, nacl naClient) *server { +func New(opts ...Option) *server { x := new(server) - x.l = l.Named("ldap") - x.c = nacl + for _, o := range opts { + o(x) + } x.Server = ldap.NewServer() x.routes = ldap.NewRouteMux() diff --git a/internal/ldap/option.go b/internal/ldap/option.go new file mode 100644 index 0000000..cb2ad0a --- /dev/null +++ b/internal/ldap/option.go @@ -0,0 +1,14 @@ +package ldap + +import ( + "github.com/hashicorp/go-hclog" +) + +// Option handle configuration of the underlying ldap.server type. +type Option func(*server) + +// WithLogger sets the loggers for the server. +func WithLogger(l hclog.Logger) Option { return func(s *server) { s.l = l.Named("ldap") } } + +// WithNetAuth sets the NetAuth client for the server. +func WithNetAuth(n naClient) Option { return func(s *server) { s.c = n } } diff --git a/main.go b/main.go index 697849e..f2a58f7 100644 --- a/main.go +++ b/main.go @@ -9,8 +9,8 @@ import ( "github.com/hashicorp/go-hclog" "github.com/netauth/ldap/internal/ldap" "github.com/netauth/netauth/pkg/netauth" - "github.com/spf13/viper" log "github.com/sirupsen/logrus" + "github.com/spf13/viper" ) func init() { @@ -62,7 +62,7 @@ func main() { os.Exit(2) } - ls := ldap.New(appLogger, nacl) + ls := ldap.New(ldap.WithLogger(appLogger), ldap.WithNetAuth(nacl)) ls.SetDomain(viper.GetString("ldap.domain"))