-
Notifications
You must be signed in to change notification settings - Fork 8
fix: ensure single space before TYPE, ROLE, and correctly format those values #65
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
Conversation
Reviewer's GuideFixes whitespace and value formatting for TYPE, ROLE, and Solaris privilege entries in the sudoers Jinja template by enforcing single-string output and adjusts associated tests to validate these changes. Class diagram for spec data structure changes in sudoers templateclassDiagram
class spec {
operators : list[string]
selinux_type : string | list[string]
selinux_role : string | list[string]
solaris_privs : list[string]
solaris_limitprivs : list[string]
tags : list[string]
}
%% Note: The handling of selinux_type and selinux_role now ensures single string output in the template, even if the input is a list.
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @richm - I've reviewed your changes - here's some feedback:
- Consider using the built-in Jinja2
firstfilter (e.g.{{ spec.selinux_type | first }}) instead of manually indexing into the list. - The mix of
{%-and{%for whitespace control in your Jinja tags is inconsistent—standardize on one style for readability. - Double-check that removing the space in
join(",")for solaris_privs/limitprivs still aligns with the expected sudoers file formatting conventions.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider using the built-in Jinja2 `first` filter (e.g. `{{ spec.selinux_type | first }}`) instead of manually indexing into the list.
- The mix of `{%-` and `{%` for whitespace control in your Jinja tags is inconsistent—standardize on one style for readability.
- Double-check that removing the space in `join(",")` for solaris_privs/limitprivs still aligns with the expected sudoers file formatting conventions.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #65 +/- ##
=======================================
Coverage ? 52.31%
=======================================
Files ? 1
Lines ? 346
Branches ? 0
=======================================
Hits ? 181
Misses ? 165
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
[citest] |
|
Fixes #64 |
martinpitt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for fixing this! @kraker validated this in #64 (comment)
| {%- if spec.selinux_type is defined and spec.selinux_type | length > 0 -%} | ||
| TYPE={{ spec.selinux_type | join(", ") }} | ||
| {%- if spec.selinux_type is defined and spec.selinux_type | length > 0 %} | ||
| TYPE={{ spec.selinux_type if spec.selinux_type is string else spec.selinux_type[0] }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird that we entirely ignore all but the first list entries -- I suppose this should have been a single value all along? But that's water under the bridge now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird that we entirely ignore all but the first list entries -- I suppose this should have been a single value all along?
That's what I understand according to https://www.sudo.ws/docs/man/1.8.15/sudoers.man/#Quick_guide_to_EBNF - it should have been a single value all along - perhaps @radosroka can confirm.
…e values Cause: The recent refactoring for Ansible 2.19 altered the whitespacing before the TYPE and ROLE values. In addition, the TYPE and ROLE values are a single string, not a comma delimited list. We did not have any tests for these values, so we did not catch the error in the refactoring. Consequence: The role would incorrectly format the TYPE and ROLE values. Fix: Use correct Jinja formatting for the TYPE and ROLE values, and the solaris values. Ensure that the TYPE and ROLE values will be a single string. Result: The sudoers file is correctly formatted. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
|
[citest] |
|
also note that we cannot actually test the solaris options because 1) linux |
Cause: The recent refactoring for Ansible 2.19 altered the whitespacing before
the TYPE and ROLE values. In addition, the TYPE and ROLE values are a single
string, not a comma delimited list. We did not have any tests for these
values, so we did not catch the error in the refactoring.
Consequence: The role would incorrectly format the TYPE and ROLE values.
Fix: Use correct Jinja formatting for the TYPE and ROLE values, and the
solaris values. Ensure that the TYPE and ROLE values will be a single string.
Result: The sudoers file is correctly formatted.
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Fix whitespace and value formatting in the sudoers Jinja template for TYPE, ROLE, PRIVS, and LIMITPRIVS; add tests to cover selinux_type and selinux_role and refresh fixtures.
Bug Fixes:
Tests: