简体   繁体   中英

How to clear settings using azure cli and rest command?

I want to remove settings from keyVaultReferenceIdentity

az rest --method PATCH --uri "${resourceId}?api-version=2021-01-01" --body "{""properties"":{""keyVaultReferenceIdentity"":null}}" --query properties.keyVaultReferenceIdentity -o json

But for this I have

Unsupported Media Type({"error":{"code":"UnsupportedMediaType","message":"The content media type '' is not supported. Only 'application/json' is supported."}})

If I add headers:

$headers = @{"Content-Type" = "application/json" }


az rest --method PATCH --Headers $headers --uri "${resourceId}?api-version=2021-01-01" --body "{""properties"":{""keyVaultReferenceIdentity"":null}}" --query properties.keyVaultReferenceIdentity -o json

then:

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 "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 506, in shell_safe_json_parse File "json_ init _.py", line 370, in loads File "json\decoder.py", line 337, in decode File "json\decoder.py", line 355, in raw_decode json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 815, in send_raw_request File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py", line 531, in shell_safe_json_parse azure.cli.core.azclierror.InvalidArgumentValueError: Failed to parse JSON: System.Collections.Hashtable Error detail: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py", line 231, in invoke File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/ init .py", line 657, in execute File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/ init .py", line 720, in _run_jobs_serially File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/ init .py", line 691, in _run_job File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/ init .py", line 328, in call File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py", line 121, in handler File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/util/custom.py", line 16, in rest_call File "D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cl i/core/util.py", line 818, in send_raw_request ValueError: not enough values to unpack (expected 2, got 1)

Idea is to clear keyVaultReferenceIdentity however I can find valid syntax and parameters combination.

I found this issue on GH but it didn't help.

I did a repro with your CLI command and modified according to correct format and fixed, below is the CLI command where we can execute it without getting any errors.

az rest --method patch --headers "{'Content-Type': 'application/json'}" --uri /subscriptions/SUBSCRIPTION_ID/resourceGroups/RESOURCE_GROUP_NAME/providers/Microsoft.Web/sites/CheckingLogs0805?api-version=2015-08-01 --body "{'properties': {'siteConfig': {'keyVaultReferenceIdentity':null}}}" --query properties.keyVaultReferenceIdentity -o json

So, above command will fix the error messages which you have shown (ie, UnsupportedMediaType and JSONDecodeError

Now coming to the question to clear the value of 'keyVaultReferenceIdentity'. This usually sets by default while creation as SystemAssigned. These values are taken from Managed Identities.

Please check the documentation for the values System Identity and Managed Identity.

From the command which I have fixed, we can change the value of any other parameter.

Refer to screenshot as I have changed value of 'properties': {"enabled": true}

本地截图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM