mirror of
https://github.com/pocket-id/pocket-id.git
synced 2026-09-23 03:19:05 +02:00
refactor: migrate LDAP sync to an actor (#1651)
Co-authored-by: Kyle Mendell <kmendell@ofkm.us>
This commit is contained in:
co-authored by
Kyle Mendell
parent
f8db1d8a86
commit
563c0f93a6
@@ -0,0 +1,41 @@
|
||||
package ldapsync
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"github.com/pocket-id/pocket-id/backend/internal/appconfig"
|
||||
)
|
||||
|
||||
type handler struct {
|
||||
service *Service
|
||||
appConfig appconfig.AppConfigResolver
|
||||
}
|
||||
|
||||
func newHandler(service *Service, appConfig appconfig.AppConfigResolver) *handler {
|
||||
return &handler{service: service, appConfig: appConfig}
|
||||
}
|
||||
|
||||
// syncLdap godoc
|
||||
// @Summary Synchronize LDAP
|
||||
// @Description Manually trigger LDAP synchronization
|
||||
// @Tags Application Configuration
|
||||
// @Success 204 "No Content"
|
||||
// @Router /api/application-configuration/sync-ldap [post]
|
||||
func (h *handler) syncLdap(c *gin.Context) error {
|
||||
dbConfig, err := h.appConfig.GetConfig(c.Request.Context())
|
||||
if err != nil {
|
||||
return fmt.Errorf("error loading app configuration: %w", err)
|
||||
}
|
||||
|
||||
// The sync runs inline rather than through the actor, so the response reports whether it succeeded
|
||||
err = h.service.SyncAll(c.Request.Context(), dbConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Status(http.StatusNoContent)
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user