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

Tags are case sensitive due to using defaults for Dictionary and HashTable #9271

Open
nopjmp opened this issue May 22, 2019 · 3 comments
Open
Assignees
Projects
Milestone

Comments

@nopjmp
Copy link

nopjmp commented May 22, 2019

Description

Tags returned from the Az module are considered to be case sensitive. In the Azure portal, tags are considered to be case insensitive when searching for tags from the GUI.

It looks like StringComparer.OrdinalIgnoreCase is needing to be used for the HashTable and Dictionaries in several places (AKV Module example below)

public static Dictionary<string, string> ConvertToDictionary(this Hashtable tags)
{
Dictionary<string, string> tagsDictionary = new Dictionary<string, string>();
foreach (DictionaryEntry tag in tags)
{
string key = tag.Key as string;
if (string.IsNullOrWhiteSpace(key))
throw new ArgumentException("Invalid tag name");
if (tag.Value != null && !(tag.Value is string))
throw new ArgumentException("Tag has invalid value");
string value = (tag.Value == null) ? string.Empty : (string)tag.Value;
tagsDictionary[key] = value;
}
return tagsDictionary;
}
public static Hashtable ConvertToHashtable(this IDictionary<string, string> tags)
{
Hashtable tagsHashtable = new Hashtable();
foreach (var tag in tags)
tagsHashtable[tag.Key] = tag.Value;
return tagsHashtable;
}

We are having problems extracting tag information from virtual machines due to this for automation and reporting for our customers.

Steps to reproduce

