entrasync

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

README

go-entrasync

A thin Microsoft Graph reader for Entra.

Fetches users, security groups, and transitive group memberships via the Graph API. Persistence is the caller's responsibility.

Usage

import entrasync "github.com/woodleighschool/go-entrasync"

client, err := entrasync.NewClient(entrasync.Config{
    TenantID:     "...",
    ClientID:     "...",
    ClientSecret: "...",
})
if err != nil {
    return err
}

snapshot, err := client.Snapshot(ctx)
// snapshot.Users, snapshot.Groups, snapshot.Members

Config

Field Default Description
TenantID required Azure tenant ID
ClientID required App registration client ID
ClientSecret required App registration client secret
GroupMemberConcurrency 8 Parallel group member fetches during Snapshot

Versioning

Tagged releases follow semver. Use go get github.com/woodleighschool/go-entrasync@latest for the latest release.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client wraps a Microsoft Graph client for Entra bulk-fetch operations.

func NewClient

func NewClient(graph *msgraphsdk.GraphServiceClient, opts ...Option) *Client

NewClient creates an entrasync client using an existing Graph service client. The caller is responsible for creating and managing the Graph client's lifecycle.

func (*Client) FetchGroupMembers

func (c *Client) FetchGroupMembers(ctx context.Context, groupID uuid.UUID) ([]uuid.UUID, error)

FetchGroupMembers returns enabled member user IDs for the group's transitive membership.

func (*Client) FetchGroups

func (c *Client) FetchGroups(ctx context.Context) ([]Group, error)

FetchGroups returns security enabled groups.

func (*Client) FetchUsers

func (c *Client) FetchUsers(ctx context.Context) ([]User, error)

FetchUsers returns enabled member users.

func (*Client) Snapshot

func (c *Client) Snapshot(ctx context.Context) (*Snapshot, error)

Snapshot fetches users, groups, and optionally transitive group memberships. Memberships are only fetched when the client was created with WithTransitiveMemberships.

type Group

type Group struct {
	ID          uuid.UUID
	DisplayName string
	Description string
}

Group is a minimal Entra group record returned by Graph.

type Option

type Option func(*Client)

Option configures optional Client behaviour.

func WithGroupMemberConcurrency

func WithGroupMemberConcurrency(n int) Option

WithGroupMemberConcurrency overrides the default parallelism (8) used when fetching group members during Snapshot. Values <= 0 are ignored.

func WithTransitiveMemberships

func WithTransitiveMemberships() Option

WithTransitiveMemberships fetches transitive group memberships during Snapshot. Without this option, Snapshot.Members is nil.

func WithUserFields

func WithUserFields(fields ...UserField) Option

WithUserFields requests additional user properties from Graph beyond the default set (id, displayName, userPrincipalName). Fields not requested are left as zero values on User.

type Snapshot

type Snapshot struct {
	Users   []User
	Groups  []Group
	Members map[uuid.UUID][]uuid.UUID // group ID → member IDs
}

Snapshot holds all users, groups, and group memberships fetched from Entra.

type User

type User struct {
	// Always fetched
	ID          uuid.UUID
	DisplayName string
	UPN         string

	// Fetched only when requested via WithUserFields; zero-value otherwise.
	Department     string
	MailNickname   string
	OfficeLocation string
	EmployeeID     string
	CompanyName    string
}

User is an Entra user record returned by Graph.

type UserField

type UserField string

UserField is a Graph API user property name that can be requested beyond the default set (id, displayName, userPrincipalName).

const (
	FieldDepartment     UserField = "department"
	FieldMailNickname   UserField = "mailNickname"
	FieldOfficeLocation UserField = "officeLocation"
	FieldEmployeeID     UserField = "employeeId"
	FieldCompanyName    UserField = "companyName"
)

Jump to

Keyboard shortcuts

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