Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.26k stars 3.86k forks source link

Inconsistent URI encoding for Get-AzureRmResource and Set-AzureRmResource #5685

Open kwill-MSFT opened 6 years ago

kwill-MSFT commented 6 years ago

Description

Inconsistent URI encoding for Get-AzureRmResource and Set-AzureRmResource causes failures when working with App Service Certificates.

App Service Certificates use naming convention thumbprint#resourcegroup. The '#' is not always correctly encoded to %23, which causes the API call to fail with error: MissingApiVersionParameter : The api-version query parameter (?api-version=) is required for all requests.

Script/Steps for Reproduction

These commands work:

$resource = Get-AzureRmResource -ResourceName "7AF95FD8301E759535D8C9BD6F7C61E7DD92833F#TranslatorAPI_RG-WestUSwebspace" -ResourceGroupName "TranslatorAPI_RG" -ResourceType "Microsoft.Web/certificates"
$resource = Get-AzureRmResource -ResourceId "/subscriptions/5857f4d2-3dce-4b96-ad95-677f764e7a67/resourceGroups/TranslatorAPI_RG/providers/Microsoft.Web/certificates/7AF95FD8301E759535D8C9BD6F7C61E7DD92833F%23TranslatorAPI_RG-WestUSwebspace"

Set-AzureRmResource -Tag @{Test="Done"} -ResourceId "/subscriptions/5857f4d2-3dce-4b96-ad95-677f764e7a67/resourceGroups/TranslatorAPI_RG/providers/Microsoft.Web/certificates/7AF95FD8301E759535D8C9BD6F7C61E7DD92833F%23TranslatorAPI_RG-WestUSwebspace"

These commands fail:

$resource = Get-AzureRmResource -ResourceId "/subscriptions/5857f4d2-3dce-4b96-ad95-677f764e7a67/resourceGroups/TranslatorAPI_RG/providers/Microsoft.Web/certificates/7AF95FD8301E759535D8C9BD6F7C61E7DD92833F#TranslatorAPI_RG-WestUSwebspace"

$resource = Get-AzureRmResource -ResourceName "7AF95FD8301E759535D8C9BD6F7C61E7DD92833F#TranslatorAPI_RG-WestUSwebspace" -ResourceGroupName "TranslatorAPI_RG" -ResourceType "Microsoft.Web/certificates"
$resource | Set-AzureRmResource -Tag @{Test="Done"}

Module Version

PS C:\Users\kwill> Get-Module -Name AzureRM.Resources -ListAvailable

    Directory: C:\Program Files (x86)\Microsoft SDKs\Azure\PowerShell\ResourceManager\AzureResourceManager

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     5.4.0      AzureRM.Resources                   {Get-AzureRmProviderOperation, Remove-AzureRmRoleAssignmen...

Environment Data

PS C:\Users\kwill> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.16299.248
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.248
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Debug Output

PS C:\Users\kwill> $resource = Get-AzureRmResource -ResourceId "/subscriptions/5857f4d2-3dce-4b96-ad95-677f764e7a67/reso
urceGroups/TranslatorAPI_RG/providers/Microsoft.Web/certificates/7AF95FD8301E759535D8C9BD6F7C61E7DD92833F#TranslatorAPI_
RG-WestUSwebspace"
DEBUG: 3:10:09 PM - GetAzureResourceCmdlet begin processing with ParameterSet 'GetByResourceId'.
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://management.azure.com/subscriptions/5857f4d2-3dce-4b96-ad95-677f764e7a67/resourceGroups/TranslatorAPI_RG/provide
rs/Microsoft.Web/certificates/7AF95FD8301E759535D8C9BD6F7C61E7DD92833F#TranslatorAPI_RG-WestUSwebspace?api-version=2016
-03-01

Headers:
User-Agent                    : AzurePowershell/v5.4.0,PSVersion/v5.1.16299.248
ParameterSetName              : GetByResourceId
CommandName                   : Get-AzureRmResource

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
BadRequest

Headers:
Pragma                        : no-cache
x-ms-failure-cause            : gateway
x-ms-request-id               : 88751f00-2379-43a4-91a3-d45521b16882
x-ms-correlation-request-id   : 88751f00-2379-43a4-91a3-d45521b16882
x-ms-routing-request-id       : WESTUS2:20180306T211010Z:88751f00-2379-43a4-91a3-d45521b16882
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Cache-Control                 : no-cache
Date                          : Tue, 06 Mar 2018 21:10:09 GMT

Body:
{
  "error": {
    "code": "MissingApiVersionParameter",
    "message": "The api-version query parameter (?api-version=) is required for all requests."
  }
}

Get-AzureRmResource : MissingApiVersionParameter : The api-version query parameter (?api-version=) is required for all
requests.
At line:1 char:13
+ $resource = Get-AzureRmResource -ResourceId "/subscriptions/5857f4d2- ...
+             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureRmResource], ErrorResponseMessageException
    + FullyQualifiedErrorId : MissingApiVersionParameter,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementati
   on.GetAzureResourceCmdlet
cormacpayne commented 6 years ago

@kwill-MSFT Hey Kevin, would you mind providing the output of the following command:

$resource = Get-AzureRmResource -ResourceName "7AF95FD8301E759535D8C9BD6F7C61E7DD92833F#TranslatorAPI_RG-WestUSwebspace" -ResourceGroupName "TranslatorAPI_RG" -ResourceType "Microsoft.Web/certificates"

We are curious what the resulting properties are of the object returned.

@vivsriaus @ravbhatnagar would you mind taking a look at this issue?

kwill-MSFT commented 6 years ago
PS C:\Users\kwill> $resource = Get-AzureRmResource -ResourceName "7AF95FD8301E759535D8C9BD6F7C61E7DD92833F#TranslatorAPI
_RG-WestUSwebspace" -ResourceGroupName "TranslatorAPI_RG" -ResourceType "Microsoft.Web/certificates"
PS C:\Users\kwill> $resource

Name              : 7AF95FD8301E759535D8C9BD6F7C61E7DD92833F#TranslatorAPI_RG-WestUSwebspace
ResourceId        : /subscriptions/5857f4d2-3dce-4b96-ad95-677f764e7a67/resourceGroups/TranslatorAPI_RG/providers/Micro
                    soft.Web/certificates/7AF95FD8301E759535D8C9BD6F7C61E7DD92833F#TranslatorAPI_RG-WestUSwebspace
ResourceName      : 7AF95FD8301E759535D8C9BD6F7C61E7DD92833F#TranslatorAPI_RG-WestUSwebspace
ResourceType      : Microsoft.Web/certificates
ResourceGroupName : TranslatorAPI_RG
Location          : West US
SubscriptionId    : 5857f4d2-3dce-4b96-ad95-677f764e7a67
Tags              : {Test}
Properties        : @{friendlyName=; subjectName=makecert; hostNames=System.Object[]; pfxBlob=; siteName=; selfLink=;
                    issuer=makecert; issueDate=2018-01-22T16:48:36+00:00; expirationDate=2039-12-31T23:59:59+00:00;
                    password=; thumbprint=7AF95FD8301E759535D8C9BD6F7C61E7DD92833F; valid=; toDelete=; cerBlob=;
                    publicKeyHash=; hostingEnvironment=; hostingEnvironmentProfile=; keyVaultSecretStatus=Initialized;
                    webSpace=TranslatorAPI_RG-WestUSwebspace; serverFarmId=; tags=}
cormacpayne commented 6 years ago

CC: @Tiano2017

Sterlingg commented 3 years ago

Any update on this? I ran into this recently while trying to clean-up some expired app service certificates.