azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

Can create path mappings with az resource update --set on Windows but not on Linux.

Open sirwarshade opened this issue 6 years ago • 12 comments

I'm trying to add path mappings, i'm using the "az resource update" command to get to that goal. Only on windows do i get the expected result, which is the creation of additional path mappings.

Both Windows and Linux are on azure-cli 2.0.80.

Command Name az resource update

az resource update --name I20200128R4-Test-Server/config/web --resource-group I20200128R4 --resource-type Microsoft.Web/sites/config --set 'properties.virtualApplications=[{\"physicalPath\":\"site\\wwwroot\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/\"},{\"physicalPath\":\"site\\wwwroot\\v2\\flow-server\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/flow\"},{\"physicalPath\":\"site\\wwwroot\\v2\\iris-server\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/iris\"}]'

Errors: No errors, but i does not create the path mappings i need when i use the command on Linux.

To Reproduce:

Steps to reproduce the behavior. Note that argument values have been redacted, as they may contain sensitive information.

  • Have a web app;
  • Use a ubuntu/debian Linux flavor;
  • Try to create a path mapping with the "az resource update --set" command

Expected Behavior

"virtualApplications": [
  {
    "physicalPath": "site\\wwwroot",
    "preloadEnabled": true,
    "virtualDirectories": null,
    "virtualPath": "/"
  },
  {
    "physicalPath": "site\\wwwroot\\v2\\flow-server",
    "preloadEnabled": false,
    "virtualDirectories": null,
    "virtualPath": "/flow"
  },
  {
    "physicalPath": "site\\wwwroot\\v2\\iris-server",
    "preloadEnabled": false,
    "virtualDirectories": null,
    "virtualPath": "/iris"
  }
]

Environment Summary

Linux-4.4.0-18362-Microsoft-x86_64-with-debian-buster-sid
Python 3.6.5
Shell: bash

azure-cli 2.0.80

Additional Context

sirwarshade avatar Jan 29 '20 10:01 sirwarshade

add to S165.

yonzhan avatar Jan 30 '20 01:01 yonzhan

add to S168

yonzhan avatar Mar 08 '20 02:03 yonzhan

@sirwarshade Hi, I have some questions to confirm with you, please take a look:

  1. You mean that the WebApp deployed in a Windows environment can correctly set up path mappings for physicalPath and virtualPath, but the path mapping cannot take effect in WebApp deployed in Linux environment, right?
  2. Do you have this problem when you perform the same operation on portal?

zhoxing-ms avatar Mar 09 '20 14:03 zhoxing-ms

@zhoxing-ms , i execute the azure cli command from a Linux device and it fails but if i execute the azure cli from a Windows device it succeeds.

The web app is a .NET 4.7 PaaS service. I have no problem configuring the path mappings manually ( portal ).

sirwarshade avatar Mar 10 '20 13:03 sirwarshade

@sirwarshade Hi, az resource update is not designed to support updating the webapp config. (I can't actually update path mappings by executing this command on either Windows or Linux) It only supports the following functions:

  1. Resources - Update (doc link)
  2. Resources - Update By Id (doc link)

If you want to update the configuration of webapp, the following command should be executed: az webapp config set --name {resource-name} -g {resource-group} --generic-configurations "{\"virtualApplications\":[{\"physicalPath\":\"site\\wwwroot\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/\"},{\"physicalPath\":\"site\\wwwroot\\v2\\flow-server\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/flow\"},{\"physicalPath\":\"site\\wwwroot\\v2\\iris-server\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/iris\"}]}" Because only this command implements the function of Web Apps - Create Or Update Configuration (doc link)

zhoxing-ms avatar Mar 12 '20 03:03 zhoxing-ms

@sirwarshade You can have a try. If you have any other questions, please feel free to let us know.

zhoxing-ms avatar Mar 12 '20 03:03 zhoxing-ms

Because there is no reply to this question for a long time, I will close it temporarily. If you have any questions, please feel free to let us know.

zhoxing-ms avatar Mar 23 '20 02:03 zhoxing-ms

For me az webapp config set --name {WebAppName} -g {resource-group} --generic-configurations "{\"virtualApplications\":[{\"physicalPath\":\"site\\wwwroot\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/\"},{\"physicalPath\":\"site\\wwwroot\\v2\\flow-server\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/flow\"},{\"physicalPath\":\"site\\wwwroot\\v2\\iris-server\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/iris\"}]}" this did not work. It gave a bunch of error's ( powershell and bash )

az webapp config set --name {WebAppName} -g {resource-group} --generic-configurations '"{\"virtualApplications\":[{\"physicalPath\":\"site\\wwwroot\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/\"},{\"physicalPath\":\"site\\wwwroot\\v2\\flow-server\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/flow\"},{\"physicalPath\":\"site\\wwwroot\\v2\\iris-server\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/iris\"}]}"' This on the other-hand did work for me. So thank you for at-least giving me a good lead.

But it only works in Powershell-core. In bash it does not @zhoxing-ms. Can you give me an example that does work in bash when using the "az webapp config set" command ?

Below is the error that i get in Bash using the az webapp config set command

az webapp config set --name {WebAppName} -g {resource-group} --generic-configurations '"{"virtualApplications":[{"physicalPath":"site\wwwroot","preloadEnabled":false,"virtualDirectories":null,"virtualPath":"/"},{"physicalP ath":"site\wwwroot\v2\flow-server","preloadEnabled":false,"virtualDirectories":null,"virtualPath":"/flow"},{"physicalPath":"site\wwwroot\v2\iris-server","preloadEnabled":false,"virtualDirectories":null,"virtualPath":"/iris"}]}"' The command failed with an unexpected error. Here is the traceback:

dictionary update sequence element #0 has length 1; 2 is required Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 608, in execute raise ex File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 666, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 659, in _run_job six.reraise(*sys.exc_info()) File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise raise value File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 636, in _run_job result = cmd_copy(params) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 306, in call return self.handler(*args, **kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/init.py", line 493, in default_command_handler return op(**command_args) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 895, in update_site_configs result.update(get_json_object(s)) ValueError: dictionary update sequence element #0 has length 1; 2 is required

Or the error below, in this chase i removed the single quotes

az webapp config set --name {WebAppName} -g {resource-group} --generic-configurations "{"virtualApplications":[{"physicalPath":"site\wwwroot","preloadEnabled":false,"virtualDirectories":null,"virtualPath":"/"},{"physicalPath":"site\wwwroot\v2\flow-server","preloadEnabled":false,"virtualDirectories":null,"virtualPath":"/flow"},{"physicalPath":"site\wwwroot\v2\iris-server","preloadEnabled":false,"virtualDirectories":null,"virtualPath":"/iris"}]}" The command failed with an unexpected error. Here is the traceback:

not enough values to unpack (expected 2, got 1) Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/azure/cli/core/util.py", line 281, in shell_safe_json_parse return json.loads(json_or_dict_string) File "/opt/az/lib/python3.6/json/init.py", line 354, in loads return _default_decoder.decode(s) File "/opt/az/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/opt/az/lib/python3.6/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Invalid \escape: line 1 column 46 (char 45)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/azure/cli/core/util.py", line 287, in shell_safe_json_parse return ast.literal_eval(json_or_dict_string) File "/opt/az/lib/python3.6/ast.py", line 85, in literal_eval return _convert(node_or_string) File "/opt/az/lib/python3.6/ast.py", line 66, in _convert in zip(node.keys, node.values)) File "/opt/az/lib/python3.6/ast.py", line 65, in return dict((_convert(k), _convert(v)) for k, v File "/opt/az/lib/python3.6/ast.py", line 61, in _convert return list(map(_convert, node.elts)) File "/opt/az/lib/python3.6/ast.py", line 66, in _convert in zip(node.keys, node.values)) File "/opt/az/lib/python3.6/ast.py", line 65, in return dict((_convert(k), _convert(v)) for k, v File "/opt/az/lib/python3.6/ast.py", line 84, in _convert raise ValueError('malformed node or string: ' + repr(node)) ValueError: malformed node or string: <_ast.Name object at 0x7f3dccd2e358>

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 978, in update_site_configs result.update(get_json_object(s)) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/util.py", line 241, in get_json_object return _convert_to_snake_case(shell_safe_json_parse(json_string)) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/util.py", line 292, in shell_safe_json_parse raise CLIError(json_ex) # raise json_ex error which is more readable and likely. knack.util.CLIError: Invalid \escape: line 1 column 46 (char 45)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 215, in invoke cmd_result = self.invocation.execute(args) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 625, in execute raise ex File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 689, in _run_jobs_serially results.append(self._run_job(expanded_arg, cmd_copy)) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 682, in _run_job six.reraise(*sys.exc_info()) File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise raise value File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 659, in _run_job result = cmd_copy(params) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/init.py", line 324, in call return self.handler(*args, **kwargs) File "/opt/az/lib/python3.6/site-packages/azure/cli/core/init.py", line 531, in default_command_handler return op(**command_args) File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/appservice/custom.py", line 980, in update_site_configs config_name, value = s.split('=', 1) ValueError: not enough values to unpack (expected 2, got 1)

sirwarshade avatar Apr 14 '20 10:04 sirwarshade

@sirwarshade Check out this doc regarding quoting issues you're having. I'm looking at the exact same thing. Doc is going into detail and might give you insights how to handle quotes based on the type of your environment:

https://docs.microsoft.com/en-us/cli/azure/use-cli-effectively?view=azure-cli-latest#quoting-issues

The escaped example works in Powershell when using the stop-parsing symbol like so: az --% webapp config set --name {resource-name} -g {resource-group} --generic-configurations "{\"virtualApplications\":[{\"physicalPath\":\"site\\wwwroot\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/\"},{\"physicalPath\":\"site\\wwwroot\\v2\\flow-server\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/flow\"},{\"physicalPath\":\"site\\wwwroot\\v2\\iris-server\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/iris\"}]}"

eholman avatar Sep 08 '20 22:09 eholman

There are various workarounds for this as seen, however these commands only allow you to update the complete list of virtual path mappings for the app service, I cannot just add a single (or multiple) new mapping to the existing list. Is there a command to achieve this?

SteveHindmarsh avatar Aug 09 '22 09:08 SteveHindmarsh

I just want to comment that I find it very concerning that even Microsoft has put no effort into validating the very content that they publish publicly considering the number of consumers leveraging thier platform.

I refered to Microsoft documentation regarding how to add App Service Path mappings, and why not its their baby, but I couldn't get it to work correctly. I tried both the Azure cli commands resource and webApp, but Microsoft docuemntation was not correct or didn't have any real examples, so I took the time to delve into this because I too faced the same issues.

I started, as many probably did, with the Configure an App Service app-Map a URL path to a directory that instructs how to add a virtual path, and I too had the very same problems. Feedback from many regarding this open issue, 11978, spoke of escaping the quotes and even referenced the Microsoft documenmt Tips for using the Azure CLI successfully and yet this document, at least for this purpose, did not ring accuratly.

The document, Configure an App Service app-Map a URL path to a directory, had it wrong in two ways. First the Json was improperly formated, and the quotes were wrong. I break down each issue and show how to correct the issue. Note, all of the commands and Json were tested in Azure Cloudshell 2.47.0.

Let start with the formatting issue since if you correct this issue you'll then be able to see the correct way to use quotes in the Json, at least for the following Azure cli commands:

  • az resource update
  • az webapp config

The example Json provided is as listed below.

[ { "physicalPath"':' "site\wwwroot\public", "preloadEnabled"':' false, "virtualDirectories"':' null, "virtualPath"':' "/" }, { "physicalPath"':' "site\wwwroot\app2", "preloadEnabled"':' false, "virtualDirectories"':' null, "virtualPath"':' "/app2" } ]

When you create an Azure App Service you already be default have a application "/" mapped to a directory "site\wwwroot". The above Json is instructing that ANOTHER directory "site\wwwroot\public" be mapped to the application "/" which throws an exception because the virtual path needs to be unique, because we already have a mapped application "/" to directory "site\wwwroot". This Json will never work unless we change the virtual path, lets make it "/Public".

[ { "physicalPath"':' "site\wwwroot\public", "preloadEnabled"':' false, "virtualDirectories"':' null, "virtualPath"':' "/Public" }, { "physicalPath"':' "site\wwwroot\app2", "preloadEnabled"':' false, "virtualDirectories"':' null, "virtualPath"':' "/app2" } ]

Now we attempt to use the above Json with the below Azure cli command.

We now get a whole new exception:

InvalidArgumentValueError: Failed to parse string as JSON: {
Error detail: Expecting property name enclosed in double quotes

Well, this tells us everything. I then noticed that within the Json are some random single quotes, ', which were breaking the Json format.

[ { "physicalPath": "site\wwwroot\public", "preloadEnabled": false, "virtualDirectories": null, "virtualPath": "/Public" }, { "physicalPath": "site\wwwroot\app2", "preloadEnabled": false, "virtualDirectories": null, "virtualPath": "/app2" } ]

I now execute the below Azure cli resource command and it successfully created the mapped directories.

az resource update --resource-group someResourceGroup --resource-type Microsoft.Web/sites/config --name someApp/config/web --set properties.virtualApplications="[{"physicalPath": "site\wwwroot\public","preloadEnabled": false,"virtualDirectories": null,"virtualPath": "/Public"},{"physicalPath": "site\wwwroot\app2","preloadEnabled": false,"virtualDirectories": null,"virtualPath": "/app2"}]"

So I wanted to apply the Json to the Azure cli webApp command:

az webapp config set --name someApp -g someResourceGroup --generic-configurations "{"virtualApplications": [{"virtualPath": "/","physicalPath": "site\wwwroot","preloadEnabled": true,"virtualDirectories": [{"physicalPath": "site\wwwroot\public","preloadEnabled": false,"virtualDirectories": null,"virtualPath": "/Public"},{"physicalPath": "site\wwwroot\app2","preloadEnabled": false,"virtualDirectories": null,"virtualPath": "/app2"}]}]}"

I am back to the previous exception:

InvalidArgumentValueError: Failed to parse string as JSON: {
Error detail: Expecting property name enclosed in double quotes

I attempted using single quotes without success. I then moved to double double quotes, "", and that did the trick.

az webapp config set --name someApp -g someResourceGroup --generic-configurations "{""virtualApplications"": [{""virtualPath"": ""/"",""physicalPath"": ""site\wwwroot"",""preloadEnabled"": true,""virtualDirectories"": [{""physicalPath"": ""site\wwwroot\public"",""preloadEnabled"": false,""virtualDirectories"": null,""virtualPath"": ""/Public""},{""physicalPath"": ""site\wwwroot\app2"",""preloadEnabled"": false,""virtualDirectories"": null,""virtualPath"": ""/app2""}]}]}"

So, for some reason the Azure cli resource & webApp are not consistent how it handles the Json quotes. The Microsoft Azure cli team should work together to figure out why there is a difference with how quotes are managed between the two command groups. Please feel free to validate my findings.

I do want to mention that I changed the structure of the Json because I needed to map another mapped application as displayed below.

{ ""virtualApplications"": [ { ""virtualPath"": ""/"", ""physicalPath"": ""site\wwwroot"", ""preloadEnabled"": true, ""virtualDirectories"": [ { ""virtualPath"": ""/Public"", ""physicalPath"": ""site\wwwroot\public"" } ] }, { ""virtualPath"": ""/app2"", ""physicalPath"": ""site\wwwroot\app2"", ""preloadEnabled"": true } ] }

HaloX69 avatar Apr 18 '23 17:04 HaloX69

My 2 cents here, I have been able to make it work in bash creating a json file and using it with azure client:

echo "{\"virtualApplications\":[{\"physicalPath\":\"site\\\\wwwroot\",\"preloadEnabled\":false,\"virtualDirectories\":null,\"virtualPath\":\"/\"},{\"physicalPath\":\"site\\\\wwwroot\\\\someApp\",\"preloadEnabled\": false,\"virtualDirectories\": null,\"virtualPath\": \"/blueprints\"}]}" > json.txt

az webapp config set --resource-group someResourceGroup --name someApp --generic-configurations "@json.txt"

jorferri avatar Feb 02 '24 09:02 jorferri