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

feature: Documentation command #1009

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

xNok
Copy link

@xNok xNok commented Sep 30, 2024

I found myself wanting to generate reference documentation for my policies, and I figured it would be nice if this was a built-in feature of conftest.

While the way of structuring the documentation can be opinionated, I think using the FlatAnnotationsRefSet is a safe bet, as OPA's core does all the heavy lifting of organizing annotations and rules.

My initial attempt was to combine FlatAnnotationsRefSet and Go-template and offer the least opinionated approach to documentation format that can be easily overridden. However, I had some trouble properly formatting titles (H1, H2, H3, etc...) and had to introduce some custom logic to handle it. (As a side note this could potentially be handles by adding template function libraries such as sprig)

Copy link
Member

@boranx boranx left a comment

Choose a reason for hiding this comment

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

hey @xNok

Thanks for bringing this together, I actually very liked the idea of using go templates and embedding both so if the user has their own, overriding it to balance flexibility with functionality.
This can help us collectively gather feedback on how users actually use it and refactor to get it closer to the user needs.
+1 from me on implementation.
Just left some comments at first glance, will look at more.

document/template.go Outdated Show resolved Hide resolved
document/metadata.go Show resolved Hide resolved
document/metadata.go Show resolved Hide resolved
document/metadata_test.go Outdated Show resolved Hide resolved
internal/commands/document.go Outdated Show resolved Hide resolved
@xNok xNok force-pushed the documentation-command branch 2 times, most recently from 834216c to e2cdeed Compare October 9, 2024 11:39
xNok and others added 7 commits October 9, 2024 12:44
Signed-off-by: Alexandre Couedelo <[email protected]>

refactor: change the way we access annotations

I am testing different way to generate the doc. Having the compiler object is much easier than the annotation set only

Signed-off-by: Alexandre Couedelo <[email protected]>
Signed-off-by: Alexandre Couedelo <[email protected]>
Signed-off-by: Alexandre Couedelo <[email protected]>

fix: make title coherent in submodules documentation

Signed-off-by: Alexandre Couedelo <[email protected]>
Signed-off-by: Alexandre Couedelo <[email protected]>

chore: ignore golden files in git

Signed-off-by: Alexandre Couedelo <[email protected]>

chore: document and test the custom template feature

Signed-off-by: Alexandre Couedelo <[email protected]>

chore: linting

Signed-off-by: Alexandre Couedelo <[email protected]>
…9.0 (open-policy-agent#1010)

Bumps [github.com/open-policy-agent/opa](https://github.com/open-policy-agent/opa) from 0.68.0 to 0.69.0.
- [Release notes](https://github.com/open-policy-agent/opa/releases)
- [Changelog](https://github.com/open-policy-agent/opa/blob/main/CHANGELOG.md)
- [Commits](open-policy-agent/opa@v0.68.0...v0.69.0)

---
updated-dependencies:
- dependency-name: github.com/open-policy-agent/opa
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Alexandre Couedelo <[email protected]>
build(deps): bump github.com/open-policy-agent/opa from 0.68.0 to 0.69.0 (open-policy-agent#1010)

Bumps [github.com/open-policy-agent/opa](https://github.com/open-policy-agent/opa) from 0.68.0 to 0.69.0.
- [Release notes](https://github.com/open-policy-agent/opa/releases)
- [Changelog](https://github.com/open-policy-agent/opa/blob/main/CHANGELOG.md)
- [Commits](open-policy-agent/opa@v0.68.0...v0.69.0)

---
updated-dependencies:
- dependency-name: github.com/open-policy-agent/opa
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Alexandre Couedelo <[email protected]>

chore: go mod tidy
document/metadata.go Outdated Show resolved Hide resolved
document/metadata.go Outdated Show resolved Hide resolved
document/metadata.go Outdated Show resolved Hide resolved
document/metadata_test.go Outdated Show resolved Hide resolved
document/template.go Outdated Show resolved Hide resolved
Signed-off-by: Alexandre Couedelo <[email protected]>
Copy link
Member

@jalseth jalseth 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 PR! It is very thorough and including documentation on how to use the feature is much appreciated.

document/template.go Outdated Show resolved Hide resolved
document/template.go Outdated Show resolved Hide resolved
document/template.go Outdated Show resolved Hide resolved
document/template.go Outdated Show resolved Hide resolved
document/template_test.go Outdated Show resolved Hide resolved
document/metadata_test.go Outdated Show resolved Hide resolved
document/metadata_test.go Show resolved Hide resolved
document/metadata_test.go Outdated Show resolved Hide resolved
document/metadata_test.go Outdated Show resolved Hide resolved
document/metadata_test.go Outdated Show resolved Hide resolved
jalseth

Signed-off-by: Alexandre Couedelo <[email protected]>
Signed-off-by: Alexandre Couedelo <[email protected]>
@xNok
Copy link
Author

xNok commented Oct 24, 2024

@jalseth, I have addressed your comment. It seems there is a broken test, and it fails on master and my last heavy_check_mark: revision. I have no clue what could be causing it to fail.

image

image

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.

3 participants