Skip to content
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

Rectifies metadata path information for paths containing Microsoft.Graph prefix in nested segments. #2492

17 changes: 12 additions & 5 deletions src/Authentication/Authentication/custom/common/GraphUri.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
timayabi2020 marked this conversation as resolved.
Show resolved Hide resolved
$SegmentBuilder += "/$Segment"
}
$NewUri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder
}

return $NewUri
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95132,7 +95132,7 @@
},
{
"Module": "Beta.Identity.SignIns",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders",
timayabi2020 marked this conversation as resolved.
Show resolved Hide resolved
"OutputType": "IMicrosoftGraphIdentityProviderBase",
"Method": "GET",
"ApiVersion": "beta",
Expand Down Expand Up @@ -95208,7 +95208,7 @@
},
{
"Module": "Beta.Identity.SignIns",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
"OutputType": null,
"Method": "GET",
"ApiVersion": "beta",
Expand All @@ -95220,7 +95220,7 @@
},
{
"Module": "Beta.Identity.SignIns",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$count",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$count",
"OutputType": null,
"Method": "GET",
"ApiVersion": "beta",
Expand Down Expand Up @@ -305344,7 +305344,7 @@
},
{
"Module": "Beta.Identity.SignIns",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
"Uri": "/identity/authenticationEventsFlows/{authenticationEventsFlow-id}/externalUsersSelfServiceSignUpEventsFlow/onAuthenticationMethodLoadStart/onAuthenticationMethodLoadStartExternalUsersSelfServiceSignUp/identityProviders/$ref",
"OutputType": null,
"Method": "POST",
"ApiVersion": "beta",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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" {
Expand Down
18 changes: 12 additions & 6 deletions tools/PostGeneration/NewCommandMetadata.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,22 @@ $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 = ""
# 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 "/"
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
timayabi2020 marked this conversation as resolved.
Show resolved Hide resolved
$SegmentBuilder += "/$Segment"
}
$Uri = $Uri -replace [Regex]::Escape($MatchedUriSegment), $SegmentBuilder
}

$MappingValue = @{
Command = $CommandName
Variants = [System.Collections.ArrayList]@($VariantName)
Expand Down