首页 > 解决方案 > 如何使用 azure cli 和 rest 命令清除设置?

问题描述

我想删除设置keyVaultReferenceIdentity

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

但为此我有

不支持的媒体类型({"error":{"code":"UnsupportedMediaType","message":"不支持内容媒体类型''。仅支持'application/json'。"}})

如果我添加标题:

$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

然后:

该命令因意外错误而失败。这是回溯:没有足够的值来解包(预期 2,得到 1)回溯(最近一次调用最后):文件“D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\ azure/cli/core/util.py”,第 506 行,shell_safe_json_parse 文件“json_init _.py ”,第 370 行,加载文件“json\decoder.py”,第 337 行,解码文件“json\decoder. py",第 355 行,在 raw_decode json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)

上述异常是以下异常的直接原因:

回溯(最后一次调用):文件“D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py”,第 815 行,在 send_raw_request 文件中“D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/util.py”,第 531 行,在 shell_safe_json_parse azure.cli.core.azclierror.InvalidArgumentValueError 中:无法解析 JSON:System.Collections.Hashtable 错误详细信息:预期值:第 1 行第 1 列(字符 0)

在处理上述异常的过程中,又出现了一个异常:

回溯(最近一次调用):文件“D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/cli.py”,第 231 行,在调用文件“D:\ a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/ init .py”,第 657 行,在执行文件“D:\a\1\s\build_scripts \windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/ init .py”,第 720 行,在 _run_jobs_serially 文件“D:\a\1\s\build_scripts\windows\artifacts\cli\ Lib\site-packages\azure/cli/core/commands/ init .py”,第 691 行,在 _run_job 文件“D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure /cli/core/commands/ init .py”,第 328 行,调用中 文件“D:\a\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/commands/command_operation.py”,第 121 行,在处理程序文件“D:\a\ 1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/command_modules/util/custom.py”,第 16 行,在 rest_call 文件“D:\a\1\s\build_scripts\windows \artifacts\cli\Lib\site-packages\azure/cli/core/util.py",第 818 行,在 send_raw_request ValueError 中:没有足够的值来解包(预期 2,得到 1)

想法是明确的,keyVaultReferenceIdentity但是我可以找到有效的语法和参数组合。

我在 GH 上发现了这个问题,但没有帮助。

标签: pythonazureazure-cli

解决方案


我使用您的 CLI 命令进行了复制,并根据正确的格式进行了修改并修复,下面是 CLI 命令,我们可以在其中执行它而不会出现任何错误。

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

因此,上面的命令将修复您显示的错误消息(即 UnsupportedMediaType 和 JSONDecodeError

现在来解决“keyVaultReferenceIdentity”的值的问题。这通常在创建时默认设置为 SystemAssigned。这些值取自托管标识。

请检查文档以获取 System Identity 和 Managed Identity 的值。

从我修复的命令中,我们可以更改任何其他参数的值。

请参阅屏幕截图,因为我更改了“属性”的值:{“启用”:真}

本地截图


推荐阅读