chore: remove meaningless comments

This commit is contained in:
Stavros
2025-07-12 13:17:06 +03:00
parent e742603c15
commit 8ebed0ac9a
24 changed files with 81 additions and 876 deletions

View File

@@ -16,17 +16,15 @@ type LDAP struct {
}
func NewLDAP(config types.LdapConfig) (*LDAP, error) {
// Create a new LDAP instance with the provided configuration
ldap := &LDAP{
Config: config,
}
// Connect to the LDAP server
if err := ldap.Connect(); err != nil {
_, err := ldap.connect()
if err != nil {
return nil, fmt.Errorf("failed to connect to LDAP server: %w", err)
}
// Start heartbeat goroutine
go func() {
for range time.Tick(time.Duration(5) * time.Minute) {
err := ldap.heartbeat()
@@ -39,25 +37,23 @@ func NewLDAP(config types.LdapConfig) (*LDAP, error) {
return ldap, nil
}
func (l *LDAP) Connect() error {
// Connect to the LDAP server
func (l *LDAP) connect() (*ldapgo.Conn, error) {
conn, err := ldapgo.DialURL(l.Config.Address, ldapgo.DialWithTLSConfig(&tls.Config{
InsecureSkipVerify: l.Config.Insecure,
MinVersion: tls.VersionTLS12,
}))
if err != nil {
return err
return nil, err
}
// Bind to the LDAP server with the provided credentials
err = conn.Bind(l.Config.BindDN, l.Config.BindPassword)
if err != nil {
return err
return nil, err
}
// Store the connection in the LDAP struct
// Set and return the connection
l.Conn = conn
return nil
return conn, nil
}
func (l *LDAP) Search(username string) (string, error) {
@@ -65,7 +61,6 @@ func (l *LDAP) Search(username string) (string, error) {
escapedUsername := ldapgo.EscapeFilter(username)
filter := fmt.Sprintf(l.Config.SearchFilter, escapedUsername)
// Create a search request to find the user by username
searchRequest := ldapgo.NewSearchRequest(
l.Config.BaseDN,
ldapgo.ScopeWholeSubtree, ldapgo.NeverDerefAliases, 0, 0, false,
@@ -74,7 +69,6 @@ func (l *LDAP) Search(username string) (string, error) {
nil,
)
// Perform the search
searchResult, err := l.Conn.Search(searchRequest)
if err != nil {
return "", err
@@ -84,14 +78,11 @@ func (l *LDAP) Search(username string) (string, error) {
return "", fmt.Errorf("err multiple or no entries found for user %s", username)
}
// User found, return the distinguished name (DN)
userDN := searchResult.Entries[0].DN
return userDN, nil
}
func (l *LDAP) Bind(userDN string, password string) error {
// Bind to the LDAP server with the user's DN and password
err := l.Conn.Bind(userDN, password)
if err != nil {
return err
@@ -100,10 +91,8 @@ func (l *LDAP) Bind(userDN string, password string) error {
}
func (l *LDAP) heartbeat() error {
// Perform a simple search to check if the connection is alive
log.Info().Msg("Performing LDAP connection heartbeat")
// Create a search request to find the user by username
searchRequest := ldapgo.NewSearchRequest(
"",
ldapgo.ScopeBaseObject, ldapgo.NeverDerefAliases, 0, 0, false,
@@ -112,11 +101,11 @@ func (l *LDAP) heartbeat() error {
nil,
)
// Perform the search
_, err := l.Conn.Search(searchRequest)
if err != nil {
return err
}
// No error means the connection is alive
return nil
}