mapper

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package mapper provides mapping between SCIM resources and CoreForge entities.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPrincipalType = errors.New("principal must be of type human for SCIM User mapping")

ErrInvalidPrincipalType is returned when attempting to map a non-human principal to SCIM User.

Functions

func ParseGroupID

func ParseGroupID(id string) (uuid.UUID, error)

ParseGroupID parses a SCIM group ID to a UUID.

func ParsePrincipalID

func ParsePrincipalID(id string) (uuid.UUID, error)

ParsePrincipalID parses a SCIM user ID to a UUID.

func ParseUserID

func ParseUserID(id string) (uuid.UUID, error)

ParseUserID parses a SCIM user ID to a UUID.

Types

type Config

type Config struct {
	// BaseURL is the base URL for SCIM resources.
	BaseURL string

	// IncludeGroups determines whether to include group memberships in user resources.
	IncludeGroups bool

	// IncludeMembers determines whether to include members in group resources.
	IncludeMembers bool
}

Config contains configuration for mappers.

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns the default mapper configuration.

type EnterpriseExtension

type EnterpriseExtension struct {
	EmployeeNumber string `json:"employee_number,omitempty"`
	CostCenter     string `json:"cost_center,omitempty"`
	Organization   string `json:"organization,omitempty"`
	Division       string `json:"division,omitempty"`
	Department     string `json:"department,omitempty"`
	ManagerID      string `json:"manager_id,omitempty"`
}

EnterpriseExtension contains enterprise user extension data. This is stored as metadata on the user in CoreForge.

func (*EnterpriseExtension) IsEmpty

func (ext *EnterpriseExtension) IsEmpty() bool

IsEmpty returns true if the extension has no data.

type ExtensionMapper

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

ExtensionMapper maps enterprise extension data.

func NewExtensionMapper

func NewExtensionMapper(config *Config) *ExtensionMapper

NewExtensionMapper creates a new extension mapper.

func (*ExtensionMapper) FromMetadata

func (m *ExtensionMapper) FromMetadata(metadata map[string]any) *EnterpriseExtension

FromMetadata converts a metadata map to enterprise extension.

func (*ExtensionMapper) FromSCIM

func (m *ExtensionMapper) FromSCIM(ctx context.Context, enterprise *scim.EnterpriseUser) *EnterpriseExtension

FromSCIM converts SCIM EnterpriseUser to enterprise extension metadata.

func (*ExtensionMapper) ToMetadata

func (m *ExtensionMapper) ToMetadata(ext *EnterpriseExtension) map[string]any

ToMetadata converts enterprise extension to a metadata map.

func (*ExtensionMapper) ToSCIM

ToSCIM converts enterprise extension metadata to SCIM EnterpriseUser.

type GroupMapper

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

GroupMapper maps between SCIM Group resources and CoreForge Organization entities.

func NewGroupMapper

func NewGroupMapper(config *Config) *GroupMapper

NewGroupMapper creates a new group mapper.

func (*GroupMapper) ApplyPatch

ApplyPatch applies PATCH operations to an OrganizationInfo.

func (*GroupMapper) FromSCIM

func (m *GroupMapper) FromSCIM(ctx context.Context, scimGroup *scim.Group) (*identity.CreateOrganizationInput, error)

FromSCIM converts a SCIM Group to a CoreForge CreateOrganizationInput.

func (*GroupMapper) ToSCIM

ToSCIM converts a CoreForge OrganizationInfo to a SCIM Group.

func (*GroupMapper) ToSCIMWithMembers

func (m *GroupMapper) ToSCIMWithMembers(ctx context.Context, org *identity.OrganizationInfo, members []*identity.MembershipInfo, memberNames map[uuid.UUID]string) (*scim.Group, error)

ToSCIMWithMembers converts a CoreForge OrganizationInfo to a SCIM Group with members.

func (*GroupMapper) ToSCIMWithMeta

func (m *GroupMapper) ToSCIMWithMeta(ctx context.Context, org *identity.OrganizationInfo, createdAt, updatedAt time.Time) (*scim.Group, error)

ToSCIMWithMeta converts a CoreForge OrganizationInfo to a SCIM Group with metadata timestamps.

func (*GroupMapper) ToUpdateInput

func (m *GroupMapper) ToUpdateInput(ctx context.Context, scimGroup *scim.Group) (*identity.UpdateOrganizationInput, error)

ToUpdateInput converts a SCIM Group to a CoreForge UpdateOrganizationInput.

type Mapper

type Mapper[S any, E any] interface {
	// ToSCIM converts a CoreForge entity to a SCIM resource.
	ToSCIM(ctx context.Context, entity E) (S, error)

	// FromSCIM converts a SCIM resource to a CoreForge entity or update input.
	// Returns an interface{} that can be either a create input or update input.
	FromSCIM(ctx context.Context, resource S) (any, error)

	// ApplyPatch applies PATCH operations to an entity.
	ApplyPatch(ctx context.Context, entity E, ops []patch.Operation) (E, error)
}

Mapper defines the interface for mapping between SCIM resources and CoreForge entities.

type MemberOperation

type MemberOperation struct {
	Op     patch.OperationType
	UserID uuid.UUID
}

MemberOperation represents a member add/remove operation.

type PrincipalUserMapper

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

PrincipalUserMapper maps between SCIM User resources and CoreForge Principal+Human entities. This mapper wraps the Principal-centric identity model where SCIM Users map to Principal(type=human) with an associated Human extension.

func NewPrincipalUserMapper

func NewPrincipalUserMapper(config *Config) *PrincipalUserMapper

NewPrincipalUserMapper creates a new principal user mapper.

func (*PrincipalUserMapper) ApplyPatch

ApplyPatch applies PATCH operations to a Principal and returns an UpdateHumanInput.

func (*PrincipalUserMapper) FromSCIM

func (m *PrincipalUserMapper) FromSCIM(ctx context.Context, scimUser *scim.User) (*principal.CreateHumanInput, error)

FromSCIM converts a SCIM User to a CoreForge CreateHumanInput.

func (*PrincipalUserMapper) ToSCIM

ToSCIM converts a CoreForge Principal (with Human extension) to a SCIM User.

func (*PrincipalUserMapper) ToSCIMWithMeta

func (m *PrincipalUserMapper) ToSCIMWithMeta(ctx context.Context, p *principal.Principal, createdAt, updatedAt time.Time) (*scim.User, error)

ToSCIMWithMeta converts a CoreForge Principal to a SCIM User with metadata timestamps.

func (*PrincipalUserMapper) ToUpdateInput

func (m *PrincipalUserMapper) ToUpdateInput(ctx context.Context, scimUser *scim.User) (*principal.UpdateHumanInput, error)

ToUpdateInput converts a SCIM User to a CoreForge UpdateHumanInput.

type UserMapper

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

UserMapper maps between SCIM User resources and CoreForge User entities.

func NewUserMapper

func NewUserMapper(config *Config) *UserMapper

NewUserMapper creates a new user mapper.

func (*UserMapper) ApplyPatch

func (m *UserMapper) ApplyPatch(ctx context.Context, user *identity.UserInfo, ops []patch.Operation) (*identity.UpdateUserInput, error)

ApplyPatch applies PATCH operations to a UserInfo.

func (*UserMapper) FromSCIM

func (m *UserMapper) FromSCIM(ctx context.Context, scimUser *scim.User) (*identity.CreateUserInput, error)

FromSCIM converts a SCIM User to a CoreForge CreateUserInput.

func (*UserMapper) ToSCIM

func (m *UserMapper) ToSCIM(ctx context.Context, user *identity.UserInfo) (*scim.User, error)

ToSCIM converts a CoreForge UserInfo to a SCIM User.

func (*UserMapper) ToSCIMWithMeta

func (m *UserMapper) ToSCIMWithMeta(ctx context.Context, user *identity.UserInfo, createdAt, updatedAt time.Time) (*scim.User, error)

ToSCIMWithMeta converts a CoreForge UserInfo to a SCIM User with metadata timestamps.

func (*UserMapper) ToUpdateInput

func (m *UserMapper) ToUpdateInput(ctx context.Context, scimUser *scim.User) (*identity.UpdateUserInput, error)

ToUpdateInput converts a SCIM User to a CoreForge UpdateUserInput.

Jump to

Keyboard shortcuts

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