Repository navigation
core: enforce identifier namespaces for step types and capabilities (#322) #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ffc26b3
core: enforce identifier namespaces for step types and capabilities (…
blindzero d59d8cc
Merge branch 'main' into feature/322-identifier-namespaces
blindzero 143245e
core: validate first-party step type shape (IdLE.Step.<Name>|<Area>.<…
claude[bot] 0017ce5
core: validate first-party step type shape (IdLE.Step.<Name>)
claude[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| # ReservedNamespaces.psd1 - IdLE.Core | ||
| # | ||
| # Data-only single source of truth for identifier namespaces (no ScriptBlocks). | ||
| # | ||
| # Rules (owner first, then product): | ||
| # - 'IdLE.' is reserved for the IdLE project (first-party modules shipped in the IdLE bundle). | ||
| # - Extensions (every other module, host or organization) use '<Owner>.IdLE.<...>', e.g. 'Contoso.IdLE.Step.Hr.SyncManager'. | ||
| # | ||
| # Each identifier kind declares: | ||
| # ExtensionPattern - regex an extension identifier must match | ||
| # Example - extension example used in error messages | ||
| @{ | ||
| ReservedPrefix = 'IdLE.' | ||
|
|
||
| StepType = @{ | ||
| FirstPartyPattern = '^IdLE\.Step(\.[A-Za-z][A-Za-z0-9]*)+$' | ||
| ExtensionPattern = '^(?!IdLE\.)[A-Za-z][A-Za-z0-9]*\.IdLE\.Step(\.[A-Za-z][A-Za-z0-9]*)+$' | ||
| Example = 'Contoso.IdLE.Step.Hr.SyncManager' | ||
| } | ||
|
|
||
| Capability = @{ | ||
| ExtensionPattern = '^(?!IdLE\.)[A-Za-z][A-Za-z0-9]*\.IdLE(\.[A-Za-z][A-Za-z0-9]*){2,}$' | ||
| Example = 'Contoso.IdLE.Hr.Manager.Read' | ||
|
|
||
| # Capabilities defined by IdLE. 'IdLE.*' capabilities not listed here are rejected, | ||
| # whether advertised by a provider or required by step metadata. | ||
| # Keep in sync with docs/reference/capabilities.md (enforced by tests). | ||
| Defined = @( | ||
| 'IdLE.DirectorySync.Status' | ||
| 'IdLE.DirectorySync.Trigger' | ||
| 'IdLE.Entitlement.Grant' | ||
| 'IdLE.Entitlement.List' | ||
| 'IdLE.Entitlement.Prune' | ||
| 'IdLE.Entitlement.Revoke' | ||
| 'IdLE.Identity.Attribute.Ensure' | ||
| 'IdLE.Identity.Create' | ||
| 'IdLE.Identity.Delete' | ||
| 'IdLE.Identity.Disable' | ||
| 'IdLE.Identity.Enable' | ||
| 'IdLE.Identity.List' | ||
| 'IdLE.Identity.Move' | ||
| 'IdLE.Identity.Read' | ||
| 'IdLE.Identity.RevokeSessions' | ||
| 'IdLE.Mailbox.Info.Read' | ||
| 'IdLE.Mailbox.OutOfOffice.Ensure' | ||
| 'IdLE.Mailbox.Permissions.Ensure' | ||
| 'IdLE.Mailbox.Type.Ensure' | ||
| ) | ||
|
|
||
| # Deprecated capability -> replacement. Accepted with a warning and mapped to the replacement. | ||
| Deprecated = @{ | ||
| 'IdLE.Mailbox.Read' = 'IdLE.Mailbox.Info.Read' | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/IdLE.Core/Private/Get-IdleIdentifierNamespaceError.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| function Get-IdleIdentifierNamespaceError { | ||
| <# | ||
| .SYNOPSIS | ||
| Checks an identifier against the namespace rules and returns an error message, or $null if valid. | ||
|
|
||
| .DESCRIPTION | ||
| Rules (see Data/ReservedNamespaces.psd1): | ||
| - StepType: 'IdLE.*' only from first-party modules; extensions use '<Owner>.IdLE.Step.<...>'. | ||
| - Capability: 'IdLE.*' only if defined by IdLE (or a deprecated alias); extensions use '<Owner>.IdLE.<Domain>.<Verb>'. | ||
|
|
||
| Messages start with a stable error code (ReservedNamespace, InvalidExtensionNamespace, UnknownCapability). | ||
|
|
||
| .PARAMETER Kind | ||
| Identifier kind: StepType or Capability. | ||
|
|
||
| .PARAMETER Identifier | ||
| The identifier to check. | ||
|
|
||
| .PARAMETER FirstParty | ||
| The identifier is defined by a first-party module (StepType only). | ||
|
|
||
| .OUTPUTS | ||
| System.String (error message) or $null. | ||
| #> | ||
| [CmdletBinding()] | ||
| param( | ||
| [Parameter(Mandatory)] | ||
| [ValidateSet('StepType', 'Capability')] | ||
| [string] $Kind, | ||
|
|
||
| [Parameter(Mandatory)] | ||
| [ValidateNotNullOrEmpty()] | ||
| [string] $Identifier, | ||
|
|
||
| [Parameter()] | ||
| [switch] $FirstParty | ||
| ) | ||
|
|
||
| $rules = Get-IdleReservedNamespaces | ||
| $kindRules = $rules[$Kind] | ||
| $label = if ($Kind -eq 'StepType') { 'Step type' } else { 'Capability' } | ||
|
|
||
| if ($Identifier.StartsWith($rules.ReservedPrefix, [System.StringComparison]::OrdinalIgnoreCase)) { | ||
| if ($Kind -eq 'Capability') { | ||
| if ($kindRules.Defined -contains $Identifier -or $kindRules.Deprecated.ContainsKey($Identifier)) { | ||
| return $null | ||
| } | ||
|
|
||
| $hint = "Extensions define their own capabilities as '<Owner>.IdLE.<Domain>.<Verb>', e.g. '$($kindRules.Example)'." | ||
| return "UnknownCapability: Capability '$Identifier' is not defined by IdLE (see docs/reference/capabilities.md). $hint" | ||
| } | ||
|
|
||
| if ($FirstParty) { | ||
| # Catch catalog typos such as 'IdLE.Foo.Bar' before they become valid workflow step types. | ||
| if ($Identifier -notmatch $kindRules.FirstPartyPattern) { | ||
| return "InvalidFirstPartyStepType: $label '$Identifier' must follow 'IdLE.Step.<Name>' (e.g. 'IdLE.Step.EmitEvent' or 'IdLE.Step.Mailbox.GetInfo')." | ||
| } | ||
|
|
||
| return $null | ||
| } | ||
|
|
||
| $suffix = $Identifier.Substring($rules.ReservedPrefix.Length) | ||
| $hint = "Use '<Owner>.IdLE.$suffix', e.g. 'Contoso.IdLE.$suffix'." | ||
| return "ReservedNamespace: $label '$Identifier' uses the reserved prefix '$($rules.ReservedPrefix)'. $hint" | ||
| } | ||
|
|
||
| if ($Identifier -notmatch $kindRules.ExtensionPattern) { | ||
| return "InvalidExtensionNamespace: $label '$Identifier' must follow '<Owner>.IdLE.<...>', e.g. '$($kindRules.Example)'." | ||
| } | ||
|
|
||
| return $null | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| function Get-IdleReservedNamespaces { | ||
| <# | ||
| .SYNOPSIS | ||
| Returns the identifier namespace rules (Data/ReservedNamespaces.psd1). | ||
|
|
||
| .DESCRIPTION | ||
| The rules are data-only and loaded once per module session. | ||
|
|
||
| .OUTPUTS | ||
| Hashtable with ReservedPrefix and one entry per identifier kind (StepType, Capability). | ||
| #> | ||
| [CmdletBinding()] | ||
| param() | ||
|
|
||
| $rules = Get-Variable -Name 'IdleReservedNamespaces' -Scope Script -ValueOnly -ErrorAction SilentlyContinue | ||
| if ($null -eq $rules) { | ||
| $path = Join-Path -Path (Split-Path -Path $PSScriptRoot -Parent) -ChildPath 'Data/ReservedNamespaces.psd1' | ||
| $rules = Import-PowerShellDataFile -LiteralPath $path | ||
| Set-Variable -Name 'IdleReservedNamespaces' -Scope Script -Value $rules | ||
| } | ||
|
|
||
| return $rules | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.