Git Product home page Git Product logo

aaz-dev-tools's Introduction

Microsoft Atomic Azure CLI Dev Tools

The aaz-dev tool is designed to generate atomic Azure CLI commands from OpenAPI specifications. For more information, please refer to document and video.

Installation

Currently, we can install it with a .whl file. Later on, we'll publish it to PyPI to support pip install way of installation.

Setting up your development environment

1 Code repos

Please Fork the following repos in your github account and Clone them in your local disk:

After clone you can add upstream for every repos in your local clone by using git remote add upstream.

2 Setup python

2.1 Install python

Please install python with version >= 3.8 in your local machine.

  • For windows: You can download and run full installer from Python Download.
  • For linux: You can install python from Package Manager or build a stable relase from source code

Check the version of python, make use it's not less than 3.8.

  • For windows: You can run:
    C:\Users\{xxxx}\AppData\Local\Programs\Python\Python3{xxxx}\python --version
    C:\Users\{xxxx}\AppData\Local\Programs\Python\Python3{xxxx} is the python installation path.
  • For linux:
    python --version
    You can also specify the version number when you have multiple versions installed. For example if you want to run version 3.8
    python3.8 --version

2.2 Setup a python virtual environment

You can use venv to create virtual environments, optionally isolated from system site directories. Each virtual environment has its own Python binary (which matches the version of the binary that was used to create this environment) and can have its own independent set of installed Python packages in its site directories.

You can run the following command to create a new virtual environment:

  • For windows:
    C:\Users\{xxxx}\AppData\Local\Programs\Python\Python3{xxxx}\python -m venv {some path}\{venv name}
  • For linux:
    python3.8 -m venv {some path}/{venv name}

3 Active existing virtual environment

You should always active the virtual environment for azure-cli development.

  • For Windows:
    • Powershell
    {some path}\{venv name}\Scripts\Activate.ps1
    • Command Prompt
    {some path}\{venv name}\Scripts\activate.bat
  • For Linux:
source {some path}/{venv name}/bin/activate

After active the virtual environment, the python command will always be the one creates this virtual environment and you can always use python

python --version

4 Install tools for azure-cli development

Both for windows and linux

pip install azdev

4.2 Install aaz-dev-tools

  • For Windows
    • Powershell
    pip install aaz-dev
    
    • Command Prompt
    pip install aaz-dev
    
  • For linux
    pip install aaz-dev

4.3 Set up build env

  • For linux users, set up python3 build tools would avoid other unseen installation issues
    Ubuntu: apt-get install python3-dev build-essential
    Centos: yum install python3-devel
    

4.4 Possible problems

  • For windows users, dependency python-levenshtein installation might run into trouble. developers might need to download .whl file and install it manually (reference to link)

5. Code repos setup

5.1 azure-cli

Before start to the development task, you should always sync the code in the dev branch of upstream(Azure/Azure-cli). If your commands will generated to azure-cli repo, you should checkout a new branch with feature- prefix.

5.2 azure-cli-extensions

If your commands will generated to azure-cli-extension repo, you should sync the code in the main branch of upstream(Azure/Azure-cli-extensions), and checkout a new branch with feature- prefix.

5.3 aaz

Before start to the development task, you should always sync the change in the main branch of upstream, and checkout a new branch with feature- prefix.

5.4 run azdev setup

You should always run the following command everytime you sync azure-cli code of upstream.

azdev setup --cli {path to azure-cli} --repo {path to azure-cli-extensions}

6 Run aaz-dev-tools

aaz-dev run -c {path to azure-cli} -e {path to azure-cli-extensions} -s {path swagger or swagger-pr} -a {path to aaz}

Before using generated commands

  1. Make sure you have logined by az login.
  2. Make sure you have switched to the subscription for test by az account set -s {subscription ID for test}
  3. If your commands are in extensions, make sure you have loaded this extension by azdev extension add {your extension name}

Other documentations

Submit code and command models

After finish the development, you should push the change in your forked repos first, and the create a Pull Request to upstream repos.

  • azure-cli: create a Pull Request to dev branch of Azure/azure-cli
  • azure-cli-extensions: create a Pull Request to main branch of Azure/azure-cli-extensions
  • aaz: create a Pull Request to main branch of Azure/azz

Reporting issues and feedback

If you encounter any bugs with the tool please file an issue in the Issues section of our GitHub repository.

License

MIT License

Copyright (c) Microsoft Corporation. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

aaz-dev-tools's People

Contributors

allyw avatar calvinhzy avatar jacekey23 avatar jeremyhouser-ms avatar kairu-ms avatar microsoft-github-policy-service[bot] avatar mochilia avatar necusjz avatar onlined avatar reanaived avatar wangzelin007 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aaz-dev-tools's Issues

No way to see long running API response

The current CLI provides waiting by default for each command. When --no-wait option is used, the CLI immediately returns back without displaying anything to the customer. If this is a long running action, the customer has no ability to retrieve the status of async command. Each command would need to use --debug to see 'Azure-AsyncOperation' header returned. This creates poor customer experience.

The proposal is to enhance command behavior for --no-wait.
Specifically, when the customer asks not to wait for the final result, the CLI should print a header back.

aaz-dev-tool not generation command/code as expected. cli option for list must be backward compatible.

Closed Azure/azure-cli#25139

Related command
aaz-dev-tool not generation command/code as expected. command option for list must be backward compatible. following are expectation generated command

az maintenance configuration create --resource-group 'log-dev-eus-rsg' --resource-name 'LinuxNonProd2' --duration '03:55' --location 'eastus' --maintenance-scope 'InGuestPatch' --maintenance-window-recur-every '1Month Second Sunday' --maintenance-window-start-date-time '2022-07-26 00:00' --maintenance-window-time-zone 'Eastern Standard Time' --reboot-setting 'IfRequired' --visibility 'Custom' --install-patches-linux-parameters classifications-to-include=Critical classifications-to-include=Security --debug

Debug output:

cli.azure.cli.core.sdk.policies: Request body:
cli.azure.cli.core.sdk.policies: {"location": "eastus", "properties": {"maintenanceScope": "InGuestPatch", "visibility": "Custom", "installPatches": {"rebootSetting": "IfRequired", "linuxParameters": {"classificationsToInclude": ["Critical", "Security"]}}, "maintenanceWindow": {"startDateTime": "2022-07-26 00:00", "duration": "03:55", "timeZone": "Eastern Standard Time", "recurEvery": "1Month Second Sunday"}}}

Is your feature request related to a problem? Please describe.
No, bug in code generation (must provide backward compatibility)

Describe the solution you'd like
Provide option to accept list in command line

Support original autorest naming complex for legacy compatibility

@kairu-ms This issue follows up with the meeting we recently had about integrating aaz into our CLI generation for Network Cloud.

My team is making the move from autorest to aaz. As part of this effort, we need to conform our CLI to previous naming standards.

This means that when a resource type is namedLikeThis in our spec, we need to resulting command to read "az namedlikethis with-sub-command" rather than "az named-like-this with-sub-command". Additionally, we would like for child resources which now become nested in parent resources to also respect this, such that parentResource with childResource results in the command 'az parentresource childresource with-sub-command".

An option to either choose this legacy format or define our own format would be greatly appreciated.

Thank you!

Make "aaz run -c" switch non-required

The -c switch is used to specify the command_modules in azure-cli

when working with code which is not present in azure-cli, this switch is unnecessary. Requiring it creates a dependency to either give it a dummy directory to find the path it expects, download azure-cli and use it, or give it a dummy directory without the path it expects, which generates an error that doesn't matter to us.

Instead, I would like to see a message in the help for -c and -s/--sm that states when you should use the given switch.

Please let me know what you think, thank you.

aaz generated delete command returns `TypeError: 'NoneType' object is not callable` for async delete operation

Hello, I used aaz-dev-tools to generate commands for this swagger. It defines a resource called storageclass, and its deletion operation is a long running operation swagger.

But when using the delete command, it returns error. The resource is actually deleted despite the error.

It seems to happen when the LRO is completed.

> az k8s-runtime storage-class delete  --resource-uri /subscriptions/b9e38f20-7c9c-4497-a25d-1a0c5eef2108/resourceGroups/jundachen/providers/Microsoft.Kubernetes/connectedClusters/test-1-arc --storage-class-name rwx-test --debug
...
urllib3.connectionpool: https://management.azure.com:443 "GET /subscriptions/b9e38f20-7c9c-4497-a25d-1a0c5eef2108/providers/Microsoft.KubernetesRuntime/locations/EASTUS/operationStatuses/1cf49bf6-8312-4cb0-9284-a40775d92ed9*40175B44B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0hRgTzuMiiq8PUrVdDBN8_c3HcEZsxdazvy4RNcw_7WjYA3QdRzVtaOAEfPq6GrfCF7n8qlpXjMSOq5Oc-mL6EwulQAybtx4RxY0zI5tDTHfITDo2FVSa6thj9WVlgOF2UxNbopXBAYpN-fbgUTanBsphWY2F_Kz_VKFv-4UXHwyNiDa3wpaQrmQ2urunWos3lEhx0aRKdNTZwjJtK78rfIazNccJHT1LHpWU7i8XEBYP_RzftkGhoEhofdnth4t99G4Clw9RBOC8Km1SZ7zJTtaYcCU-NXSzWQgWTQeGMwo5CnvADN5uPXz3aUMxAukDY-ed4wPldjzzJFmzk&s=Vo1W0vEiuHbagWjbset47CqgjisFTXkazmTEFBQOv-0K1Q7l2LwPmgMsh2_3Vf7gzil_eK1Yg6JjGHfzDVsGOKbZrZfgf0N6rdE-olX13SzyVfDQR-DCAy4xpG4YJ6nM08leYkhtAS3IW_cpD4BOa13k0fH8AHeM6umy0iHyRnk6colEKl-HD1y2RIT2HJMmBP-5wxW2BGyEXBd4fpbr3uISiiXEQd09-rpM7_YwxXBid30PuSlRoKk8P1orrpQStuWFta-SwAMhfO4D8Q_LyDRkCeQnFfUl7wWjloVF-rJkmhYX-MbRd7hbz-_HIyj5CT5AEVYxWYLpKjfQ00-xsQ&h=4aKM-brAHAE2UdqImaVJCv_UG2HYZ-3KRCfCtnru8Mk HTTP/1.1" 200 683
cli.azure.cli.core.sdk.policies: Response status: 200
cli.azure.cli.core.sdk.policies: Response headers:
cli.azure.cli.core.sdk.policies:     'Cache-Control': 'no-cache'
cli.azure.cli.core.sdk.policies:     'Pragma': 'no-cache'
cli.azure.cli.core.sdk.policies:     'Content-Length': '683'
cli.azure.cli.core.sdk.policies:     'Content-Type': 'application/json; charset=utf-8'
cli.azure.cli.core.sdk.policies:     'Expires': '-1'
cli.azure.cli.core.sdk.policies:     'ETag': '"bf019337-0000-0100-0000-65dd580c0000"'
cli.azure.cli.core.sdk.policies:     'x-ms-ratelimit-remaining-subscription-reads': '11999'
cli.azure.cli.core.sdk.policies:     'x-ms-request-id': '4fbf305b-49c8-46dc-b6af-636ed05c4c46'
cli.azure.cli.core.sdk.policies:     'x-ms-correlation-request-id': '53f9555e-19f4-42e0-8969-ac2587e625aa'
cli.azure.cli.core.sdk.policies:     'x-ms-routing-request-id': 'SOUTHEASTASIA:20240227T033401Z:53f9555e-19f4-42e0-8969-ac2587e625aa'
cli.azure.cli.core.sdk.policies:     'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
cli.azure.cli.core.sdk.policies:     'X-Content-Type-Options': 'nosniff'
cli.azure.cli.core.sdk.policies:     'X-Cache': 'CONFIG_NOCACHE'
cli.azure.cli.core.sdk.policies:     'X-MSEdge-Ref': 'Ref A: 8A4962C6087046F28835BD02D5296987 Ref B: MAA201060513033 Ref C: 2024-02-27T03:33:59Z'
cli.azure.cli.core.sdk.policies:     'Date': 'Tue, 27 Feb 2024 03:34:00 GMT'
cli.azure.cli.core.sdk.policies: Response content:
cli.azure.cli.core.sdk.policies: {"id":"/subscriptions/b9e38f20-7c9c-4497-a25d-1a0c5eef2108/providers/Microsoft.KubernetesRuntime/locations/EASTUS/operationStatuses/1cf49bf6-8312-4cb0-9284-a40775d92ed9*40175B44BD3CAF9B59AFF23D2B0AFC276BD5EDDC0D41311D2624DA15FAA6086F","name":"1cf49bf6-8312-4cb0-9284-a40775d92ed9*40175B44BD3CAF9B59AFF23D2B0AFC276BD5EDDC0D41311D2624DA15FAA6086F","resourceId":"/subscriptions/b9e38f20-7c9c-4497-a25d-1a0c5eef2108/resourceGroups/jundachen/providers/Microsoft.Kubernetes/connectedClusters/test-1-arc/providers/Microsoft.KubernetesRuntime/storageClasses/rwx-test","status":"Succeeded","startTime":"2024-02-27T03:33:27.3505511Z","endTime":"2024-02-27T03:33:32.7938472Z","properties":null}
cli.azure.cli.core.azclierror: Traceback (most recent call last):
  File "E:\Code\azure-cli-extensions\env\lib\site-packages\knack\cli.py", line 233, in invoke
    cmd_result = self.invocation.execute(args)
  File "E:\Code\azure-cli-extensions\env\lib\site-packages\azure\cli\core\commands\__init__.py", line 664, in execute
    raise ex
  File "E:\Code\azure-cli-extensions\env\lib\site-packages\azure\cli\core\commands\__init__.py", line 729, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "E:\Code\azure-cli-extensions\env\lib\site-packages\azure\cli\core\commands\__init__.py", line 709, in _run_job
    result = LongRunningOperation(cmd_copy.cli_ctx, 'Starting {}'.format(cmd_copy.name))(result)
  File "E:\Code\azure-cli-extensions\env\lib\site-packages\azure\cli\core\commands\__init__.py", line 1033, in __call__
    result = poller.result()
  File "E:\Code\azure-cli-extensions\env\lib\site-packages\azure\cli\core\aaz\_poller.py", line 109, in result
    resource = self._polling_method.resource()
  File "E:\Code\azure-cli-extensions\env\lib\site-packages\azure\core\polling\base_polling.py", line 668, in resource
    return self._parse_resource(self._pipeline_response)
  File "E:\Code\azure-cli-extensions\env\lib\site-packages\azure\core\polling\base_polling.py", line 683, in _parse_resource
    return self._deserialization_callback(pipeline_response)
TypeError: 'NoneType' object is not callable

az cli (2.57), all extensions and aaz-dev-tools (2.6) are updated to latest.

How can I resolve this issue? Thanks!

Long run operation instant return lacks

The cdn custom-domain enable-https cmd may takes hours before it returns, and meanwhile this cmd will report the progress,
the old way it can return when receiving first report, but now when using aaz, the cmd will keep reporting until the enable operation finished.

Support generating an empty param option with polymorphism object without parameters

https://github.com/calvinhzy/azure-rest-api-specs/blob/b0b51026d94ecc2f9748df05451fc5417bd974c4/specification/recoveryservicessiterecovery/resource-manager/Microsoft.RecoveryServices/stable/2022-08-01/service.json#L12880-L12895

2022-08-01 /subscriptions/{}/resourcegroups/{}/providers/microsoft.recoveryservices/vaults/{}/replicationfabrics/{}/replicationprotectioncontainers/{}/replicationprotectioncontainermappings/{}

CLI - Array of object feature request

CLI - Array of object feature request
The multiple addition/deletion feature is not supported by the aaz-dev-tool subcommand's current version. That is, when I use a subcommand to construct, for example, az eventhubs namespace encryption add, we can only add one encryption attribute at a time.

Therefore, in order to avoid this, we have built custom code. For example, I added the cli_add_encryption method. https://github.com/schaudhari6254888/azure-cli/blob/cccd800d7c631dbc33e9710719bfe6a3ea142fb1/src/azure-cli/azure/cli/command_modules/eventhubs/operations/namespace_custom.py#L90

However, if we can construct this Array of objects using a tool, for example, look at this swagger file.

https://github.com/schaudhari6254888/azure-rest-api-specs/blob/6c6b16dc98d720304633b76c8e82c282ffa9cc08/specification/eventhub/resource-manager/Microsoft.EventHub/preview/2022-10-01-preview/namespaces-preview.json#L915

keyVaultProperties is an array of objects containing keyName, keyVaultURI, KeyVersion, and Identity. So the encryption add subcommand should take this keyVaultProperties as an array of objects, allowing us to handle multiple addition of encryption for the add subcommand.

Similarly, for the delete subcommand operation, we may use x-ms-identifier=['properties/keyVaultProperties'] to identify the deletion to be done on keyVaultProperties only.

for ex - az eventhubs namespace encryption remove --resource-group {rg} --namespace-name {namespacename} --encryption-config key-name={key2} key-vault-uri={key_uri} user-assigned-identity={id1} --encryption-config key-name={key3} key-vault-uri={key_uri} user-assigned-identity={id1}

This way, we can simplify the subcommands and avoid future custom code.

InvalidSwaggerValueError: type is not supported : [None]

I am trying to use aaz-dev to generate command modules from changes in this PR Azure/azure-rest-api-specs#27529 however I'm getting the following error after clicking "Submit" in my workspace:

ResponseError: InvalidSwaggerValueError: type is not supported : [None] : ('C:\\dev\\projects\\azure-rest-api-specs\\specification\\resources\\resource-manager\\Microsoft.Resources\\stable\\2024-03-01\\deploymentStacks.json', 'definitions', 'DeploymentParameter', 'properties', 'value')

Screenshot 2024-03-01 115924

This is the relevant swagger definition: https://github.com/Azure/azure-rest-api-specs/pull/27529/files#diff-ce26e6277ce376291646359d007c1267f3d1f94a8a799c60bcbba402d64ea43bR1350

The type of this value property is dynamic. It is an 'any' type (number, string, boolean, object, array, null, etc) and its actual value type is checked at runtime in the service.

There doesn't seem to be a spec for an 'any' type, but supposedly the swagger tooling treats an unspecified type as any.

What should I do in this case? Is it a bug or can I represent this a different way such as binary data?

Required parameter is treated as optional by aaz-dev

Treat object parameter as free-form object when the parameter does not specify additionalProperties=false explicitly in API spec

Per https://swagger.io/docs/specification/data-models/data-types/, an object is free-form object by default if it doesn't specify additionalProperties=false in API spec.

Currently, aaz-dev only treats object as free-form object when the object specifies additionalProperties=true. Here's an example definition that falls into this situation, which will cause Failed to parse '--custom-properties' argument: "Model 'AAZObjectArg' has no field named 'xxx'" error when user passes free-form object to the parameter:

"CustomProperties": {
      "type": "object",
      "description": "The custom metadata defined for API catalog entities."
},

The expected behavior is aaz-dev can treat above parameter as free-form object and allow users pass values with arbitrary properties.

You can use https://github.com/Azure/azure-rest-api-specs/blob/main/specification/apicenter/resource-manager/Microsoft.ApiCenter/stable/2024-03-01/apicenter.json to test the behavior.

Required properties with no required sub-properties omits empty object in ReST PUT call

When attempting to generate a CLI from OpenAPI/swagger with the following:

    "KubernetesClusterFeature": {
      "type": "object",
      "title": "KubernetesClusterFeature represents the feature of a Kubernetes cluster.",
      "required": [
        "properties"
      ],
      "properties": {
        "properties": {
          "$ref": "#/definitions/KubernetesClusterFeatureProperties",
          ... 

where the properties property has no required fields within.

When any of the subordinate fields are specified, the correct body is produced.
However, when none of the child fields of the properties field are specified in the CLI command, the entire required property is omitted.

Expected:

PUT .../kubernetesClusterFeatures/someFeature

{
    "properties": {}
}

Instead produced:

PUT .../kubernetesClusterFeatures/someFeature

{}

This is a malformed request.

Reference this swagger: https://github.com/Azure/azure-rest-api-specs-pr/blob/62cbc2823818c586464a030bd1e80a39df9da4f8/specification/networkcloud/resource-manager/Microsoft.NetworkCloud/preview/2024-06-01-preview/networkcloud.json#L9791

Add support for x-ms-long-running-operation-options.final-state-schema

Autorest has added a new field to the x-ms-long-running-operation-options specification extension, final-state-schema.

https://github.com/Azure/autorest/tree/main/docs/extensions#x-ms-long-running-operation-options

final-state-schema can be used to point to the definition of the response schema returned from the final-state-via. Previously this schema was specified on the 200 response for the operation, but this was problematic because the operation may not actually return 200. final-state-schema allows the API author to avoid "fibbing" about the 200 response just to make autorest work.

aaz-dev-tools should also add support for final-state-schema.

Cannot analyze response in aaz-dev-generated code

I am migrating old cli to AAZ, but when I am running UT, there is an error:

E           azure.cli.testsdk.exceptions.JMESPathCheckAssertionError: Query 'deliveryPolicy.rules[1].conditions[0].parameters.matchType' doesn't yield expected value 'Wildcard', instead the actual value is 'None'. Data: 
E           {
E             "contentTypesToCompress": [],
E             "customDomains": [],
E             "deliveryPolicy": {
E               "description": "default_policy",
E               "rules": [
E                 {
E                   "actions": [
E                     {
E                       "name": "CacheExpiration",
E                       "parameters": {
E                         "cacheBehavior": "Override",
E                         "cacheDuration": "00:05:00",
E                         "cacheType": "All",
E                         "typeName": "DeliveryRuleCacheExpirationActionParameters"
E                       }
E                     }
E                   ],
E                   "conditions": [],
E                   "order": 0
E                 },
E                 {
E                   "actions": [
E                     {
E                       "name": "CacheExpiration",
E                       "parameters": {
E                         "cacheBehavior": "Override",
E                         "cacheDuration": "00:05:00",
E                         "cacheType": "All",
E                         "typeName": "DeliveryRuleCacheExpirationActionParameters"
E                       }
E                     }
E                   ],
E                   "conditions": [
E                     {
E                       "name": "UrlPath",
E                       "parameters": {
E                         "typeName": "DeliveryRuleUrlPathConditionParameters"
E                       }
E                     }
E                   ],
E                   "order": 1
E                 }
E               ]
E             },
E             "geoFilters": [],
E             "hostName": "endpointkewgalgzdqdgommi.azureedge.net",
E             "id": "/subscriptions/27cafca8-b9a4-4264-b399-45d0c9cca1ab/resourcegroups/clitest.rgxc2tgodwwnzgtbitsa4fj65fgukgms4ka4wifgodbqzlo3jj23he4mvap622qozgo/providers/Microsoft.Cdn/profiles/akpxtdyjskdyy22ocjaiehxi/endpoints/endpointkewgalgzdqdgommi",
E             "isCompressionEnabled": false,
E             "isHttpAllowed": true,
E             "isHttpsAllowed": true,
E             "location": "WestUs",
E             "name": "endpointkewgalgzdqdgommi",
E             "originGroups": [],
E             "origins": [
E               {
E                 "enabled": true,
E                 "hostName": "huaiyiztesthost1.blob.core.chinacloudapi.cn",
E                 "httpPort": 80,
E                 "httpsPort": 443,
E                 "name": "huaiyiztesthost1-blob-core-chinacloudapi-cn"
E               }
E             ],
E             "provisioningState": "Succeeded",
E             "queryStringCachingBehavior": "IgnoreQueryString",
E             "resourceGroup": "clitest.rgxc2tgodwwnzgtbitsa4fj65fgukgms4ka4wifgodbqzlo3jj23he4mvap622qozgo",
E             "resourceState": "Running",
E             "tags": {},
E             "type": "Microsoft.Cdn/profiles/endpoints"
E           }

However, I can see matchType in my response when I debug this cmd with launch.json, so I think there is some reason why aaz analyze failed in the field conditions.

The change I made: https://github.com/Ptnan7/azure-cli/blob/3a9a8b3cf2cd92e166da17f71b419001942ae52e/src/azure-cli/azure/cli/command_modules/cdn/custom/custom_cdn.py#L628

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.