Skip to content

invoke-azrest #12291

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 24 commits into from
Jul 1, 2020
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
4 changes: 2 additions & 2 deletions src/Accounts/Accounts.Test/ErrorResolutionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public void HandlesExceptionError()
var autorestException = new Microsoft.Rest.Azure.CloudException("exception message")
{
Body = new Microsoft.Rest.Azure.CloudError { Code = "AutorestCode", Message = "Autorest message" },
Request = new Rest.HttpRequestMessageWrapper(request, ""),
Response = new Rest.HttpResponseMessageWrapper(response, ""),
Request = new Microsoft.Rest.HttpRequestMessageWrapper(request, ""),
Response = new Microsoft.Rest.HttpResponseMessageWrapper(response, ""),
RequestId = "AutoRestRequestId"
};

Expand Down
35 changes: 35 additions & 0 deletions src/Accounts/Accounts.Test/InvokeAzRestTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Azure.Commands.Profile.Test
{
public class InvokeAzRestTests : AccountsTestRunner
{
public InvokeAzRestTests(ITestOutputHelper output)
: base(output)
{
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestInvokeAzRest()
{
TestRunner.RunTestScript("Test-InvokeAzRest");
}
}
}
54 changes: 54 additions & 0 deletions src/Accounts/Accounts.Test/InvokeAzRestTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Tests cmdlets Invoke-AzRest
#>

function Test-InvokeAzRest
{
$put = "PUT"
$get = "GET"
$patch = "PATCH"
$delete = "DELETE"
$api = "2019-10-01"
$name = "mockRG4Test"

$tag = "`{`"tags`": `{`"key`": `"val`"`}`}"
$payload = "`{`"Location`": `"eastus`"`}"

$response = Invoke-AzRest -ResourceGroupName $name -ApiVersion $api -Method $put -payload $payload

Assert-AreEqual 201 $response.StatusCode
Assert-AreEqual $put $response.Method
Assert-NotNull $response.Content

$response = Invoke-AzRest -ResourceGroupName $name -ApiVersion $api -Method $get

Assert-AreEqual 200 $response.StatusCode
Assert-AreEqual $get $response.Method
Assert-NotNull $response.Content

$response = Invoke-AzRest -ResourceGroupName $name -ApiVersion $api -Method $patch -payload $tag

Assert-AreEqual 200 $response.StatusCode
Assert-AreEqual $patch $response.Method
Assert-NotNull $response.Content

$response = Invoke-AzRest -ResourceGroupName $name -ApiVersion $api -Method $delete

Assert-AreEqual 202 $response.StatusCode
Assert-AreEqual $delete $response.Method
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
{
"Entries": [
{
"RequestUri": "/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/mockRG4Test?api-version=2019-10-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvOWUyMjNkYmUtMzM5OS00ZTE5LTg4ZWItMDk3NWYwMmFjODdmL3Jlc291cmNlR3JvdXBzL21vY2tSRzRUZXN0P2FwaS12ZXJzaW9uPTIwMTktMTAtMDE=",
"RequestMethod": "PUT",
"RequestBody": "{\r\n \"Location\": \"eastus\"\r\n}",
"RequestHeaders": {
"x-ms-client-request-id": [
"81de12fa-bbcf-47d5-a8fd-943c1ad886e1"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.28928.01",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.18363.",
"Microsoft.Azure.Internal.Common.AzureRestClient/1.3.17"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Content-Length": [
"22"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"x-ms-ratelimit-remaining-subscription-writes": [
"1199"
],
"x-ms-request-id": [
"7cc85e9c-718e-4ce9-92cd-76098f863590"
],
"x-ms-correlation-request-id": [
"7cc85e9c-718e-4ce9-92cd-76098f863590"
],
"x-ms-routing-request-id": [
"SOUTHEASTASIA:20200630T032251Z:7cc85e9c-718e-4ce9-92cd-76098f863590"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"Date": [
"Tue, 30 Jun 2020 03:22:51 GMT"
],
"Content-Length": [
"219"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
]
},
"ResponseBody": "{\r\n \"id\": \"/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/mockRG4Test\",\r\n \"name\": \"mockRG4Test\",\r\n \"type\": \"Microsoft.Resources/resourceGroups\",\r\n \"location\": \"eastus\",\r\n \"properties\": {\r\n \"provisioningState\": \"Succeeded\"\r\n }\r\n}",
"StatusCode": 201
},
{
"RequestUri": "/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/mockRG4Test?api-version=2019-10-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvOWUyMjNkYmUtMzM5OS00ZTE5LTg4ZWItMDk3NWYwMmFjODdmL3Jlc291cmNlR3JvdXBzL21vY2tSRzRUZXN0P2FwaS12ZXJzaW9uPTIwMTktMTAtMDE=",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"d64d1bd0-4477-4d0f-b846-10fd6344bb1a"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.28928.01",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.18363.",
"Microsoft.Azure.Internal.Common.AzureRestClient/1.3.17"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"x-ms-ratelimit-remaining-subscription-reads": [
"11994"
],
"x-ms-request-id": [
"3812dcc9-0254-4fe9-b88f-40706ff4a59a"
],
"x-ms-correlation-request-id": [
"3812dcc9-0254-4fe9-b88f-40706ff4a59a"
],
"x-ms-routing-request-id": [
"SOUTHEASTASIA:20200630T032251Z:3812dcc9-0254-4fe9-b88f-40706ff4a59a"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"Date": [
"Tue, 30 Jun 2020 03:22:51 GMT"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Content-Length": [
"219"
]
},
"ResponseBody": "{\r\n \"id\": \"/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/mockRG4Test\",\r\n \"name\": \"mockRG4Test\",\r\n \"type\": \"Microsoft.Resources/resourceGroups\",\r\n \"location\": \"eastus\",\r\n \"properties\": {\r\n \"provisioningState\": \"Succeeded\"\r\n }\r\n}",
"StatusCode": 200
},
{
"RequestUri": "/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/mockRG4Test?api-version=2019-10-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvOWUyMjNkYmUtMzM5OS00ZTE5LTg4ZWItMDk3NWYwMmFjODdmL3Jlc291cmNlR3JvdXBzL21vY2tSRzRUZXN0P2FwaS12ZXJzaW9uPTIwMTktMTAtMDE=",
"RequestMethod": "PATCH",
"RequestBody": "{\r\n \"tags\": {\r\n \"key\": \"val\"\r\n }\r\n}",
"RequestHeaders": {
"x-ms-client-request-id": [
"28343bc5-2bb1-4156-b4a4-aa5d93f6d5a1"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.28928.01",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.18363.",
"Microsoft.Azure.Internal.Common.AzureRestClient/1.3.17"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Content-Length": [
"24"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"x-ms-ratelimit-remaining-subscription-writes": [
"1196"
],
"x-ms-request-id": [
"61d06e8b-185e-4c2e-a7b3-83a92c0b252b"
],
"x-ms-correlation-request-id": [
"61d06e8b-185e-4c2e-a7b3-83a92c0b252b"
],
"x-ms-routing-request-id": [
"SOUTHEASTASIA:20200630T032254Z:61d06e8b-185e-4c2e-a7b3-83a92c0b252b"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"Date": [
"Tue, 30 Jun 2020 03:22:54 GMT"
],
"Content-Length": [
"240"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
]
},
"ResponseBody": "{\r\n \"id\": \"/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/mockRG4Test\",\r\n \"name\": \"mockRG4Test\",\r\n \"type\": \"Microsoft.Resources/resourceGroups\",\r\n \"location\": \"eastus\",\r\n \"tags\": {\r\n \"key\": \"val\"\r\n },\r\n \"properties\": {\r\n \"provisioningState\": \"Succeeded\"\r\n }\r\n}",
"StatusCode": 200
},
{
"RequestUri": "/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/resourceGroups/mockRG4Test?api-version=2019-10-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvOWUyMjNkYmUtMzM5OS00ZTE5LTg4ZWItMDk3NWYwMmFjODdmL3Jlc291cmNlR3JvdXBzL21vY2tSRzRUZXN0P2FwaS12ZXJzaW9uPTIwMTktMTAtMDE=",
"RequestMethod": "DELETE",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"3ab6d714-2aea-4d95-a43d-f07e26d47f81"
],
"Accept-Language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.28928.01",
"OSName/Windows",
"OSVersion/Microsoft.Windows.10.0.18363.",
"Microsoft.Azure.Internal.Common.AzureRestClient/1.3.17"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Pragma": [
"no-cache"
],
"Location": [
"https://management.azure.com/subscriptions/9e223dbe-3399-4e19-88eb-0975f02ac87f/operationresults/eyJqb2JJZCI6IlJFU09VUkNFR1JPVVBERUxFVElPTkpPQi1NT0NLUkc0VEVTVC1FQVNUVVMiLCJqb2JMb2NhdGlvbiI6ImVhc3R1cyJ9?api-version=2019-10-01"
],
"Retry-After": [
"15"
],
"x-ms-ratelimit-remaining-subscription-deletes": [
"14999"
],
"x-ms-request-id": [
"2307c7dc-bddf-42b1-81e0-5b42931cbc56"
],
"x-ms-correlation-request-id": [
"2307c7dc-bddf-42b1-81e0-5b42931cbc56"
],
"x-ms-routing-request-id": [
"SOUTHEASTASIA:20200630T032258Z:2307c7dc-bddf-42b1-81e0-5b42931cbc56"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-Content-Type-Options": [
"nosniff"
],
"Date": [
"Tue, 30 Jun 2020 03:22:57 GMT"
],
"Expires": [
"-1"
],
"Content-Length": [
"0"
]
},
"ResponseBody": "",
"StatusCode": 202
}
],
"Names": {},
"Variables": {
"SubscriptionId": "9e223dbe-3399-4e19-88eb-0975f02ac87f"
}
}
5 changes: 3 additions & 2 deletions src/Accounts/Accounts/Az.Accounts.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,16 @@ CmdletsToExport = 'Disable-AzDataCollection', 'Disable-AzContextAutosave',
'Disconnect-AzAccount', 'Get-AzContextAutosaveSetting',
'Set-AzDefault', 'Get-AzDefault', 'Clear-AzDefault',
'Register-AzModule', 'Enable-AzureRmAlias', 'Disable-AzureRmAlias',
'Uninstall-AzureRm', 'Get-AzProfile', 'Select-AzProfile'
'Uninstall-AzureRm', 'Get-AzProfile', 'Select-AzProfile',
'Invoke-AzRestMethod'

# Variables to export from this module
# VariablesToExport = @()

# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
AliasesToExport = 'Add-AzAccount', 'Login-AzAccount', 'Remove-AzAccount',
'Logout-AzAccount', 'Select-AzSubscription', 'Resolve-Error',
'Save-AzProfile', 'Get-AzDomain'
'Save-AzProfile', 'Get-AzDomain', 'Invoke-AzRest'

# DSC resources to export from this module
# DscResourcesToExport = @()
Expand Down
1 change: 1 addition & 0 deletions src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Added new cmdlet `Invoke-AzRestMethod`

## Version 1.9.0
* Supported discovering environment setting by default and adding environment via `Add-AzEnvironment`
Expand Down
Loading