Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create options for human-readable output formats #437

Merged
merged 27 commits into from
Jul 20, 2020
Merged

Conversation

acaird
Copy link
Contributor

@acaird acaird commented May 25, 2020

Added a -summary and -longsummary options to zlint.

The -summary option produces output that looks like:

+-------+--------------+
| LEVEL | # OCCURANCES |
+-------+--------------+
| info  |            0 |
| warn  |            1 |
| error |            7 |
| fatal |            0 |
+-------+--------------+

and the -longsummary produces output that looks like:

+-------+--------------+------------------------------------------+
| LEVEL | # OCCURANCES |                 DETAILS                  |
+-------+--------------+------------------------------------------+
| info  |            0 |  -                                       |
| warn  |            1 | w_ext_san_critical_with_subject_dn       |
| error |            7 | e_cert_policy_iv_requires_country        |
|       |              | e_ca_key_cert_sign_not_set               |
|       |              | e_ca_organization_name_missing           |
|       |              | e_ca_crl_sign_not_set                    |
|       |              | e_ca_country_name_missing                |
|       |              | e_sub_ca_crl_distribution_points_missing |
|       |              | e_sub_cert_not_is_ca                     |
| fatal |            0 |  -                                       |
+-------+--------------+------------------------------------------+

The only significant changes to zlint was to export statusLabelToLintStatus from result.go and to pull in tablewriter.

Thanks for considering these changes.

acaird added 2 commits May 25, 2020 11:26
Linting the test file `testdata/utf8ControlX88.pem` results in:
```
+-------+--------------+
| LEVEL | # OCCURANCES |
+-------+--------------+
| info  |            0 |
| warn  |            7 |
| error |           15 |
| fatal |            0 |
+-------+--------------+
```
Running:
```sh
testdata/indivValAllBad.pem | ./zlint -longsummary
```
the output is:
```
+-------+--------------+------------------------------------------+
| LEVEL | # OCCURANCES |                 DETAILS                  |
+-------+--------------+------------------------------------------+
| info  |            0 |  -                                       |
| warn  |            1 | w_ext_san_critical_with_subject_dn       |
| error |            7 | e_ca_crl_sign_not_set                    |
|       |              | e_sub_ca_crl_distribution_points_missing |
|       |              | e_ca_country_name_missing                |
|       |              | e_cert_policy_iv_requires_country        |
|       |              | e_sub_cert_not_is_ca                     |
|       |              | e_ca_key_cert_sign_not_set               |
|       |              | e_ca_organization_name_missing           |
| fatal |            0 |  -                                       |
+-------+--------------+------------------------------------------+
```
@cardonator
Copy link
Contributor

Wow, this is awesome. Seriously. Thanks for contributing that. I have been wanting something like this for a while but haven't had any time to work on it.

Copy link
Member

@zakird zakird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@zakird
Copy link
Member

zakird commented May 25, 2020

I've committed additional changes to this PR, so tagging @cpu or @dadrian to take a final pass and merge.

Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @acaird,

Thanks for the PR! I only had a few minutes this morning and haven't had a chance to do a very thorough review. I did have a few comments worth sharing up front.

v2/cmd/zlint/main.go Outdated Show resolved Hide resolved
v2/go.mod Outdated Show resolved Hide resolved
@acaird
Copy link
Contributor Author

acaird commented May 28, 2020

I'm not entirely convinced that removing the tablewriter dependency is worth it, but the new output looks like:

cat testdata/indivValAllBad.pem | ./zlint -summary
| LEVEL | # OCCURRENCES |
+-------+---------------+
|  info |             0 |
|  warn |             1 |
| error |             7 |
| fatal |             0 |

and

cat testdata/indivValAllBad.pem | ./zlint -longsummary
| LEVEL | # OCCURRENCES |                  DETAILS                  |
+-------+---------------+-------------------------------------------+
|  info |             0 |                                        -  |
|  warn |             1 |        w_ext_san_critical_with_subject_dn |
| error |             7 |                      e_sub_cert_not_is_ca |
|       |               |                e_ca_key_cert_sign_not_set |
|       |               |  e_sub_ca_crl_distribution_points_missing |
|       |               |                     e_ca_crl_sign_not_set |
|       |               |                 e_ca_country_name_missing |
|       |               |         e_cert_policy_iv_requires_country |
|       |               |            e_ca_organization_name_missing |
| fatal |             0 |                                        -  |

@acaird
Copy link
Contributor Author

acaird commented May 28, 2020

Tests and some consideration of moving the filtering elsewhere will come later.

Thanks for all the feedback!

Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the iteration on this @acaird! I really appreciate that you were able to rework the table code without the new dependency.

I left some review feedback in this round with some suggestions to refactor the outputSummary func into smaller pieces. If you can handle that & take a crack at some test coverage I think we'll be in a good place to merge. I won't block this PR on trying to consolidate some of the filtering logic back into the ResultSet type, we track that as a follow-up or a nice to have.

Thanks!

v2/cmd/zlint/main.go Outdated Show resolved Hide resolved
v2/cmd/zlint/main.go Outdated Show resolved Hide resolved
v2/cmd/zlint/main.go Outdated Show resolved Hide resolved
v2/cmd/zlint/main.go Outdated Show resolved Hide resolved
v2/cmd/zlint/main.go Outdated Show resolved Hide resolved
@cpu cpu self-assigned this May 31, 2020
@acaird
Copy link
Contributor Author

acaird commented Jun 2, 2020

@cpu thanks for the feedback, I'll clean it up and write some tests, hopefully I'll get to it all within the next week or so

@cpu
Copy link
Member

cpu commented Jun 25, 2020

👋 @acaird just wanted to check in on this branch. Do you feel like you'll have a chance to address the last bits of feedback in the next few weeks? If you think you might not have the time I definitely understand and would be happy to adopt this PR to get it across the line. Let me know what you would prefer!

@acaird
Copy link
Contributor Author

acaird commented Jun 26, 2020

👋 @cpu. I haven't given up yet! If I can't get something worthwhile by Tuesday I'll put it up for adoption. Sorry for the delays... :/

@cpu
Copy link
Member

cpu commented Jun 26, 2020

If I can't get something worthwhile by Tuesday I'll put it up for adoption. Sorry for the delays... :/

Please don't apologize, take your time :-) I just want to make sure my feedback isn't the only thing keeping this from landed in tree. Thanks for the update!

acaird and others added 3 commits June 28, 2020 15:32
author Andrew Caird <acaird@gmail.com> 1590420366 -0400
committer Andrew Caird <acaird@gmail.com> 1593372751 -0400

Add a -summary option to print a short summary of the linting

Linting the test file `testdata/utf8ControlX88.pem` results in:
```
+-------+--------------+
| LEVEL | # OCCURANCES |
+-------+--------------+
| info  |            0 |
| warn  |            7 |
| error |           15 |
| fatal |            0 |
+-------+--------------+
```

and a  -longSummary option and output

Running:
```sh
testdata/indivValAllBad.pem | ./zlint -longsummary
```
the output is:
```
+-------+--------------+------------------------------------------+
| LEVEL | # OCCURANCES |                 DETAILS                  |
+-------+--------------+------------------------------------------+
| info  |            0 |  -                                       |
| warn  |            1 | w_ext_san_critical_with_subject_dn       |
| error |            7 | e_ca_crl_sign_not_set                    |
|       |              | e_sub_ca_crl_distribution_points_missing |
|       |              | e_ca_country_name_missing                |
|       |              | e_cert_policy_iv_requires_country        |
|       |              | e_sub_cert_not_is_ca                     |
|       |              | e_ca_key_cert_sign_not_set               |
|       |              | e_ca_organization_name_missing           |
| fatal |            0 |  -                                       |
+-------+--------------+------------------------------------------+
```
Co-authored-by: tld-update-bot <cpu+tldbot@letsencrypt.org>
Co-authored-by: tld-update-bot <cpu+tldbot@letsencrypt.org>
@acaird
Copy link
Contributor Author

acaird commented Jun 30, 2020

Writing tests in main is not ideal; I can keep working on it or I can split the functions and their requirements into a file that isn't main and test that. Thoughts?

@cpu
Copy link
Member

cpu commented Jul 2, 2020

I can split the functions and their requirements into a file that isn't main and test that. Thoughts?

@acaird Splitting would be my pref. but it's lightly held. If you find it easier to keep working through main that's OK with me. I don't want to hold you up :-)

v2/formattedoutput/formattedOutput.go Outdated Show resolved Hide resolved
v2/formattedoutput/formattedOutput.go Outdated Show resolved Hide resolved
v2/cmd/zlint/main.go Outdated Show resolved Hide resolved
Copy link
Member

@cpu cpu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With three other +1 reviews I don't want to hold this useful addition to zlint up any longer on my request for unit tests. I think there's room for flexibility here, especially given it isn't adding or changing any linting logic so i'll go ahead and stamp + merge.

@acaird If you've already started on tests a follow-up PR to add what you have would be great. Thanks!

@zakird zakird merged commit ca9532d into zmap:master Jul 20, 2020
@cpu
Copy link
Member

cpu commented Jul 20, 2020

@zakird Thanks for merging, was just typing out a squash commit message.

@zakird
Copy link
Member

zakird commented Jul 20, 2020

oh 🤦 sorry about that!

@cpu
Copy link
Member

cpu commented Jul 20, 2020

No worries :-) Happy it's all merged up 🎉

@acaird
Copy link
Contributor Author

acaird commented Jul 23, 2020

Thanks for merging it. I'm glad it's useful. I'm sorry about the tests, they are still forthcoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants