Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `pwsh -NoProfile -File ./tools/Invoke-IdleScriptAnalyzer.ps1`
- **Generated references** under `docs/reference/` are never edited by hand. Regenerate them with
`./tools/Generate-IdleCmdletReference.ps1` and `./tools/Generate-IdleStepReference.ps1` (see `CONTRIBUTING.md`).
- **Branch names** for issue work: `issues/<issueNumber>-<sanitizedTitle>`.
- **Branch names** follow the branching model in `CONTRIBUTING.md` (`<prefix>/<issueNumber>-<short-description>`,
e.g. `feature/292-...`).
- On pull requests, CI restores `.claude/` and `CLAUDE.md` from the base branch. Changes to these files only take
effect for reviews after they are merged.
14 changes: 11 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,17 @@ git clone https://github.com/blindzero/IdentityLifecycleEngine.git
### Branching Model

- `main` → stable
- feature branches:
- `feature/<short-description>`
- `fix/<short-description>`
- work branches: `<prefix>/<issueNumber>-<short-description>` (omit `<issueNumber>-` if there is no issue)

| Prefix | Use for |
| --- | --- |
| `feature/` | new functionality |
| `fix/` or `hotfix/` | bug fixes or urgent fixes for a released version |
| `ci/` | CI/CD workflows and build tooling |
| `docs/` | documentation only |
| `chore/` | maintenance (dependencies, cleanup, repo housekeeping) |

Example: `feature/292-step-handler-registration-via-catalog`

---

Expand Down
54 changes: 51 additions & 3 deletions docs/extend/steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,57 @@ Every step type registered with the engine **must** declare a data-only metadata
- A key must not appear in both sets.
- Metadata must be data-only — ScriptBlocks are rejected.

Step pack modules expose their catalog via `Get-IdleStepMetadataCatalog`, which loads from a
`StepMetadataCatalog.psd1` data file. Host-supplied step types may supplement (but not override)
the catalog via `Providers.StepMetadata`.
Host-supplied step types may supplement (but not override) the catalog via `Providers.StepMetadata`.

### Step packs

A step pack is a module that ships a `StepMetadataCatalog.psd1` data file and declares it in its
module manifest. The engine discovers every loaded module carrying this marker:

```powershell
# Contoso.IdLE.Steps.Hr.psd1
@{
# ...
FunctionsToExport = @('Invoke-ContosoStepSyncManager')
PrivateData = @{
IdLE = @{
Kind = 'StepPack'
StepCatalog = 'StepMetadataCatalog.psd1' # relative to the module folder
}
}
}
```

Each catalog entry declares its handler with the `Handler` key. The engine registers it automatically,
so hosts do not need `Providers.StepRegistry` for step pack steps:

```powershell
# Contoso.IdLE.Steps.Hr/StepMetadataCatalog.psd1
@{
'Contoso.IdLE.Step.Hr.SyncManager' = @{
Handler = 'Invoke-ContosoStepSyncManager'
RequiredCapabilities = @('Contoso.IdLE.Hr.Manager.Read')
WithSchema = @{
RequiredKeys = @('IdentityKey')
OptionalKeys = @('Provider', 'AuthSessionName', 'AuthSessionOptions')
}
}
}
```

**Rules:**

- `Handler` is a function name (string) exported by the step pack module. It is bound to the declaring
module (`Contoso.IdLE.Steps.Hr\Invoke-ContosoStepSyncManager`); a handler from another module is rejected.
- The module does not need to be imported globally; nested modules work.
- `StepCatalog` must point to a file inside the module folder.
- A step type may be defined by only one step pack.
- `Providers.StepRegistry` still takes precedence over catalog handlers (e.g. to replace a step in tests).
- `Providers.StepMetadata` must not declare `Handler`; host-defined steps register their handler via
`Providers.StepRegistry`.

Modules named `IdLE.Steps.*` that export `Get-IdleStepMetadataCatalog` but carry no marker are still
discovered. This fallback is deprecated.

Metadata exists to make steps:

Expand Down
2 changes: 1 addition & 1 deletion src/IdLE.Core/Private/ConvertTo-IdleWorkflowSteps.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function ConvertTo-IdleWorkflowSteps {
else {
# Workflow references a Step.Type for which no StepMetadata entry is available - fail fast.
$errorMessage = "MissingStepTypeMetadata: Workflow step '$stepName' references step type '$stepType' which has no metadata entry. " + `
"To resolve this: (1) Import/load the step pack module (IdLE.Steps.*) that provides metadata for '$stepType' via Get-IdleStepMetadataCatalog, OR " + `
"To resolve this: (1) Import/load the step pack module (manifest PrivateData.IdLE.Kind = 'StepPack') that provides metadata for '$stepType', OR " + `
"(2) For host-defined/custom step types only, provide Providers.StepMetadata['$stepType'] = @{ RequiredCapabilities = @(...) }."
throw [System.InvalidOperationException]::new($errorMessage)
}
Expand Down
161 changes: 11 additions & 150 deletions src/IdLE.Core/Private/Get-IdleStepRegistry.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,6 @@ function Get-IdleStepRegistry {

$registry = [hashtable]::new([System.StringComparer]::OrdinalIgnoreCase)

# Helper: Resolve a step handler name without requiring global command exports.
#
# Resolution order:
# 1) Global command discovery (host imported a module globally) -> "Invoke-IdleStepX"
# 2) Module-scoped discovery (nested/hidden module loaded) -> "ModuleName\Invoke-IdleStepX"
function Resolve-IdleStepHandlerName {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $CommandName,

[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[string] $ModuleName
)

# 1) Global discovery (optional; supports hosts that import step packs globally)
$cmd = Get-Command -Name $CommandName -ErrorAction SilentlyContinue
if ($null -ne $cmd) {
return $cmd.Name
}

# 2) Module-scoped discovery (supports nested modules that are not globally exported)
$module = Get-Module -Name $ModuleName -All | Select-Object -First 1
if ($null -eq $module) {
return $null
}

if ($null -ne $module.ExportedCommands -and $module.ExportedCommands.ContainsKey($CommandName)) {

# Use a module-qualified command name so the engine can invoke it without relying on
# global session exports. This keeps built-in steps available "within IdLE" only.
return "$($module.Name)\$CommandName"
}

return $null
}

# 1) Copy host-provided StepRegistry (optional)
# We support two shapes for compatibility:
# - Providers.StepRegistry (hashtable)
Expand Down Expand Up @@ -102,121 +63,21 @@ function Get-IdleStepRegistry {
}
}

# 2) Register built-in steps if available.
# 2) Register handlers declared by loaded step packs (StepMetadataCatalog 'Handler' key).
#
# Built-in steps are first-party step packs (e.g. IdLE.Steps.Common). They may be loaded as nested
# modules by the IdLE meta module. In that case, the step commands are not necessarily exported
# globally. We therefore support module-qualified handler names.
if (-not $registry.ContainsKey('IdLE.Step.EmitEvent')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepEmitEvent' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.EmitEvent'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.EnsureAttributes')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepEnsureAttributes' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.EnsureAttributes'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.EnsureEntitlement')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepEnsureEntitlement' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.EnsureEntitlement'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.CreateIdentity')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepCreateIdentity' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.CreateIdentity'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.DisableIdentity')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepDisableIdentity' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.DisableIdentity'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.EnableIdentity')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepEnableIdentity' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.EnableIdentity'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.MoveIdentity')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepMoveIdentity' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.MoveIdentity'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.DeleteIdentity')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepDeleteIdentity' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.DeleteIdentity'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.RevokeIdentitySessions')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepRevokeIdentitySessions' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.RevokeIdentitySessions'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.PruneEntitlements')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepPruneEntitlements' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.PruneEntitlements'] = $handler
}
}
# First-party and third-party step packs declare their handlers the same way. Handler names are
# module-qualified, so step packs loaded as nested modules (e.g. by the IdLE meta module) work without
# exporting their commands globally. Host-provided entries from (1) take precedence.
$stepPackCatalog = Resolve-IdleStepMetadataCatalog -Providers $null

if (-not $registry.ContainsKey('IdLE.Step.PruneEntitlementsEnsureKeep')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepPruneEntitlementsEnsureKeep' -ModuleName 'IdLE.Steps.Common'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.PruneEntitlementsEnsureKeep'] = $handler
foreach ($stepType in $stepPackCatalog.Keys) {
if ($registry.ContainsKey($stepType)) {
continue
}
}

if (-not $registry.ContainsKey('IdLE.Step.TriggerDirectorySync')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepTriggerDirectorySync' -ModuleName 'IdLE.Steps.DirectorySync'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.TriggerDirectorySync'] = $handler
}
}

# Mailbox steps (IdLE.Steps.Mailbox module)
if (-not $registry.ContainsKey('IdLE.Step.Mailbox.EnsureOutOfOffice')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepMailboxOutOfOfficeEnsure' -ModuleName 'IdLE.Steps.Mailbox'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.Mailbox.EnsureOutOfOffice'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.Mailbox.GetInfo')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepMailboxGetInfo' -ModuleName 'IdLE.Steps.Mailbox'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.Mailbox.GetInfo'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.Mailbox.EnsureType')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepMailboxTypeEnsure' -ModuleName 'IdLE.Steps.Mailbox'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.Mailbox.EnsureType'] = $handler
}
}

if (-not $registry.ContainsKey('IdLE.Step.Mailbox.EnsurePermissions')) {
$handler = Resolve-IdleStepHandlerName -CommandName 'Invoke-IdleStepMailboxPermissionsEnsure' -ModuleName 'IdLE.Steps.Mailbox'
if (-not [string]::IsNullOrWhiteSpace($handler)) {
$registry['IdLE.Step.Mailbox.EnsurePermissions'] = $handler
$metadata = $stepPackCatalog[$stepType]
if ($metadata.ContainsKey('Handler')) {
$registry[$stepType] = $metadata['Handler']
}
}

Expand Down
Loading
Loading