Skip to content

Commit 85dd6b3

Browse files
committed
autotailor: Add --relative-path option for layered product compatibility
Add a new --relative-path flag that generates benchmark references using relative paths instead of absolute file:// URIs. This enables compatibility with Red Hat Satellite and other layered products that cannot resolve local filesystem paths. When --relative-path is specified: - Absolute paths are converted to basename only - Relative paths are preserved as provided by the user The default behavior remains unchanged for backward compatibility. Resolves: RHEL-143568
1 parent 7373845 commit 85dd6b3

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

utils/autotailor

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ class Tailoring:
300300
self.id = "xccdf_auto_tailoring_default"
301301
self.version = 1
302302
self.original_ds_filename = ""
303+
self.use_relative_path = False
303304

304305
self.profiles = []
305306

@@ -319,8 +320,19 @@ class Tailoring:
319320
root.set("id", self.id)
320321

321322
benchmark = ET.SubElement(root, "{%s}benchmark" % NS)
322-
datastream_uri = pathlib.Path(
323-
self.original_ds_filename).absolute().as_uri()
323+
if self.use_relative_path:
324+
# Preserve relative paths as-is, convert absolute paths to basename
325+
ds_path = pathlib.Path(self.original_ds_filename)
326+
if ds_path.is_absolute():
327+
# Convert absolute path to basename for compatibility with layered products
328+
datastream_uri = ds_path.name
329+
else:
330+
# Keep relative paths as provided by the user
331+
datastream_uri = self.original_ds_filename
332+
else:
333+
# Use absolute URI (default behavior for backward compatibility)
334+
datastream_uri = pathlib.Path(
335+
self.original_ds_filename).absolute().as_uri()
324336
benchmark.set("href", datastream_uri)
325337

326338
version = ET.SubElement(root, "{%s}version" % NS)
@@ -433,6 +445,10 @@ def get_parser():
433445
"-o", "--output", default="-",
434446
help="Where to save the tailoring file. If not supplied, write to "
435447
"standard output.")
448+
parser.add_argument(
449+
"--relative-path", action="store_true",
450+
help="Use relative path (basename only) for the benchmark href instead of "
451+
"absolute file:// URI.")
436452
return parser
437453

438454

@@ -447,6 +463,7 @@ if __name__ == "__main__":
447463
t = Tailoring()
448464
t.original_ds_filename = args.datastream
449465
t.reverse_dns = args.id_namespace
466+
t.use_relative_path = args.relative_path
450467

451468
if args.json_tailoring:
452469
t.import_json_tailoring(args.json_tailoring)

0 commit comments

Comments
 (0)