在查询Jmespath上实现条件
我有这个查询,这给我带来了KeyVault秘密的到期日期,我必须带来少于30天的
az keyvault secret show \
--vault name "$keyvault" \
--name "$secret" \
--query "attributes.expires" - o tsv
日期
--query "attributes.expires < 30 days" - o tsv
I have this query which bring me the expiring dates of the keyvault's secret, I have to bring the dates that are less than 30 days
az keyvault secret show \
--vault name "$keyvault" \
--name "$secret" \
--query "attributes.expires" - o tsv
How can I implement something like
--query "attributes.expires < 30 days" - o tsv
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您将无法在JMespath中进行日期计算,但是您可以完美地让PowerShell这样做,并使用
get-date
实用程序。对于Jmespath查询部分,您必须知道只能将过滤器应用于数组,而不是对象,这是您似乎拥有的。
但是,您可以使用函数
to_array
在您的对象上,然后使用 pipe Expression 仅获取数组的第一项 -| [0]
。因此,如果Azure客户端未过滤的JSON返回看起来像是
您的查询
You won't be able to make the date computation in JMESPath, but you could perfectly let PowerShell do it, with the
Get-Date
utility.For the JMESPath query part, you have to know that a filter can only be applied to an array, not to an object, which is what you seems to have.
You can overcome this, though, using the function
to_array
on your object, and, then, use a pipe expression to get only the first item of the array –| [0]
.So, if the unfiltered JSON return of the Azure client looks like
Then, this should be your query