From 4ae8ed9eefb6b8773b33310854fb3e9d74f3cf1e Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Thu, 14 Dec 2023 14:12:10 +0300 Subject: [PATCH 1/6] Rectified metadata script to generate correct paths with nested segments containing microsoft.graph prefix --- .../custom/common/MgCommandMetadata.json | 8 ++++---- tools/PostGeneration/NewCommandMetadata.ps1 | 13 ++++++++----- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Authentication/Authentication/custom/common/MgCommandMetadata.json b/src/Authentication/Authentication/custom/common/MgCommandMetadata.json index 2c9c429b2b9..20d5e6fda6d 100644 --- a/src/Authentication/Authentication/custom/common/MgCommandMetadata.json +++ b/src/Authentication/Authentication/custom/common/MgCommandMetadata.json @@ -95132,7 +95132,7 @@ }, { "Module": "Beta.Identity.SignIns", - "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders", + "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStartonAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders", "OutputType": "IMicrosoftGraphIdentityProviderBase", "Method": "GET", "ApiVersion": "beta", @@ -95208,7 +95208,7 @@ }, { "Module": "Beta.Identity.SignIns", - "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref", + "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStartonAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref", "OutputType": null, "Method": "GET", "ApiVersion": "beta", @@ -95220,7 +95220,7 @@ }, { "Module": "Beta.Identity.SignIns", - "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$count", + "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStartonAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$count", "OutputType": null, "Method": "GET", "ApiVersion": "beta", @@ -305344,7 +305344,7 @@ }, { "Module": "Beta.Identity.SignIns", - "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref", + "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStartonAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref", "OutputType": null, "Method": "POST", "ApiVersion": "beta", diff --git a/tools/PostGeneration/NewCommandMetadata.ps1 b/tools/PostGeneration/NewCommandMetadata.ps1 index c273d259b0f..e5316726e62 100644 --- a/tools/PostGeneration/NewCommandMetadata.ps1 +++ b/tools/PostGeneration/NewCommandMetadata.ps1 @@ -61,13 +61,16 @@ $ApiVersion | ForEach-Object { # Remove FQN in action/function names. if ($Uri -match $ActionFunctionFQNPattern) { $MatchedUriSegment = $Matches.0 + $SegmentBuilder = "" # Trim nested namespace segments. - $NestedNamespaceSegments = $Matches.1 -split "\." - # Remove trailing '()' from functions. - $LastSegment = $NestedNamespaceSegments[-1] -replace "\(\)", "" - $Uri = $Uri -replace [Regex]::Escape($MatchedUriSegment), "/$LastSegment" + $NestedNamespaceSegments = $Matches.1 -split "/" + # Remove microsoft.graph prefix and remove trailing '()' from functions. + foreach($segment in $NestedNamespaceSegments){ + $segment = $segment.Replace("microsoft.graph.","").Replace("()", "") + $SegmentBuilder += "/$segment" + } + $Uri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder } - $MappingValue = @{ Command = $CommandName Variants = [System.Collections.ArrayList]@($VariantName) From c173d59b99bac0c658d041d2a139fc090d8ec6be Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Thu, 14 Dec 2023 14:54:58 +0300 Subject: [PATCH 2/6] Rectified path --- .../Authentication/custom/common/MgCommandMetadata.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Authentication/Authentication/custom/common/MgCommandMetadata.json b/src/Authentication/Authentication/custom/common/MgCommandMetadata.json index 20d5e6fda6d..41114d97d04 100644 --- a/src/Authentication/Authentication/custom/common/MgCommandMetadata.json +++ b/src/Authentication/Authentication/custom/common/MgCommandMetadata.json @@ -95132,7 +95132,7 @@ }, { "Module": "Beta.Identity.SignIns", - "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStartonAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders", + "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders", "OutputType": "IMicrosoftGraphIdentityProviderBase", "Method": "GET", "ApiVersion": "beta", @@ -95208,7 +95208,7 @@ }, { "Module": "Beta.Identity.SignIns", - "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStartonAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref", + "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref", "OutputType": null, "Method": "GET", "ApiVersion": "beta", @@ -95220,7 +95220,7 @@ }, { "Module": "Beta.Identity.SignIns", - "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStartonAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$count", + "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$count", "OutputType": null, "Method": "GET", "ApiVersion": "beta", @@ -305344,7 +305344,7 @@ }, { "Module": "Beta.Identity.SignIns", - "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStartonAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref", + "Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref", "OutputType": null, "Method": "POST", "ApiVersion": "beta", From 73e568620eaed7ea3ed8d214b3d222bf27c863ff Mon Sep 17 00:00:00 2001 From: Tim Date: Mon, 18 Dec 2023 09:36:51 +0300 Subject: [PATCH 3/6] Update tools/PostGeneration/NewCommandMetadata.ps1 Co-authored-by: Peter Ombwa --- tools/PostGeneration/NewCommandMetadata.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/PostGeneration/NewCommandMetadata.ps1 b/tools/PostGeneration/NewCommandMetadata.ps1 index e5316726e62..1338934c60c 100644 --- a/tools/PostGeneration/NewCommandMetadata.ps1 +++ b/tools/PostGeneration/NewCommandMetadata.ps1 @@ -58,7 +58,7 @@ $ApiVersion | ForEach-Object { $Method = $Matches.2 $Uri = $Matches.3 - # Remove FQN in action/function names. + # Remove FQN in paths. if ($Uri -match $ActionFunctionFQNPattern) { $MatchedUriSegment = $Matches.0 $SegmentBuilder = "" From e01ae3b4ea1061d300b58d70307a8030e679accf Mon Sep 17 00:00:00 2001 From: Timothy Wamalwa Date: Mon, 18 Dec 2023 10:25:49 +0300 Subject: [PATCH 4/6] Made updates as per PR review --- .../Authentication/custom/common/GraphUri.ps1 | 17 ++++++++++++----- .../test/Find-MgGraphCommand.Tests.ps1 | 16 ++++++++++++++-- tools/PostGeneration/NewCommandMetadata.ps1 | 11 +++++++---- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/Authentication/Authentication/custom/common/GraphUri.ps1 b/src/Authentication/Authentication/custom/common/GraphUri.ps1 index 1c5a34bf51e..8f328ea450c 100644 --- a/src/Authentication/Authentication/custom/common/GraphUri.ps1 +++ b/src/Authentication/Authentication/custom/common/GraphUri.ps1 @@ -103,14 +103,21 @@ function GraphUri_RemoveNamespaceFromActionFunction { $ActionFunctionFQNPattern = "\/Microsoft.Graph.(.*)$" $NewUri = $Uri - # Remove FQN in action/function names. + # Remove FQN in paths. if ($Uri -match $ActionFunctionFQNPattern) { $MatchedUriSegment = $Matches.0 + $SegmentBuilder = "" # Trim nested namespace segments. - $NestedNamespaceSegments = $Matches.1 -split "\." - # Remove trailing '()' from functions. - $LastSegment = $NestedNamespaceSegments[-1] -replace "\(\)", "" - $NewUri = $Uri -replace [Regex]::Escape($MatchedUriSegment), "/$LastSegment" + $NestedNamespaceSegments = $Matches.1 -split "/" + foreach($Segment in $NestedNamespaceSegments){ + # Remove microsoft.graph prefix and trailing '()' from functions. + $Segment = $segment.Replace("microsoft.graph.","").Replace("()", "") + # Get resource object name from segment if it exists. e.g get 'updateAudience' from windowsUpdates.updateAudience + $ResourceObj = $Segment.Split(".") + $Segment = $ResourceObj.Count -gt 1 ? $ResourceObj[$ResourceObj.Count-1] : $Segment + $SegmentBuilder += "/$Segment" + } + $NewUri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder } return $NewUri diff --git a/src/Authentication/Authentication/test/Find-MgGraphCommand.Tests.ps1 b/src/Authentication/Authentication/test/Find-MgGraphCommand.Tests.ps1 index d170fcf9511..eefdf6f7a03 100644 --- a/src/Authentication/Authentication/test/Find-MgGraphCommand.Tests.ps1 +++ b/src/Authentication/Authentication/test/Find-MgGraphCommand.Tests.ps1 @@ -138,7 +138,7 @@ Describe "Find-MgGraphCommand Command" { $MgCommand.Command | Should -Be @("Get-MgReportSharePointActivityUserCount", "Get-MgBetaReportSharePointActivityUserCount") } | Should -Not -Throw } - It 'Should find commands for uri woth /me segments' { + It 'Should find commands for uri with /me segments' { { $MgCommand = Find-MgGraphCommand -Uri "/me/events/" $MgCommand | Should -HaveCount 4 @@ -150,7 +150,7 @@ Describe "Find-MgGraphCommand Command" { $MgCommand.Command | Select-Object -Unique | Should -BeIn @("New-MgUserEvent", "Get-MgUserEvent", "New-MgBetaUserEvent", "Get-MgBetaUserEvent") } | Should -Not -Throw } - It 'Should find commands for uri woth /me segments' { + It 'Should find commands for uri with /me segments' { { $MgCommand = Find-MgGraphCommand -Uri "https://graph.microsoft.com/v1.0/me/events/" $MgCommand | Should -HaveCount 4 @@ -162,6 +162,18 @@ Describe "Find-MgGraphCommand Command" { $MgCommand.Command | Select-Object -Unique | Should -BeIn @("New-MgUserEvent", "Get-MgUserEvent", "New-MgBetaUserEvent", "Get-MgBetaUserEvent") } | Should -Not -Throw } + It 'Should find commands for uri with Microsoft.Graph prefix in nested segments' { + { + $MgCommand = Find-MgGraphCommand -Uri "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/microsoft.graph.externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/microsoft.graph.onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders" + $MgCommand | Should -HaveCount 1 + $MgCommand.Command | Select-Object -Unique | should -HaveCount 1 + $MgCommand.Method | Select-Object -Unique | should -HaveCount 1 + $MgCommand.APIVersion | Select-Object -Unique | should -HaveCount 1 + $MgCommand.Variants | Select-Object -Unique | should -HaveCount 1 + $MgCommand.URI | Select-Object -Unique | Should -Be "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders" + $MgCommand.Command | Select-Object -Unique | Should -BeIn @("Get-MgBetaIdentityAuthenticationEventFlowAsOnAuthenticationMethodLoadStartExternalUserSelfServiceSignUpIdentityProvider") + } | Should -Not -Throw + } } Context "FindByCommand" { diff --git a/tools/PostGeneration/NewCommandMetadata.ps1 b/tools/PostGeneration/NewCommandMetadata.ps1 index 1338934c60c..c7a4f3c809b 100644 --- a/tools/PostGeneration/NewCommandMetadata.ps1 +++ b/tools/PostGeneration/NewCommandMetadata.ps1 @@ -64,10 +64,13 @@ $ApiVersion | ForEach-Object { $SegmentBuilder = "" # Trim nested namespace segments. $NestedNamespaceSegments = $Matches.1 -split "/" - # Remove microsoft.graph prefix and remove trailing '()' from functions. - foreach($segment in $NestedNamespaceSegments){ - $segment = $segment.Replace("microsoft.graph.","").Replace("()", "") - $SegmentBuilder += "/$segment" + foreach($Segment in $NestedNamespaceSegments){ + # Remove microsoft.graph prefix and trailing '()' from functions. + $Segment = $segment.Replace("microsoft.graph.","").Replace("()", "") + # Get resource object name from segment if it exists. e.g get 'updateAudience' from windowsUpdates.updateAudience + $ResourceObj = $Segment.Split(".") + $Segment = $ResourceObj.Count -gt 1 ? $ResourceObj[$ResourceObj.Count-1] : $Segment + $SegmentBuilder += "/$Segment" } $Uri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder } From 25d211e99ec78578d51f5b826acdb7af6d15f3c2 Mon Sep 17 00:00:00 2001 From: Tim Date: Wed, 20 Dec 2023 21:54:33 +0300 Subject: [PATCH 5/6] Update src/Authentication/Authentication/custom/common/GraphUri.ps1 Co-authored-by: Mustafa Zengin --- src/Authentication/Authentication/custom/common/GraphUri.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Authentication/Authentication/custom/common/GraphUri.ps1 b/src/Authentication/Authentication/custom/common/GraphUri.ps1 index 8f328ea450c..c52e66aac79 100644 --- a/src/Authentication/Authentication/custom/common/GraphUri.ps1 +++ b/src/Authentication/Authentication/custom/common/GraphUri.ps1 @@ -114,7 +114,7 @@ function GraphUri_RemoveNamespaceFromActionFunction { $Segment = $segment.Replace("microsoft.graph.","").Replace("()", "") # Get resource object name from segment if it exists. e.g get 'updateAudience' from windowsUpdates.updateAudience $ResourceObj = $Segment.Split(".") - $Segment = $ResourceObj.Count -gt 1 ? $ResourceObj[$ResourceObj.Count-1] : $Segment + $Segment = $ResourceObj[$ResourceObj.Count-1] $SegmentBuilder += "/$Segment" } $NewUri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder From 09fd21958cb6fb04ddce2bad8ac8c2205fbd6167 Mon Sep 17 00:00:00 2001 From: Tim Date: Thu, 28 Dec 2023 22:31:16 +0300 Subject: [PATCH 6/6] Update tools/PostGeneration/NewCommandMetadata.ps1 Co-authored-by: Peter Ombwa --- tools/PostGeneration/NewCommandMetadata.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/PostGeneration/NewCommandMetadata.ps1 b/tools/PostGeneration/NewCommandMetadata.ps1 index c7a4f3c809b..9a2e375dc89 100644 --- a/tools/PostGeneration/NewCommandMetadata.ps1 +++ b/tools/PostGeneration/NewCommandMetadata.ps1 @@ -69,7 +69,7 @@ $ApiVersion | ForEach-Object { $Segment = $segment.Replace("microsoft.graph.","").Replace("()", "") # Get resource object name from segment if it exists. e.g get 'updateAudience' from windowsUpdates.updateAudience $ResourceObj = $Segment.Split(".") - $Segment = $ResourceObj.Count -gt 1 ? $ResourceObj[$ResourceObj.Count-1] : $Segment + $Segment = $ResourceObj[$ResourceObj.Count-1] $SegmentBuilder += "/$Segment" } $Uri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder