如何使用Azure CLI az rest命令清除keyVaultReferenceIdentity配置并解决报错
解决方案
错误原因
- 首次执行报错是未指定请求的Content-Type,Azure资源管理API要求PATCH请求的媒体类型必须为
application/json - 第二次报错是因为PowerShell格式的哈希表无法直接作为参数传递给Azure CLI,Azure CLI无法解析该格式导致参数拆解失败
正确执行命令
推荐使用Azure CLI内置--content-type参数的写法,无需手动构造请求头,语法更简洁:
az rest --method PATCH ` --uri "${resourceId}?api-version=2021-01-01" ` --content-type "application/json" ` --body '{"properties":{"keyVaultReferenceIdentity":null}}' ` --query properties.keyVaultReferenceIdentity ` -o json
如果需要自定义请求头,需将头信息转换为JSON格式的字符串再传递给--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
结果验证
命令执行成功后返回值为null,即代表keyVaultReferenceIdentity配置已被成功清除。
内容的提问来源于stack exchange,提问作者Krzysztof Madej
相关产品推荐
相关产品推荐

