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

Fix timestamps for data-stream composition #12625

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions build-scripts/compose_ds.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ssg.build_sce import collect_sce_checks
from ssg.constants import (
cat_namespace, datastream_namespace, oval_namespace, sce_namespace,
XCCDF12_NS, xlink_namespace)
timestamp, XCCDF12_NS, xlink_namespace)
import ssg.xml

try:
Expand Down Expand Up @@ -47,7 +47,7 @@ def embed_sce_checks_in_datastream(datastreamtree, checklists, checks, build_dir
datastreamtree, '{%s}extended-component' % datastream_namespace,
attrib={
'id': component_id,
'timestamp': get_timestamp(path)
'timestamp': timestamp
})
# Append the file content
script_data = ET.SubElement(component, '{%s}script' % sce_namespace)
Expand Down Expand Up @@ -190,16 +190,6 @@ def parse_args():
return parser.parse_args()


def get_timestamp(file_name):
source_date_epoch = os.getenv("SOURCE_DATE_EPOCH")
if source_date_epoch:
time_sec = float(source_date_epoch)
else:
time_sec = os.path.getmtime(file_name)
timestamp = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime(time_sec))
return timestamp


def add_component(
ds_collection, component_ref_parent, component_file_name,
dependencies=None):
Expand All @@ -210,7 +200,7 @@ def add_component(
component = ET.SubElement(
ds_collection, "{%s}component" % datastream_namespace)
component.set("id", component_id)
component.set("timestamp", get_timestamp(component_file_name))
component.set("timestamp", timestamp)
component_ref = ET.SubElement(
component_ref_parent, "{%s}component-ref" % datastream_namespace)
component_ref_id = "scap_%s_cref_%s" % (
Expand Down Expand Up @@ -247,6 +237,7 @@ def compose_ds(
ds.set("id", "scap_%s_datastream_%s" % (ID_NS, name))
ds.set("scap-version", "1.3")
ds.set("use-case", "OTHER")
ds.set("timestamp", timestamp)
dictionaries = ET.SubElement(ds, "{%s}dictionaries" % datastream_namespace)
checklists = ET.SubElement(ds, "{%s}checklists" % datastream_namespace)
checks = ET.SubElement(ds, "{%s}checks" % datastream_namespace)
Expand Down
5 changes: 1 addition & 4 deletions ssg/build_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,10 +742,7 @@ def _create_benchmark_xml_skeleton(self, env_yaml):
root.set('xml:lang', 'en-US')

status = ET.SubElement(root, '{%s}status' % XCCDF12_NS)
status.set(
'date',
time.strftime("%Y-%m-%d",
time.gmtime(int(os.environ.get('SOURCE_DATE_EPOCH', time.time())))))
status.set('date', timestamp)
status.text = self.status

add_sub_element(root, "title", XCCDF12_NS, self.title)
Expand Down
Loading