AWS CLI - 一行和第二级JSON的单行上的输出文本

发布于 2025-02-10 03:45:22 字数 1398 浏览 1 评论 0 原文

我正在尝试从AWS证书管理器中获得其域名,有效数据,验证状态和验证方法的证书列表(例如100),并使用AWS CLI命令 AWS ACM DICESS ACM DICECT-CREDICETIFICATE

我尝试了嵌套过滤和 - ouput Text ,但输出在两行上。我想原因是验证status和validationMethod在JSON OUPUT中是第二级,仅次于证书/域名。

如何将文本ouput插入一行?

例如

foo.bar.com    2022-06-18T23:59:59+00:00 FAILED  DNS 

这是 - 输出文本

$ aws acm describe-certificate --certificate-arn arn:aws:acm:region:aws-account_id:certificate/xxxx  --query Certificate.[DomainName,NotAfter,DomainValidationOptions[].[ValidationStatus,ValidationMethod]] --output text
foo.bar.com    2022-06-18T23:59:59+00:00
FAILED  DNS

这是 - - 输出JSON (默认输出)

 aws acm describe-certificate --certificate-arn arn:aws:acm:region:aws-account_id:certificate/xxxx  --query Certificate.[DomainName,NotAfter,DomainValidationOptions[].[ValidationStatus,ValidationMethod]]
[
    "foo.bar.com",
    2022-06-18T23:59:59+00:00,
    [
        [
            "FAILED",
            "DNS"
        ]
    ]
]

I am trying to get a list of certificates (let's say 100) from AWS Certificates Manager with their Domain Name, Expiry Data, Validation Status and Validation Method with the aws cli command aws acm describe-certificate.

I tried nesting filtering and --ouput text but the output is on two lines. I guess the reason is that ValidationStatus and ValidationMethod are second level in the json ouput after Certificate/DomainValidationOptions.

How would it be possible to get the text ouput in a single line?

Like

foo.bar.com    2022-06-18T23:59:59+00:00 FAILED  DNS 

https://awscli.amazonaws.com/v2/documentation/api/latest/reference/acm/describe-certificate.html

This is the --output text

$ aws acm describe-certificate --certificate-arn arn:aws:acm:region:aws-account_id:certificate/xxxx  --query Certificate.[DomainName,NotAfter,DomainValidationOptions[].[ValidationStatus,ValidationMethod]] --output text
foo.bar.com    2022-06-18T23:59:59+00:00
FAILED  DNS

This is the --output json (default output)

 aws acm describe-certificate --certificate-arn arn:aws:acm:region:aws-account_id:certificate/xxxx  --query Certificate.[DomainName,NotAfter,DomainValidationOptions[].[ValidationStatus,ValidationMethod]]
[
    "foo.bar.com",
    2022-06-18T23:59:59+00:00,
    [
        [
            "FAILED",
            "DNS"
        ]
    ]
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

记忆で 2025-02-17 03:45:22

实现此目标的一种方法是在Jmespath 平坦的操作员 - [] - 在您的查询中。

有这样的查询:

Certificate.[
  DomainName,
  NotAfter,
  DomainValidationOptions[].[ValidationStatus, ValidationMethod]
][][]

将为您提供一个域,一个域,JSON输出

[
  "www.example.com",
  "2022-06-18T23:59:59+00:00",
  "FAILED",
  "DNS"
]

并最终进入一行。


现在,请注意,如果您在 domainvalidationOptions 数组中有多个项目,那么它们将在同一行上所有输出,因为您将拥有一个数组。

两个域的示例:

[
  "www.example.com",
  "2022-06-18T23:59:59+00:00",
  "FAILED",
  "DNS",
  "FAILED",
  "DNS"
]

请参阅DNS和验证status verialationMethod 重复那里的两个域?

您可能想做的是从域中查询 domainname ,至少至少:

Certificate.[
  NotAfter,
  DomainValidationOptions[].[DomainName, ValidationStatus, ValidationMethod]
][][]

它仍然在一条线上,但会为您提供与验证相关的域:

[
  "2022-06-18T23:59:59+00:00",
  "www.example.com",
  "FAILED",
  "DNS",
  "www.example.net",
  "FAILED",
  "DNS"
]

A way to achieve this is to flatten the array you are receiving from the AWS command, with the help of the JMESPath flatten operator — [] — in your query.

Having a query like this:

Certificate.[
  DomainName,
  NotAfter,
  DomainValidationOptions[].[ValidationStatus, ValidationMethod]
][][]

Would give you, with one domain the JSON output

[
  "www.example.com",
  "2022-06-18T23:59:59+00:00",
  "FAILED",
  "DNS"
]

And end up on one line.


Now mind that, if you have more than one item in the DomainValidationOptions array, they will, then, all output on the same line, because you'll have one array with everything.

Example for two domains:

[
  "www.example.com",
  "2022-06-18T23:59:59+00:00",
  "FAILED",
  "DNS",
  "FAILED",
  "DNS"
]

See the DNS and ValidationStatus and ValidationMethod repeating for the two domains there?

What you might want to do, is to query the DomainName from the DomainValidationOptions, at least:

Certificate.[
  NotAfter,
  DomainValidationOptions[].[DomainName, ValidationStatus, ValidationMethod]
][][]

Which would still be on one line, but will get you the domain related to the validation:

[
  "2022-06-18T23:59:59+00:00",
  "www.example.com",
  "FAILED",
  "DNS",
  "www.example.net",
  "FAILED",
  "DNS"
]
走走停停 2025-02-17 03:45:22

使用约翰的建议取得了一些进展。
通过使用“ Inuseby [0]”和“ Inuseby”,我设法在第一行中输出“ Inuseby”;否则将在第二行。

还使用“ domainvalidationOptions [0] .ValidationStatus”而不是“ domainvalidationOptions.ValidationStatus”将其输出在第二行而不是第3行上。

尽管如此,我还是希望

"RenewalSummary.[RenewalStatus,DomainValidationOptions[0].ValidationStatus]"

也要在第一行上输出。我注意到续订是一个对象,{},而不是数组,[]。

  "RenewalSummary": {
            "RenewalStatus": "PENDING_VALIDATION",
            "DomainValidationOptions": [
                {
                    "DomainName": "foo.bar.com",
                    "ValidationDomain": "foo.bar.com",
                    "ValidationStatus": "PENDING_VALIDATION",
                    "ResourceRecord": {
                        "Name": "_9d77eed0XXX66.foo.bar.com.",
                        "Type": "CNAME",
                        "Value": "_a5XXXX3.tgztlnjmjp.acm-validations.aws."
                    },
                    "ValidationMethod": "DNS"
                }
            ],
            "UpdatedAt": "2022-06-24T11:16:34.617000+00:00"
        },

aws acm describe-certificate --certificate-arn arn:aws:acm:region:aws-account_id:certificate/xxxx --query Certificate.[DomainName,Issuer,Status,FailureReason,NotAfter,InUseBy[0],RenewalSummary.[RenewalStatus,DomainValidationOptions[0].ValidationStatus]] --output text

这就是输出的外观:

foo.bar.com  Amazon  ISSUED  None    2022-06-18T23:59:59+00:00       arn:aws:elasticloadbalancing:eu-west-1:aws_account_id:loadbalancer/app/alb_foo_bar/XXX
PENDING_VALIDATION      PENDING_VALIDATION

Some progress was made using John's suggestion.
By using "InUseBy[0]" and not only "InUseBy", I managed to output the "InUseBy" on the first line; otherwise it would be on the second line.

Also using "DomainValidationOptions[0].ValidationStatus" instead of "DomainValidationOptions.ValidationStatus" outputs this on the 2nd line instead of 3rd.

Still, I would like

"RenewalSummary.[RenewalStatus,DomainValidationOptions[0].ValidationStatus]"

to be output on the first line too. I noticed RenewalSummary is an object ,{}, not an array, [].

  "RenewalSummary": {
            "RenewalStatus": "PENDING_VALIDATION",
            "DomainValidationOptions": [
                {
                    "DomainName": "foo.bar.com",
                    "ValidationDomain": "foo.bar.com",
                    "ValidationStatus": "PENDING_VALIDATION",
                    "ResourceRecord": {
                        "Name": "_9d77eed0XXX66.foo.bar.com.",
                        "Type": "CNAME",
                        "Value": "_a5XXXX3.tgztlnjmjp.acm-validations.aws."
                    },
                    "ValidationMethod": "DNS"
                }
            ],
            "UpdatedAt": "2022-06-24T11:16:34.617000+00:00"
        },

aws acm describe-certificate --certificate-arn arn:aws:acm:region:aws-account_id:certificate/xxxx --query Certificate.[DomainName,Issuer,Status,FailureReason,NotAfter,InUseBy[0],RenewalSummary.[RenewalStatus,DomainValidationOptions[0].ValidationStatus]] --output text

This is how the output looks now:

foo.bar.com  Amazon  ISSUED  None    2022-06-18T23:59:59+00:00       arn:aws:elasticloadbalancing:eu-west-1:aws_account_id:loadbalancer/app/alb_foo_bar/XXX
PENDING_VALIDATION      PENDING_VALIDATION
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文