groupsync

package
v2.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

This package provides utility to deal with the group synchronization issue.

The "groups" attribute of the User resource is a readOnly attribute, which shall be updated according to the change of "members" in Group resources. This package provides mere utilities that may be helpful, it does not assume a certain way to resolve this issue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Diff

type Diff struct {
	// contains filtered or unexported fields
}

Diff reports the difference between the members of two group resources.

func Compare

func Compare(before *prop.Resource, after *prop.Resource) *Diff

Compare compares the two snapshots of two group resources before and after the modification and reports their differences in membership. At least one of before and after should be non-nil. When before is nil, all members of the after resource are considered to have just joined; when after is nil, all members of the before resource are considered to have just left.

func (*Diff) CountJoined

func (d *Diff) CountJoined() int

CountJoined returns the total number of new members that joined the group.

func (*Diff) CountLeft

func (d *Diff) CountLeft() int

CountLeft returns the total number of members that just left the group.

func (*Diff) ForEachJoined

func (d *Diff) ForEachJoined(callback func(id string))

ForEachJoined iterates all member ids that joined the group and invoke the callback.

func (*Diff) ForEachLeft

func (d *Diff) ForEachLeft(callback func(id string))

ForEachLeft iterates all member ids that left the group and invoke the callback.

type SyncService

type SyncService struct {
	// contains filtered or unexported fields
}

SyncService synchronizes the user resource's "groups" property.

func NewSyncService

func NewSyncService(groupDB db.DB) *SyncService

NewSyncService returns a new SyncService.

func (*SyncService) SyncGroupPropertyForUser

func (s *SyncService) SyncGroupPropertyForUser(ctx context.Context, user *prop.Resource) error

SyncGroupPropertyForUser updates the user's "groups" property, according to the latest state in Group resources. This method does not save or replace the updated resource with the database. It is up to the caller to do so.

Due to nested membership, this method may search the group database multiple times, which may turn out to be a lengthy process. The ctx context can be used to set a timeline or cancel the processing, this method will respect that at appropriate intervals.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL