-
Notifications
You must be signed in to change notification settings - Fork 429
autotailor: Add --relative-path option for layered product compatibility #2337
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -300,6 +300,7 @@ class Tailoring: | |
| self.id = "xccdf_auto_tailoring_default" | ||
| self.version = 1 | ||
| self.original_ds_filename = "" | ||
| self.use_relative_path = False | ||
|
|
||
| self.profiles = [] | ||
|
|
||
|
|
@@ -319,8 +320,19 @@ class Tailoring: | |
| root.set("id", self.id) | ||
|
|
||
| benchmark = ET.SubElement(root, "{%s}benchmark" % NS) | ||
| datastream_uri = pathlib.Path( | ||
| self.original_ds_filename).absolute().as_uri() | ||
| if self.use_relative_path: | ||
| # Preserve relative paths as-is, convert absolute paths to basename | ||
| ds_path = pathlib.Path(self.original_ds_filename) | ||
| if ds_path.is_absolute(): | ||
| # Convert absolute path to basename for compatibility with layered products | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The option name is |
||
| datastream_uri = ds_path.name | ||
| else: | ||
| # Keep relative paths as provided by the user | ||
| datastream_uri = self.original_ds_filename | ||
| else: | ||
| # Use absolute URI (default behavior for backward compatibility) | ||
| datastream_uri = pathlib.Path( | ||
| self.original_ds_filename).absolute().as_uri() | ||
| benchmark.set("href", datastream_uri) | ||
|
|
||
| version = ET.SubElement(root, "{%s}version" % NS) | ||
|
|
@@ -433,6 +445,10 @@ def get_parser(): | |
| "-o", "--output", default="-", | ||
| help="Where to save the tailoring file. If not supplied, write to " | ||
| "standard output.") | ||
| parser.add_argument( | ||
| "--relative-path", action="store_true", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please document the new option in the man page. |
||
| help="Use relative path (basename only) for the benchmark href instead of " | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test that covers this feature. |
||
| "absolute file:// URI.") | ||
| return parser | ||
|
|
||
|
|
||
|
|
@@ -447,6 +463,7 @@ if __name__ == "__main__": | |
| t = Tailoring() | ||
| t.original_ds_filename = args.datastream | ||
| t.reverse_dns = args.id_namespace | ||
| t.use_relative_path = args.relative_path | ||
|
|
||
| if args.json_tailoring: | ||
| t.import_json_tailoring(args.json_tailoring) | ||
|
|
||
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.
The
to_xmlmethod starts getting long. I suggest extracting the code that determines the URI to a separate method eg._get_datastream_uri()