Documentation
¶
Overview ¶
Package periodicjobs provides scheduled background jobs for the usernaut controller.
This file implements the user offboarding periodic job that automatically removes inactive users from all backend systems when they are no longer found in LDAP.
Index ¶
Constants ¶
const ( // UserOffboardingJobName is the unique identifier for the user offboarding periodic job. UserOffboardingJobName = "usernaut_user_offboarding" // UserOffboardingJobInterval defines how often the user offboarding job runs. // Set to 24 hours to perform daily cleanup of inactive users. UserOffboardingJobInterval = 24 * time.Hour )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PeriodicTask ¶
type PeriodicTaskManager ¶
type PeriodicTaskManager struct {
Tasks []PeriodicTask
}
func NewPeriodicTaskManager ¶
func NewPeriodicTaskManager() *PeriodicTaskManager
NewPeriodicTaskManager creates a new PeriodicTaskManager used manage interval based tasks
func (*PeriodicTaskManager) AddTask ¶
func (p *PeriodicTaskManager) AddTask(task PeriodicTask)
func (*PeriodicTaskManager) RunAll ¶
func (p *PeriodicTaskManager) RunAll(ctx context.Context) error
RunAll runs all the tasks in the PeriodicTaskManager it launches a new goroutine for each task and stops when the context is canceled it uses a ticker to run the tasks at the specified interval (from the task) and stops when the context is canceled If interval == -1, the task is run only once.
type UserOffboardingJob ¶
type UserOffboardingJob struct {
// contains filtered or unexported fields
}
UserOffboardingJob implements a periodic job that monitors user activity and automatically offboards inactive users from all configured backends.
The job performs the following operations:
- Scans Redis cache for all user entries
- Verifies each user's status in LDAP directory
- Offboards users who are no longer active in LDAP from all backends
- Removes inactive users from the cache
This ensures that user access is automatically revoked when users leave the organization or become inactive in the LDAP directory.
func NewUserOffboardingJob ¶
func NewUserOffboardingJob( sharedCacheMutex *sync.RWMutex, dataStore *store.Store, ldapClient ldap.LDAPClient, backendClients map[string]clients.Client, ) *UserOffboardingJob
NewUserOffboardingJob creates and initializes a new UserOffboardingJob instance.
This constructor:
- Loads the application configuration
- Initializes cache and LDAP clients
- Sets up all enabled backend clients
- Returns a fully configured job ready for execution
Parameters:
- sharedCacheMutex: Shared mutex to prevent race conditions with other components
- dataStore: Shared store instance with prefixed keys
- ldapClient: Shared LDAP client instance
- backendClients: Map of initialized backend clients
Returns:
- *UserOffboardingJob: A configured job instance
func (*UserOffboardingJob) AddToPeriodicTaskManager ¶
func (uoj *UserOffboardingJob) AddToPeriodicTaskManager(mgr *PeriodicTaskManager)
AddToPeriodicTaskManager registers this job with the provided periodic task manager.
This method integrates the user offboarding job into the controller's periodic task execution system, allowing it to run at the configured interval.
Parameters:
- mgr: The PeriodicTaskManager instance to register this job with
func (*UserOffboardingJob) GetInterval ¶
func (uoj *UserOffboardingJob) GetInterval() time.Duration
GetInterval returns the execution interval for this periodic job.
This method is required by the PeriodicTask interface and defines how often the user offboarding job should be executed.
Returns:
- time.Duration: The interval between job executions (24 hours)
func (*UserOffboardingJob) GetName ¶
func (uoj *UserOffboardingJob) GetName() string
GetName returns the unique name identifier for this periodic job.
This method is required by the PeriodicTask interface and provides a human-readable name for logging and monitoring purposes.
Returns:
- string: The job name "usernaut_user_offboarding"
func (*UserOffboardingJob) Run ¶
func (uoj *UserOffboardingJob) Run(ctx context.Context) error
Run executes the main user offboarding logic.
This method is required by the PeriodicTask interface and contains the core business logic for identifying and offboarding inactive users.
The execution flow:
- Retrieves all user keys from the cache
- Processes each user to check LDAP status
- Offboards users who are inactive in LDAP
- Reports execution results and any errors
Parameters:
- ctx: Context for cancellation and logging
Returns:
- error: Any fatal error that occurred during execution, or a summary of non-fatal errors if any users failed to process