From 47e7640dff303d29ee35ed75daefb272dc5df512 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Wed, 17 Aug 2022 15:23:49 +0200 Subject: [PATCH 1/4] added Remove-AzApiManagementUser script --- .../Arcus.Scripting.ApiManagement.psd1 | Bin 8586 -> 8658 bytes .../Arcus.Scripting.ApiManagement.psm1 | 37 ++++++ .../Arcus.Scripting.ApiManagement.pssproj | 1 + .../Scripts/Remove-AzApiManagementUser.ps1 | 40 ++++++ .../Arcus.Scripting.ApiManagement.tests.ps1 | 115 ++++++++++++++++++ 5 files changed, 193 insertions(+) create mode 100644 src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUser.ps1 diff --git a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psd1 b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psd1 index 1e7f2a19540f79fd1241abfae8a8686e0f573c27..ec6bf88e529dc488042de6dec1344ad02a8f51f1 100644 GIT binary patch delta 24 gcmeBjzT~{2Pk6GPu)yRw!e)~n3EFHvA$*7z0DBJ!uK)l5 delta 16 XcmccQ+~vHXPk8bKVVBKPB0G2iJdg%d diff --git a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 index e6a96273..87099069 100644 --- a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 +++ b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 @@ -177,6 +177,43 @@ function Create-AzApiManagementUser { Export-ModuleMember -Function Create-AzApiManagementUser +<# + .Synopsis + Removes a user from Azure API Management. + + .Description + Remove a user from Azure API Management based on e-mail address. + + .Parameter ResourceGroupName + The resource group containing the API Management service. + + .Parameter ServiceName + The name of the API Management service located in Azure. + + .Parameter MailAddress + The e-mail address of the user. + + .Parameter SubscriptionId + [Optional] The Id of the subscription containing the Azure API Management service. When not provided, it will be retrieved from the current context (Get-AzContext). + + .Parameter AccessToken + [Optional] The access token to be used. When not provided, it will be retrieved from the current context (Get-AzContext). +#> +function Remove-AzApiManagementUser { + param( + [string][Parameter(Mandatory = $true)] $ResourceGroupName = $(throw "Resource group name is required"), + [string][parameter(Mandatory = $true)] $ServiceName = $(throw "API management service name is required"), + [string][parameter(Mandatory = $true)] $MailAddress = $(throw "The mail-address of the user is required"), + [string][parameter(Mandatory = $false)] $SubscriptionId, + [string][parameter(Mandatory = $false)] $AccessToken + ) + + . $PSScriptRoot\Scripts\Remove-AzApiManagementUser.ps1 -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName -MailAddress $MailAddress + +} + +Export-ModuleMember -Function Remove-AzApiManagementUser + <# .Synopsis Import a policy to a product in Azure API Management. diff --git a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.pssproj b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.pssproj index fe893601..3e0e88de 100644 --- a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.pssproj +++ b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.pssproj @@ -33,6 +33,7 @@ + diff --git a/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUser.ps1 b/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUser.ps1 new file mode 100644 index 00000000..b6cb5c5c --- /dev/null +++ b/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUser.ps1 @@ -0,0 +1,40 @@ +param( + [string][Parameter(Mandatory = $true)] $ResourceGroupName = $(throw "Resource group name is required"), + [string][parameter(Mandatory = $true)] $ServiceName = $(throw "API management service name is required"), + [string][parameter(Mandatory = $true)] $MailAddress = $(throw "The mail-address of the user is required"), + [string][parameter(Mandatory = $false)] $SubscriptionId, + [string][parameter(Mandatory = $false)] $AccessToken +) + +$apim = Get-AzApiManagement -ResourceGroupName $ResourceGroupName -Name $ServiceName +if ($apim -eq $null) { + throw "Unable to find the Azure API Management Instance $ServiceName in resource group $ResourceGroupName" +} +$apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName + +if ($SubscriptionId -eq "" -or $AccessToken -eq "") { + # Request accessToken in case the script contains no records + $token = Get-AzCachedAccessToken + + $AccessToken = $token.AccessToken + $SubscriptionId = $token.SubscriptionId +} + +try { + Write-Host "Retrieving the user account with e-mail '$mailAddress'" + $apimUser = Get-AzApiManagementUser -Context $apimContext -Email $MailAddress + + if ($apimUser -ne $null) { + $apimUserId = $apimUser.UserId + + Write-Host "Attempting to remove the user account with e-mail '$mailAddress' and id '$apimUserId'" + Az.ApiManagement\Remove-AzApiManagementUser -Context $apimContext -UserId $apimUserId + Write-Host "Removed the user account with e-mail '$mailAddress' and id '$apimUserId'" + } else { + Write-Host "User account with e-mail '$mailAddress' not found in the APIM instance '$ServiceName'" + } +} +catch { + Write-Host $_ + throw "Failed to remove the user account for '$MailAddress' in the APIM instance '$ServiceName'" +} \ No newline at end of file diff --git a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 index 81897838..fab76eab 100644 --- a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 @@ -1350,6 +1350,121 @@ InModuleScope Arcus.Scripting.ApiManagement { } | Should -Throw -ExpectedMessage "Unable to find the Azure API Management Instance $serviceName in resource group $resourceGroup" + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 + } + } + Context "Remove Azure API Management User" { + It "Removing a user from Azure API Management is OK" { + # Arrange + $resourceGroup = "contoso" + $serviceName = "contosoApi" + $mailAddress = "john.doe@contoso.com" + $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + $userId = 1 + $apiUser = [pscustomobject] @{ + UserId = $userId; + }; + + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable + Mock New-AzApiManagementContext { + $ResourceGroupName | Should -Be $resourceGroup + $ServiceName | Should -Be $serviceName + return $context } -Verifiable + Mock Get-AzCachedAccessToken -MockWith { + return @{ + SubscriptionId = "123456" + AccessToken = "accessToken" + } + } + Mock Get-AzApiManagementUser { + $Context | Should -Be $context + $Email | Should -Be $mailAddress + return $apiUser } -Verifiable + Mock Az.ApiManagement\Remove-AzApiManagementUser { + $Context | Should -Be $context + $UserId | Should -Be $userId + return $null } -Verifiable + + # Act + Arcus.Scripting.ApiManagement\Remove-AzApiManagementUser ` + -ResourceGroupName $resourceGroup ` + -ServiceName $serviceName ` + -MailAddress $mailAddress + + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 + Assert-MockCalled New-AzApiManagementContext -Times 1 + Assert-MockCalled Get-AzCachedAccessToken -Times 1 + Assert-MockCalled Get-AzApiManagementUser -Times 1 + Assert-MockCalled Az.ApiManagement\Remove-AzApiManagementUser -Times 1 + } + It "Removing a user from Azure API Management that does not exist is OK" { + # Arrange + $resourceGroup = "contoso" + $serviceName = "contosoApi" + $mailAddress = "john.doe@contoso.com" + $context = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.ServiceManagement.Models.PsApiManagementContext + $stubApiManagement = New-Object -TypeName Microsoft.Azure.Commands.ApiManagement.Models.PsApiManagement + + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $stubApiManagement } -Verifiable + Mock New-AzApiManagementContext { + $ResourceGroupName | Should -Be $resourceGroup + $ServiceName | Should -Be $serviceName + return $context } -Verifiable + Mock Get-AzCachedAccessToken -MockWith { + return @{ + SubscriptionId = "123456" + AccessToken = "accessToken" + } + } + Mock Get-AzApiManagementUser { + $Context | Should -Be $context + $Email | Should -Be $mailAddress + return $null } -Verifiable + + # Act + Arcus.Scripting.ApiManagement\Remove-AzApiManagementUser ` + -ResourceGroupName $resourceGroup ` + -ServiceName $serviceName ` + -MailAddress $mailAddress + + # Assert + Assert-VerifiableMock + Assert-MockCalled Get-AzApiManagement -Times 1 + Assert-MockCalled New-AzApiManagementContext -Times 1 + Assert-MockCalled Get-AzCachedAccessToken -Times 1 + Assert-MockCalled Get-AzApiManagementUser -Times 1 + } + It "Removing a user from a non-existing Azure API Management fails" { + # Arrange + $resourceGroup = "contoso" + $serviceName = "contosoApi" + $mailAddress = "john.doe@contoso.com" + + Mock Get-AzApiManagement { + $ResourceGroupName | Should -Be $resourceGroup + $Name | Should -Be $serviceName + return $null } -Verifiable + + # Act + { + Arcus.Scripting.ApiManagement\Remove-AzApiManagementUser ` + -ResourceGroupName $resourceGroup ` + -ServiceName $serviceName ` + -MailAddress $mailAddress + } | Should -Throw -ExpectedMessage "Unable to find the Azure API Management Instance $serviceName in resource group $resourceGroup" + + # Assert Assert-VerifiableMock Assert-MockCalled Get-AzApiManagement -Times 1 From d36102425bc240ebeb7dd5651aa4d2fcf854f7f3 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Wed, 17 Aug 2022 15:36:13 +0200 Subject: [PATCH 2/4] fix create user docs --- .../02-Features/powershell/azure-api-management.md | 14 +++++++------- .../Arcus.Scripting.ApiManagement.psm1 | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/preview/02-Features/powershell/azure-api-management.md b/docs/preview/02-Features/powershell/azure-api-management.md index 77f2e590..1f7630bd 100644 --- a/docs/preview/02-Features/powershell/azure-api-management.md +++ b/docs/preview/02-Features/powershell/azure-api-management.md @@ -89,7 +89,7 @@ PS> Create-AzApiManagementApiOperation -ResourceGroupName $ResourceGroup -Servic ## Creating a new user in an Azure API Management service -Signup or invite a new user in an existing API in Azure API Management. +Signup or invite a new user in an existing Azure API Management instance. | Parameter | Mandatory | Description | | ------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | @@ -109,7 +109,7 @@ Signup or invite a new user in an existing API in Azure API Management. **Example** -Invite a new user in an existing API in Azure API Management. +Invite a new user in an existing Azure API Management instance. ```powershell PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress @@ -117,7 +117,7 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S # Invitation has been sent to FirstName $LastName ($MailAddress) ``` -Invite a new user in an existing API in Azure API Management and specify a UserId. +Invite a new user in an existing Azure API Management instance and specify a UserId. ```powershell PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -UserId $UserId @@ -125,7 +125,7 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S # Invitation has been sent to FirstName $LastName ($MailAddress) ``` -Invite a new user in an existing API in Azure API Management and include a note. +Invite a new user in an existing Azure API Management instance and include a note. ```powershell PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -Note $Note @@ -133,7 +133,7 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S # Invitation has been sent to FirstName $LastName ($MailAddress) ``` -Invite a new user in an existing API in Azure API Management and send a notification. +Invite a new user in an existing Azure API Management instance and send a notification. ```powershell PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -SendNotification @@ -141,7 +141,7 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S # Invitation has been sent to FirstName $LastName ($MailAddress) ``` -Signup a new user in an existing API in Azure API Management. +Signup a new user in an existing Azure API Management instance. ```powershell PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -ConfirmationType signup @@ -150,7 +150,7 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S # Since no password was provided, one has been generated. Please advise the user to change this password the first time logging in ``` -Signup a new user in an existing API in Azure API Management and specify a password. +Signup a new user in an existing Azure API Management instance and specify a password. ```powershell PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -Password $Password -ConfirmationType signup diff --git a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 index 87099069..ae5cf412 100644 --- a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 +++ b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 @@ -111,7 +111,7 @@ Export-ModuleMember -Function Create-AzApiManagementApiOperation Creates a user in Azure API Management. .Description - Signup or invite a new user in an existing API in Azure API Management. + Signup or invite a new user in an existing Azure API Management instance. .Parameter ResourceGroupName The resource group containing the API Management service. From ef4aea5557af01931c3508f85c578d122fe3ab3c Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Wed, 17 Aug 2022 15:41:07 +0200 Subject: [PATCH 3/4] added docs for Remove-AzApiManagementUser --- .../powershell/azure-api-management.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/preview/02-Features/powershell/azure-api-management.md b/docs/preview/02-Features/powershell/azure-api-management.md index 1f7630bd..1f122215 100644 --- a/docs/preview/02-Features/powershell/azure-api-management.md +++ b/docs/preview/02-Features/powershell/azure-api-management.md @@ -158,6 +158,29 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S # Account has been created for FirstName $LastName ($MailAddress) ``` +## Removing a user from an Azure API Management service + +Remove a user from an existing Azure API Management instance based on e-mail address. + +| Parameter | Mandatory | Description | +| ------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `ResourceGroupName` | yes | The resource group containing the Azure API Management instance | +| `ServiceName` | yes | The name of the Azure API Management instance located in Azure | +| `MailAddress` | yes | The email address of the user that is to be removed | +| `SubscriptionId` | no | The Id of the subscription containing the Azure API Management instance. When not provided, it will be retrieved from the current context (Get-AzContext). | +| `AccessToken` | no | The access token to be used to add the user to the Azure API Management instance. When not provided, it will be retrieved from the current context (Get-AzContext). | + +**Example** + +Remove a user from an existing Azure API Management instance. + +```powershell +PS> Remove-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -MailAddress $MailAddress +# Retrieving the user account with e-mail '$MailAddress' +# Attempting to remove the user account with e-mail '$MailAddress' and id '1' +# Removed the user account with e-mail '$MailAddress' and id '1' +``` + ## Importing a policy to a product in the Azure API Management instance Imports a policy from a file to a product in Azure API Management. From ffbcf5150f53a877cf8d3eaf6ab68e554bf755d8 Mon Sep 17 00:00:00 2001 From: Pim Simons Date: Thu, 18 Aug 2022 08:18:41 +0200 Subject: [PATCH 4/4] renamed scripts to prevent issues --- .../powershell/azure-api-management.md | 14 +++++----- .../Arcus.Scripting.ApiManagement.psd1 | Bin 8658 -> 8686 bytes .../Arcus.Scripting.ApiManagement.psm1 | 14 +++++----- .../Arcus.Scripting.ApiManagement.pssproj | 4 +-- ... => Create-AzApiManagementUserAccount.ps1} | 0 ... => Remove-AzApiManagementUserAccount.ps1} | 2 +- .../Arcus.Scripting.ApiManagement.tests.ps1 | 26 +++++++++--------- 7 files changed, 30 insertions(+), 30 deletions(-) rename src/Arcus.Scripting.ApiManagement/Scripts/{Create-AzApiManagementUser.ps1 => Create-AzApiManagementUserAccount.ps1} (100%) rename src/Arcus.Scripting.ApiManagement/Scripts/{Remove-AzApiManagementUser.ps1 => Remove-AzApiManagementUserAccount.ps1} (94%) diff --git a/docs/preview/02-Features/powershell/azure-api-management.md b/docs/preview/02-Features/powershell/azure-api-management.md index 1f122215..73a6e144 100644 --- a/docs/preview/02-Features/powershell/azure-api-management.md +++ b/docs/preview/02-Features/powershell/azure-api-management.md @@ -112,7 +112,7 @@ Signup or invite a new user in an existing Azure API Management instance. Invite a new user in an existing Azure API Management instance. ```powershell -PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress +PS> Create-AzApiManagementUserAccount -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress # Attempting to invite $FirstName $LastName ($MailAddress) # Invitation has been sent to FirstName $LastName ($MailAddress) ``` @@ -120,7 +120,7 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S Invite a new user in an existing Azure API Management instance and specify a UserId. ```powershell -PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -UserId $UserId +PS> Create-AzApiManagementUserAccount -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -UserId $UserId # Attempting to invite $FirstName $LastName ($MailAddress) # Invitation has been sent to FirstName $LastName ($MailAddress) ``` @@ -128,7 +128,7 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S Invite a new user in an existing Azure API Management instance and include a note. ```powershell -PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -Note $Note +PS> Create-AzApiManagementUserAccount -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -Note $Note # Attempting to invite $FirstName $LastName ($MailAddress) # Invitation has been sent to FirstName $LastName ($MailAddress) ``` @@ -136,7 +136,7 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S Invite a new user in an existing Azure API Management instance and send a notification. ```powershell -PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -SendNotification +PS> Create-AzApiManagementUserAccount -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -SendNotification # Attempting to invite $FirstName $LastName ($MailAddress) # Invitation has been sent to FirstName $LastName ($MailAddress) ``` @@ -144,7 +144,7 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S Signup a new user in an existing Azure API Management instance. ```powershell -PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -ConfirmationType signup +PS> Create-AzApiManagementUserAccount -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -ConfirmationType signup # Attempting to create account for FirstName $LastName ($MailAddress) # Account has been created for FirstName $LastName ($MailAddress) # Since no password was provided, one has been generated. Please advise the user to change this password the first time logging in @@ -153,7 +153,7 @@ PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $S Signup a new user in an existing Azure API Management instance and specify a password. ```powershell -PS> Create-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -Password $Password -ConfirmationType signup +PS> Create-AzApiManagementUserAccount -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -Password $Password -ConfirmationType signup # Attempting to create account for FirstName $LastName ($MailAddress) # Account has been created for FirstName $LastName ($MailAddress) ``` @@ -175,7 +175,7 @@ Remove a user from an existing Azure API Management instance based on e-mail add Remove a user from an existing Azure API Management instance. ```powershell -PS> Remove-AzApiManagementUser -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -MailAddress $MailAddress +PS> Remove-AzApiManagementUserAccount -ResourceGroupName $ResourceGroup -ServiceName $ServiceName -MailAddress $MailAddress # Retrieving the user account with e-mail '$MailAddress' # Attempting to remove the user account with e-mail '$MailAddress' and id '1' # Removed the user account with e-mail '$MailAddress' and id '1' diff --git a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psd1 b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psd1 index ec6bf88e529dc488042de6dec1344ad02a8f51f1..5cae572ea1e1cc501a67cad00c04ca912838278f 100644 GIT binary patch delta 44 mcmccQ{LXp9C1GAihGZbjXDDUJV?-WV5))Ze9RE0Sxp2 delta 16 YcmaFoe93vkCE>{rgxxlqi0tA807xVUY5)KL diff --git a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 index ae5cf412..775bd6dc 100644 --- a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 +++ b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.psm1 @@ -152,7 +152,7 @@ Export-ModuleMember -Function Create-AzApiManagementApiOperation .Parameter AccessToken [Optional] The access token to be used. When not provided, it will be retrieved from the current context (Get-AzContext). #> -function Create-AzApiManagementUser { +function Create-AzApiManagementUserAccount { param( [string][Parameter(Mandatory = $true)] $ResourceGroupName = $(throw "Resource group name is required"), [string][parameter(Mandatory = $true)] $ServiceName = $(throw "API management service name is required"), @@ -169,13 +169,13 @@ function Create-AzApiManagementUser { [string][parameter(Mandatory = $false)] $AccessToken ) if ($SendNotification) { - . $PSScriptRoot\Scripts\Create-AzApiManagementUser.ps1 -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -UserId $UserId -Password $Password -Note $Note -ConfirmationType $ConfirmationType -ApiVersion $ApiVersion -SubscriptionId $SubscriptionId -AccessToken $AccessToken -SendNotification + . $PSScriptRoot\Scripts\Create-AzApiManagementUserAccount.ps1 -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -UserId $UserId -Password $Password -Note $Note -ConfirmationType $ConfirmationType -ApiVersion $ApiVersion -SubscriptionId $SubscriptionId -AccessToken $AccessToken -SendNotification } else { - . $PSScriptRoot\Scripts\Create-AzApiManagementUser.ps1 -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -UserId $UserId -Password $Password -Note $Note -ConfirmationType $ConfirmationType -ApiVersion $ApiVersion -SubscriptionId $SubscriptionId -AccessToken $AccessToken + . $PSScriptRoot\Scripts\Create-AzApiManagementUserAccount.ps1 -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName -FirstName $FirstName -LastName $LastName -MailAddress $MailAddress -UserId $UserId -Password $Password -Note $Note -ConfirmationType $ConfirmationType -ApiVersion $ApiVersion -SubscriptionId $SubscriptionId -AccessToken $AccessToken } } -Export-ModuleMember -Function Create-AzApiManagementUser +Export-ModuleMember -Function Create-AzApiManagementUserAccount <# .Synopsis @@ -199,7 +199,7 @@ Export-ModuleMember -Function Create-AzApiManagementUser .Parameter AccessToken [Optional] The access token to be used. When not provided, it will be retrieved from the current context (Get-AzContext). #> -function Remove-AzApiManagementUser { +function Remove-AzApiManagementUserAccount { param( [string][Parameter(Mandatory = $true)] $ResourceGroupName = $(throw "Resource group name is required"), [string][parameter(Mandatory = $true)] $ServiceName = $(throw "API management service name is required"), @@ -208,11 +208,11 @@ function Remove-AzApiManagementUser { [string][parameter(Mandatory = $false)] $AccessToken ) - . $PSScriptRoot\Scripts\Remove-AzApiManagementUser.ps1 -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName -MailAddress $MailAddress + . $PSScriptRoot\Scripts\Remove-AzApiManagementUserAccount.ps1 -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName -MailAddress $MailAddress } -Export-ModuleMember -Function Remove-AzApiManagementUser +Export-ModuleMember -Function Remove-AzApiManagementUserAccount <# .Synopsis diff --git a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.pssproj b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.pssproj index 3e0e88de..65bbefc6 100644 --- a/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.pssproj +++ b/src/Arcus.Scripting.ApiManagement/Arcus.Scripting.ApiManagement.pssproj @@ -33,12 +33,12 @@ - - + + diff --git a/src/Arcus.Scripting.ApiManagement/Scripts/Create-AzApiManagementUser.ps1 b/src/Arcus.Scripting.ApiManagement/Scripts/Create-AzApiManagementUserAccount.ps1 similarity index 100% rename from src/Arcus.Scripting.ApiManagement/Scripts/Create-AzApiManagementUser.ps1 rename to src/Arcus.Scripting.ApiManagement/Scripts/Create-AzApiManagementUserAccount.ps1 diff --git a/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUser.ps1 b/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUserAccount.ps1 similarity index 94% rename from src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUser.ps1 rename to src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUserAccount.ps1 index b6cb5c5c..5eff7102 100644 --- a/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUser.ps1 +++ b/src/Arcus.Scripting.ApiManagement/Scripts/Remove-AzApiManagementUserAccount.ps1 @@ -28,7 +28,7 @@ try { $apimUserId = $apimUser.UserId Write-Host "Attempting to remove the user account with e-mail '$mailAddress' and id '$apimUserId'" - Az.ApiManagement\Remove-AzApiManagementUser -Context $apimContext -UserId $apimUserId + Remove-AzApiManagementUser -Context $apimContext -UserId $apimUserId Write-Host "Removed the user account with e-mail '$mailAddress' and id '$apimUserId'" } else { Write-Host "User account with e-mail '$mailAddress' not found in the APIM instance '$ServiceName'" diff --git a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 index fab76eab..8010997f 100644 --- a/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 +++ b/src/Arcus.Scripting.Tests.Unit/Arcus.Scripting.ApiManagement.tests.ps1 @@ -1042,7 +1042,7 @@ InModuleScope Arcus.Scripting.ApiManagement { } # Act - Create-AzApiManagementUser ` + Create-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -FirstName $firstName ` @@ -1088,7 +1088,7 @@ InModuleScope Arcus.Scripting.ApiManagement { } # Act - Create-AzApiManagementUser ` + Create-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -FirstName $firstName ` @@ -1136,7 +1136,7 @@ InModuleScope Arcus.Scripting.ApiManagement { } # Act - Create-AzApiManagementUser ` + Create-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -FirstName $firstName ` @@ -1185,7 +1185,7 @@ InModuleScope Arcus.Scripting.ApiManagement { } # Act - Create-AzApiManagementUser ` + Create-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -FirstName $firstName ` @@ -1234,7 +1234,7 @@ InModuleScope Arcus.Scripting.ApiManagement { } # Act - Create-AzApiManagementUser ` + Create-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -FirstName $firstName ` @@ -1283,7 +1283,7 @@ InModuleScope Arcus.Scripting.ApiManagement { } # Act - Create-AzApiManagementUser ` + Create-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -FirstName $firstName ` @@ -1313,7 +1313,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Act { - Create-AzApiManagementUser ` + Create-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -FirstName $firstName ` @@ -1341,7 +1341,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Act { - Create-AzApiManagementUser ` + Create-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -FirstName $firstName ` @@ -1386,13 +1386,13 @@ InModuleScope Arcus.Scripting.ApiManagement { $Context | Should -Be $context $Email | Should -Be $mailAddress return $apiUser } -Verifiable - Mock Az.ApiManagement\Remove-AzApiManagementUser { + Mock Remove-AzApiManagementUser { $Context | Should -Be $context $UserId | Should -Be $userId return $null } -Verifiable # Act - Arcus.Scripting.ApiManagement\Remove-AzApiManagementUser ` + Remove-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -MailAddress $mailAddress @@ -1403,7 +1403,7 @@ InModuleScope Arcus.Scripting.ApiManagement { Assert-MockCalled New-AzApiManagementContext -Times 1 Assert-MockCalled Get-AzCachedAccessToken -Times 1 Assert-MockCalled Get-AzApiManagementUser -Times 1 - Assert-MockCalled Az.ApiManagement\Remove-AzApiManagementUser -Times 1 + Assert-MockCalled Remove-AzApiManagementUser -Times 1 } It "Removing a user from Azure API Management that does not exist is OK" { # Arrange @@ -1433,7 +1433,7 @@ InModuleScope Arcus.Scripting.ApiManagement { return $null } -Verifiable # Act - Arcus.Scripting.ApiManagement\Remove-AzApiManagementUser ` + Remove-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -MailAddress $mailAddress @@ -1458,7 +1458,7 @@ InModuleScope Arcus.Scripting.ApiManagement { # Act { - Arcus.Scripting.ApiManagement\Remove-AzApiManagementUser ` + Remove-AzApiManagementUserAccount ` -ResourceGroupName $resourceGroup ` -ServiceName $serviceName ` -MailAddress $mailAddress