> $vm = Get-AzVM
> $vm.Tags["mycooltag"]
supercool
> $vm.Tags["MyCoolTag"]
> $hashTable = @{mycooltag = "supercool"}
> $hashTable["mycooltag"]
supercool
> $hashTable["MyCoolTag"]
supercool

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Script     1.6.0      Az                                  Core,Desk
Script     1.5.0      Az                                  Core,Desk
Script     1.4.0      Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzContextAutosa…
Script     1.0.1      Az.Aks                              Core,Desk {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAksC…
Script     1.0.2      Az.AnalysisServices                 Core,Desk {Resume-AzAnalysisServicesServer, Suspend-AzAnalys…
Script     1.0.0      Az.ApiManagement                    Core,Desk {Add-AzApiManagementRegion, Get-AzApiManagementSso…
Script     1.0.0      Az.ApplicationInsights              Core,Desk {Get-AzApplicationInsights, New-AzApplicationInsig…
Script     1.2.0      Az.Automation                       Core,Desk {Get-AzAutomationHybridWorkerGroup, Remove-AzAutom…
Script     1.1.2      Az.Automation                       Core,Desk {Get-AzAutomationHybridWorkerGroup, Remove-AzAutom…
Script     1.0.0      Az.Batch                            Core,Desk {Remove-AzBatchAccount, Get-AzBatchAccount, Get-Az…
Script     1.0.0      Az.Billing                          Core,Desk {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-Az…
Script     1.1.0      Az.Cdn                              Core,Desk {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-AzC…
Script     1.0.1      Az.CognitiveServices                Core,Desk {Get-AzCognitiveServicesAccount, Get-AzCognitiveSe…
Script     1.6.0      Az.Compute                          Core,Desk {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, …
Script     1.5.0      Az.Compute                          Core,Desk {Remove-AzAvailabilitySet, Get-AzAvailabilitySet, …
Script     1.0.0      Az.ContainerInstance                Core,Desk {New-AzContainerGroup, Get-AzContainerGroup, Remov…
Script     1.0.1      Az.ContainerRegistry                Core,Desk {New-AzContainerRegistry, Get-AzContainerRegistry,…
Script     1.0.2      Az.DataFactory                      Core,Desk {Set-AzDataFactoryV2, Update-AzDataFactoryV2, Get-…
Script     1.0.0      Az.DataLakeAnalytics                Core,Desk {Get-AzDataLakeAnalyticsDataSource, New-AzDataLake…
Script     1.1.0      Az.DataLakeStore                    Core,Desk {Get-AzDataLakeStoreTrustedIdProvider, Remove-AzDa…
Script     1.0.0      Az.DevTestLabs                      Core,Desk {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShutd…
Script     1.0.0      Az.Dns                              Core,Desk {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remove…
Script     1.1.0      Az.EventGrid                        Core,Desk {New-AzEventGridTopic, Get-AzEventGridTopic, Set-A…
Script     1.0.1      Az.EventHub                         Core,Desk {New-AzEventHubNamespace, Get-AzEventHubNamespace,…
Script     1.0.0      Az.HDInsight                        Core,Desk {Get-AzHDInsightJob, New-AzHDInsightSqoopJobDefini…
Script     1.0.2      Az.IotHub                           Core,Desk {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGrou…
Script     1.1.0      Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Update-AzKeyVaultCerti…
Script     1.0.2      Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Update-AzKeyVaultCerti…
Script     1.2.1      Az.LogicApp                         Core,Desk {Get-AzIntegrationAccountAgreement, Get-AzIntegrat…
Script     1.0.0      Az.MachineLearning                  Core,Desk {Move-AzMlCommitmentAssociation, Get-AzMlCommitmen…
Script     1.0.0      Az.MarketplaceOrdering              Core,Desk {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}
Script     1.0.0      Az.Media                            Core,Desk {Sync-AzMediaServiceStorageKeys, Set-AzMediaServic…
Script     1.0.1      Az.Monitor                          Core,Desk {Get-AzMetricDefinition, Get-AzMetric, Remove-AzLo…
Script     1.6.0      Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthenticationCertificate…
Script     1.4.0      Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthenticationCertificate…
Script     1.3.0      Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthenticationCertificate…
Script     1.0.0      Az.NotificationHubs                 Core,Desk {Get-AzNotificationHub, Get-AzNotificationHubAutho…
Script     1.1.0      Az.OperationalInsights              Core,Desk {New-AzOperationalInsightsAzureActivityLogDataSour…
Script     1.0.0      Az.PolicyInsights                   Core,Desk {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPolic…
Script     1.0.0      Az.PowerBIEmbedded                  Core,Desk {Remove-AzPowerBIWorkspaceCollection, Get-AzPowerB…
Script     1.2.0      Az.RecoveryServices                 Core,Desk {Get-AzRecoveryServicesBackupProperty, Get-AzRecov…
Script     1.1.0      Az.RecoveryServices                 Core,Desk {Get-AzRecoveryServicesBackupProperty, Get-AzRecov…
Script     1.0.0      Az.RedisCache                       Core,Desk {Remove-AzRedisCachePatchSchedule, New-AzRedisCach…
Script     1.0.0      Az.Relay                            Core,Desk {New-AzRelayNamespace, Get-AzRelayNamespace, Set-A…
Script     1.2.1      Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove-AzRoleAssignment,…
Script     1.2.0      Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove-AzRoleAssignment,…
Script     1.0.0      Az.ServiceBus                       Core,Desk {New-AzServiceBusNamespace, Get-AzServiceBusNamesp…
Script     1.0.1      Az.ServiceFabric                    Core,Desk {Add-AzServiceFabricApplicationCertificate, Add-Az…
Script     1.0.2      Az.SignalR                          Core,Desk {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey, N…
Script     1.7.0      Az.Sql                              Core,Desk {Get-AzSqlDatabaseTransparentDataEncryption, Get-A…
Script     1.5.0      Az.Sql                              Core,Desk {Get-AzSqlDatabaseTransparentDataEncryption, Get-A…
Script     1.1.0      Az.Storage                          Core,Desk {Get-AzStorageAccount, Get-AzStorageAccountKey, Ne…
Script     1.0.3      Az.Storage                          Core,Desk {Get-AzStorageAccount, Get-AzStorageAccountKey, Ne…
Script     1.0.0      Az.StreamAnalytics                  Core,Desk {Get-AzStreamAnalyticsFunction, Get-AzStreamAnalyt…
Script     1.0.1      Az.TrafficManager                   Core,Desk {Add-AzTrafficManagerCustomHeaderToEndpoint, Remov…
Script     1.1.2      Az.Websites                         Core,Desk {Get-AzAppServicePlan, Set-AzAppServicePlan, New-A…
Script     1.1.1      Az.Websites                         Core,Desk {Get-AzAppServicePlan, Set-AzAppServicePlan, New-A
@nopjmp nopjmp changed the title Tags are case sensitive due to defaults for Dictionary and HashTable Tags are case sensitive due to using defaults for Dictionary and HashTable May 22, 2019
@markcowl
Copy link
Member

@nopjmp Yeah, this is a great point, in ARM, tags are meant to be case insensitive and case preserving. We should make this change in the common code here: https://github.com/Azure/azure-powershell-common/blob/master/src/ResourceManager/Version2016_09_01/Tags/TagsConversionHelper.cs#L52

and ensure that service cmdletsare using it.

Description

  • Update common library tags code to use a type-insensitve comparator in the internal dictionary
  • Add unit tests to ensure case-insensitive manipulation of tags through the helper libraries
  • Consume the new common library, and look for RP-specific code that also needs to be updated.

Cost: 2

@niander niander added this to the 2019-08-13 milestone May 28, 2019
@markcowl markcowl added this to Pending in Transition via automation Aug 3, 2019
@markcowl markcowl moved this from Pending to 2019-08-08 in Transition Aug 3, 2019
@markcowl markcowl moved this from 2019-08-08 to Pending in Transition Aug 30, 2019
@markcowl markcowl removed this from the 2019-08-13 milestone Sep 11, 2019
@cormacpayne cormacpayne added the Generator Related to cmdlet generator label Sep 17, 2019
@cormacpayne cormacpayne added this to the 2019-12-03 milestone Sep 17, 2019
@markcowl markcowl moved this from Pending to Post-Ignite in Transition Oct 18, 2019
@dingmeng-xue
Copy link
Member

Will visit this issue after we change the model used by autorest.

@dsv591
Copy link

dsv591 commented Feb 3, 2021

Any updates on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Transition
  
Post-Ignite
Development

No branches or pull requests

7 participants