Azure / azure-iot-cli-extension

Azure IoT extension for Azure CLI
Other
82 stars 64 forks source link

fix: root authority quote bug #690

Closed vilit1 closed 8 months ago

vilit1 commented 8 months ago

Let's say you have an old hub that has not been migrated yet (so no properties.rootCertificates) and a route with the condition: "ObjectType = 'HistoryUpdateMessage' AND ObjectVersion = '1'"

The json dumps in the resource update command results in the wonderful message: (400104) Invalid Routing Condition, RouteName:cond2_very_long_long_long_long_name, ErrorMessage:Message:Invalid operands to binary operator '=': have 'string' and 'number', expected 'string' and 'string', Location <start>:1:53, <end>:1:54, Severity:Error . If you contact a support representative please include this correlation identifier: 866a8f51-11e4-4b16-bd76-610354864f6b, timestamp: 2023-11-08 22:34:05Z, errorcode: IH400104.

To fix this - we

  1. take the dumped string
  2. replace the " with \\"
  3. put it into the command with " around it

which results in this monstrosity of a command: resource update -n potato-hub3 -g vilit --api-version 2022-04-30-preview --resource-type Microsoft.Devices/IotHubs --set properties="{\"allowedFqdnList\": [], \"cloudToDevice\": {\"defaultTtlAsIso8601\": \"PT1H\", \"feedback\": {\"lockDurationAsIso8601\": \"PT5S\", \"maxDeliveryCount\": 10, \"ttlAsIso8601\": \"PT1H\"}, \"maxDeliveryCount\": 10}, \"enableFileUploadNotifications\": false, \"eventHubEndpoints\": {\"events\": {\"endpoint\": \"sb://iothub-ns-potato-hub-25315843-70886fa391.servicebus.windows.net/\", \"partitionCount\": 4, \"partitionIds\": [\"0\", \"1\", \"2\", \"3\"], \"path\": \"potato-hub3\", \"retentionTimeInDays\": 1}}, \"features\": \"None\", \"hostName\": \"potato-hub3.azure-devices.net\", \"ipFilterRules\": [], \"locations\": [{\"location\": \"East US\", \"role\": \"primary\"}, {\"location\": \"West US\", \"role\": \"secondary\"}], \"messagingEndpoints\": {\"fileNotifications\": {\"lockDurationAsIso8601\": \"PT5S\", \"maxDeliveryCount\": 10, \"ttlAsIso8601\": \"PT1H\"}}, \"provisioningState\": \"Succeeded\", \"rootCertificate\": {\"enableRootCertificateV2\": true}, \"routing\": {\"endpoints\": {\"cosmosDBSqlCollections\": [], \"eventHubs\": [], \"serviceBusQueues\": [], \"serviceBusTopics\": [], \"storageContainers\": []}, \"fallbackRoute\": {\"condition\": \"true\", \"endpointNames\": [\"events\"], \"isEnabled\": true, \"name\": \"$fallback\", \"source\": \"DeviceMessages\"}, \"routes\": [{\"condition\": \"ObjectType = 'HistoryUpdateMessage' AND ObjectVersion = '1'\", \"endpointNames\": [\"events\"], \"isEnabled\": true, \"name\": \"cond2_very_long_long_long_long_name\", \"source\": \"DeviceMessages\"}]}, \"state\": \"Active\", \"storageEndpoints\": {\"$default\": {\"connectionString\": \"\", \"containerName\": \"\", \"sasTtlAsIso8601\": \"PT1H\"}}}"

but it works.


This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.

Thank you for contributing to the IoT extension!

This checklist is used to make sure that common guidelines for a pull request are followed.

General Guidelines

Intent for Production

Basic expectations

Azure IoT CLI maintainers reserve the right to enforce any of the outlined expectations.

A PR is considered ready for review when all basic expectations have been met (or do not apply).