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

feat: CPLYTM-389 add cac content rules transformation #411

Merged
merged 4 commits into from
Jan 15, 2025

Conversation

qduanmu
Copy link
Contributor

@qduanmu qduanmu commented Jan 13, 2025

Description

Fixes CPLYTM-389

Type of change

  • New feature (non-breaking change which adds functionality)

How has this been tested?

  • Test A
  • Test B

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@qduanmu qduanmu changed the title feat: add cac content rules transformation feat: CPLYTM-389 add cac content rules transformation Jan 13, 2025
Copy link
Contributor

@huiwangredhat huiwangredhat left a comment

Choose a reason for hiding this comment

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

Generally LGTM. I think we should wait for the fixing of line163 in cac_transformer.py and do the test, then merge it.

@qduanmu qduanmu force-pushed the cac-rule-transform branch 2 times, most recently from d04094c to 1381bf7 Compare January 14, 2025 09:39
@qduanmu qduanmu force-pushed the cac-rule-transform branch from 1381bf7 to caaa44d Compare January 14, 2025 09:45
@qduanmu
Copy link
Contributor Author

qduanmu commented Jan 14, 2025

Generally LGTM. I think we should wait for the fixing of line163 in cac_transformer.py and do the test, then merge it.

The function could work as expected actually, and it has been verified(testing result) by manually setting the jinja macros directory which raised the error, once the ComplianceAsCode/content#12816 is merged, just uncomment the function is enough.

Copy link
Contributor

@jpower432 jpower432 left a comment

Choose a reason for hiding this comment

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

LGTM. I added a few comments to show where the trestle SDK could be used more, but they are nitpicks.

compdef.metadata.version = str(
"{:.1f}".format(float(compdef.metadata.version) + 0.1)
)
compdef.metadata.last_modified = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: For consistency across the codebase, you could use trestle modelutils instead for this update - https://github.com/oscal-compass/compliance-trestle/blob/9d5ebf3eec7fc95b721a659206905d11d6ffd724/trestle/common/model_utils.py#L662

cac_content_root: str,
compdef_type: str,
oscal_profile: str,
authored_object: AuthoredObjectBase,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It seems like the authored_object is mainly used to set the trestle_root, it might make more sense to just pass that value in directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, updated, thanks.

from processing.
"""
super().__init__(working_dir, model_filter)
repo_path = pathlib.Path(self.working_dir)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: The trestle SDK has existing logic for getting the model path that could be useful - https://github.com/oscal-compass/compliance-trestle/blob/9d5ebf3eec7fc95b721a659206905d11d6ffd724/trestle/common/model_utils.py#L352

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated, thanks.

Copy link
Member

@gvauter gvauter left a comment

Choose a reason for hiding this comment

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

Small nit comments, but lgtm.

results = run_bot(pre_tasks, kwargs)
logger.debug(f"Trestlebot results: {results}")
except Exception as e:
traceback_str = traceback.format_exc()
Copy link
Member

@gvauter gvauter Jan 14, 2025

Choose a reason for hiding this comment

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

NIT: I could be missing something, but this seems to duplicate the logic in the common.handle_exceptions decorator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we have the handle_exceptions decorator, but while I'm working the integration testing, I found it can not exit with the correct exitcode, so I updated the autosync command in #391. I could spend some time on this decorator and see how to improve it in a separate PR.

def __init__(self, rule_id: str, rule_dir: str) -> None:
"""Initialize."""
self._id = rule_id
self._description = ""
Copy link
Member

Choose a reason for hiding this comment

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

NIT: Potentially consider default value of None here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, George, here if using None, it may raise a validation error, because none is not an allowed value for Property.

@qduanmu qduanmu merged commit 8ce4f15 into complytime:main Jan 15, 2025
10 checks passed
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.

4 participants