Skip to content

Commit

Permalink
Problem:
Browse files Browse the repository at this point in the history
Primary images not uploaded with correct attr name; other names unhelpful

Solution:
Introduce a new class AttachmentDescription, to hold the filename and
attribute_name. Then update all current samples to ensure the display name is
used as intended.

Signed-off-by: Henry Jewell [email protected]
  • Loading branch information
Henry Jewell authored and henry739 committed Feb 23, 2023
1 parent 12f08db commit 31cd89e
Show file tree
Hide file tree
Showing 9 changed files with 208 additions and 123 deletions.
20 changes: 10 additions & 10 deletions archivist_samples/door_entry/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .images import assets as images_assets
from .images import events as images_events

from ..testing.assets import make_assets_create
from ..testing.assets import make_assets_create, AttachmentDescription


DOOR_TERMINAL = "Door access terminal"
Expand All @@ -29,15 +29,15 @@
############


def attachment_create(doors, name):
with resources.open_binary(images_assets, name) as fd:
def attachment_create(doors, attachment_description: AttachmentDescription):
with resources.open_binary(images_assets, attachment_description.filename) as fd:
attachment = doors.attachments.upload(fd)
result = {
"arc_attribute_type": "arc_attachment",
"arc_blob_identity": attachment["identity"],
"arc_blob_hash_alg": attachment["hash"]["alg"],
"arc_blob_hash_value": attachment["hash"]["value"],
"arc_file_name": name,
"arc_file_name": attachment_description.filename,
}

return result
Expand Down Expand Up @@ -78,7 +78,7 @@ def create_rkvst_paris(doors):
},
},
attachments=[
"entry_terminal.jpg",
AttachmentDescription("entry_terminal.jpg", "arc_primary_image"),
],
)

Expand Down Expand Up @@ -109,7 +109,7 @@ def create_cityhall(doors):
},
},
attachments=[
"cityhall.jpg",
AttachmentDescription("cityhall.jpg", "arc_primary_image"),
],
)

Expand Down Expand Up @@ -140,7 +140,7 @@ def create_courts(doors):
},
},
attachments=[
"courts.jpg",
AttachmentDescription("courts.jpg", "arc_primary_image"),
],
)

Expand Down Expand Up @@ -173,7 +173,7 @@ def create_bastille(doors):
},
},
attachments=[
"bastille.jpg",
AttachmentDescription("bastille.jpg", "arc_primary_image"),
],
)

Expand Down Expand Up @@ -206,7 +206,7 @@ def create_gdn_front(doors):
},
},
attachments=[
"gdn_front.jpg",
AttachmentDescription("gdn_front.jpg", "arc_primary_image"),
],
)

Expand Down Expand Up @@ -239,7 +239,7 @@ def create_gdn_side(doors):
},
},
attachments=[
"gdn_side.jpg",
AttachmentDescription("gdn_side.jpg", "arc_primary_image"),
],
)

Expand Down
17 changes: 9 additions & 8 deletions archivist_samples/software_bill_of_materials/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from archivist import about

from .software_package import SoftwarePackage
from ..testing.assets import AttachmentDescription

LOGGER = logging.getLogger(__name__)

Expand All @@ -28,7 +29,7 @@ def run(arch, args):
"sbom_license": "www.gnu.org/licenses/gpl.txt",
"proprietary_secret": "For your eyes only",
},
attachments=[("Comp_2.jpeg", "arc_primary_image")],
attachments=[AttachmentDescription("Comp_2.jpeg", "arc_primary_image")],
)
if package.existed:
LOGGER.info("Software Package already Created: %s", package_name)
Expand All @@ -47,7 +48,7 @@ def run(arch, args):
"supplier": "Coyote Services, Inc.",
"uuid": "com.acme.rrd2013-ce-sp1-v4-1-5-0",
},
attachments=[("v4_1_5_sbom.xml", "SWID SBOM")],
attachments=[AttachmentDescription("v4_1_5_sbom.xml", "SWID SBOM")],
)
LOGGER.info("Release registered.")

Expand All @@ -62,7 +63,7 @@ def run(arch, args):
"supplier": "Coyote Services, Inc.",
"uuid": "com.acme.rrd2013-ce-sp1-v4-1-6-0",
},
attachments=[("v4_1_6_sbom.xml", "SWID SBOM")],
attachments=[AttachmentDescription("v4_1_6_sbom.xml", "SWID SBOM")],
)
LOGGER.info("Release registered.")

Expand All @@ -80,7 +81,7 @@ def run(arch, args):
"uuid": "com.acme.rrd2013-ce-sp1-v4-1-6-1",
"reference": "CVE-20210613-1",
},
attachments=[("v4_1_6_1_sbom.xml", "SWID SBOM")],
attachments=[AttachmentDescription("v4_1_6_1_sbom.xml", "SWID SBOM")],
)
LOGGER.info("Private patch registered.")

Expand All @@ -95,7 +96,7 @@ def run(arch, args):
"supplier": "Coyote Services, Inc.",
"uuid": "com.acme.rrd2013-ce-sp1-v4-1-7-0",
},
attachments=[("v4_1_7_sbom.xml", "SWID SBOM")],
attachments=[AttachmentDescription("v4_1_7_sbom.xml", "SWID SBOM")],
)
LOGGER.info("Release registered.")

Expand All @@ -110,7 +111,7 @@ def run(arch, args):
"reference": "BIG_V_5",
"captain": "Deputy Dawg",
},
attachments=[("v5_0_0_sbom.xml", "SWID SBOM")],
attachments=[AttachmentDescription("v5_0_0_sbom.xml", "SWID SBOM")],
)

LOGGER.info("6 Approve major upgrade...")
Expand All @@ -125,7 +126,7 @@ def run(arch, args):
"captain": "Deputy Dawg",
"approver": "Yosemite Sam",
},
attachments=[("v5_0_0_sbom.xml", "SWID SBOM")],
attachments=[AttachmentDescription("v5_0_0_sbom.xml", "SWID SBOM")],
)

LOGGER.info("7 Release major upgrade...")
Expand All @@ -139,7 +140,7 @@ def run(arch, args):
"supplier": "Coyote Services, Inc.",
"uuid": "com.acme.rrd2013-ce-sp1-v5-0-0-0",
},
attachments=[("v5_0_0_sbom.xml", "SWID SBOM")],
attachments=[AttachmentDescription("v5_0_0_sbom.xml", "SWID SBOM")],
)
LOGGER.info("Release registered.")
sys_exit(0)
80 changes: 48 additions & 32 deletions archivist_samples/software_bill_of_materials/software_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@

import logging
from sys import exit as sys_exit
from typing import Optional
from typing import List, Optional

from archivist import archivist as type_helper

from ..testing.assets import make_assets_create
from ..testing.assets import make_assets_create, AttachmentDescription

from . import sbom_files


LOGGER = logging.getLogger(__name__)


def attachment_create(sboms, name):
LOGGER.info("sbom attachment creator: %s", name)
with resources.open_binary(sbom_files, name[0]) as fd:
def attachment_create(sboms, attachment_description: AttachmentDescription):
LOGGER.info("sbom attachment creator: %s", attachment_description.filename)
with resources.open_binary(sbom_files, attachment_description.filename) as fd:
attachment = sboms.attachments.upload(fd)
result = {
"arc_attribute_type": "arc_attachment",
"arc_blob_identity": attachment["identity"],
"arc_blob_hash_alg": attachment["hash"]["alg"],
"arc_blob_hash_value": attachment["hash"]["value"],
"arc_display_name": name[1],
"arc_file_name": name[0],
"arc_display_name": attachment_description.attribute_name,
"arc_file_name": attachment_description.filename,
}
return result

Expand Down Expand Up @@ -62,7 +62,7 @@ def create(
sbom_name: str,
sbom_description: str,
*,
attachments: Optional[list] = None,
attachments: Optional[List[AttachmentDescription]] = None,
custom_attrs: Optional[dict] = None,
):
attrs = {
Expand Down Expand Up @@ -106,7 +106,7 @@ def release(
self,
sbom: dict,
*,
attachments: Optional[list] = None,
attachments: Optional[List[AttachmentDescription]] = None,
latest_sbom: Optional[dict] = None,
custom_attrs: Optional[dict] = None,
custom_asset_attrs: Optional[dict] = None,
Expand Down Expand Up @@ -139,8 +139,10 @@ def release(
"sbom_uuid": sbom["uuid"],
}
if attachments:
for i, attachment in enumerate(attachments):
attrs[f"attachment_attr_{i}"] = attachment_create(self.arch, attachment)
for attachment in attachments:
attrs[attachment.attribute_name] = attachment_create(
self.arch, attachment
)

if custom_attrs is not None:
attrs.update(custom_attrs)
Expand Down Expand Up @@ -169,7 +171,7 @@ def release_plan(
self,
sbom_planned: dict,
*,
attachments: Optional[list] = None,
attachments: Optional[List[AttachmentDescription]] = None,
custom_attrs: Optional[dict] = None,
):
props = {
Expand All @@ -187,8 +189,10 @@ def release_plan(
"sbom_planned_reference": sbom_planned["reference"],
}
if attachments:
for i, attachment in enumerate(attachments):
attrs[f"attachment_attr_{i}"] = attachment_create(self.arch, attachment)
for attachment in attachments:
attrs[attachment.attribute_name] = attachment_create(
self.arch, attachment
)

if custom_attrs is not None:
attrs.update(custom_attrs)
Expand All @@ -201,7 +205,7 @@ def release_accepted(
self,
sbom_accepted: dict,
*,
attachments: Optional[list] = None,
attachments: Optional[List[AttachmentDescription]] = None,
custom_attrs: Optional[dict] = None,
):
props = {
Expand All @@ -220,8 +224,10 @@ def release_accepted(
"sbom_accepted_vuln_reference": sbom_accepted["reference"],
}
if attachments:
for i, attachment in enumerate(attachments):
attrs[f"attachment_attr_{i}"] = attachment_create(self.arch, attachment)
for attachment in attachments:
attrs[attachment.attribute_name] = attachment_create(
self.arch, attachment
)

if custom_attrs is not None:
attrs.update(custom_attrs)
Expand All @@ -235,7 +241,7 @@ def patch(
self,
sbom_patch: dict,
*,
attachments: Optional[list] = None,
attachments: Optional[List[AttachmentDescription]] = None,
custom_attrs: Optional[dict] = None,
):
props = {
Expand All @@ -254,8 +260,10 @@ def patch(
"sbom_patch_uuid": sbom_patch["uuid"],
}
if attachments:
for i, attachment in enumerate(attachments):
attrs[f"attachment_attr_{i}"] = attachment_create(self.arch, attachment)
for attachment in attachments:
attrs[attachment.attribute_name] = attachment_create(
self.arch, attachment
)

if custom_attrs is not None:
attrs.update(custom_attrs)
Expand All @@ -268,7 +276,7 @@ def private_patch(
self,
sbom_patch: dict,
*,
attachments: Optional[list] = None,
attachments: Optional[List[AttachmentDescription]] = None,
custom_attrs: Optional[dict] = None,
):
props = {
Expand All @@ -288,8 +296,10 @@ def private_patch(
"sbom_patch_vuln_reference": sbom_patch["reference"],
}
if attachments:
for i, attachment in enumerate(attachments):
attrs[f"attachment_attr_{i}"] = attachment_create(self.arch, attachment)
for attachment in attachments:
attrs[attachment.attribute_name] = attachment_create(
self.arch, attachment
)

if custom_attrs is not None:
attrs.update(custom_attrs)
Expand All @@ -303,7 +313,7 @@ def vuln_disclosure(
self,
vuln: dict,
*,
attachments: Optional[list] = None,
attachments: Optional[List[AttachmentDescription]] = None,
custom_attrs: Optional[dict],
):
props = {
Expand All @@ -325,8 +335,10 @@ def vuln_disclosure(
"vuln_target_version": vuln["target_version"],
}
if attachments:
for i, attachment in enumerate(attachments):
attrs[f"attachment_attr_{i}"] = attachment_create(self.arch, attachment)
for attachment in attachments:
attrs[attachment.attribute_name] = attachment_create(
self.arch, attachment
)

if custom_attrs is not None:
attrs.update(custom_attrs)
Expand All @@ -338,7 +350,7 @@ def vuln_disclosure(
def vuln_update(
self,
vuln: dict,
attachments: Optional[list] = None,
attachments: Optional[List[AttachmentDescription]] = None,
custom_attrs: Optional[dict] = None,
):
props = {
Expand All @@ -360,8 +372,10 @@ def vuln_update(
"vuln_target_version": vuln["target_version"],
}
if attachments:
for i, attachment in enumerate(attachments):
attrs[f"attachment_attr_{i}"] = attachment_create(self.arch, attachment)
for attachment in attachments:
attrs[attachment.attribute_name] = attachment_create(
self.arch, attachment
)

if custom_attrs is not None:
attrs.update(custom_attrs)
Expand All @@ -375,7 +389,7 @@ def deprecation(
self,
sbom_eol: dict,
*,
attachments: Optional[list] = None,
attachments: Optional[List[AttachmentDescription]] = None,
custom_attrs: Optional[dict] = None,
):
props = {
Expand All @@ -393,8 +407,10 @@ def deprecation(
"sbom_eol_target_date": sbom_eol["target_date"],
}
if attachments:
for i, attachment in enumerate(attachments):
attrs[f"attachment_attr_{i}"] = attachment_create(self.arch, attachment)
for attachment in attachments:
attrs[attachment.attribute_name] = attachment_create(
self.arch, attachment
)

if custom_attrs is not None:
attrs.update(custom_attrs)
Expand Down
2 changes: 1 addition & 1 deletion archivist_samples/synsation/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def demo_flow(ac, asset_id, asset_type, tw, wait):
"arc_blob_hash_alg": iattachment["hash"]["alg"],
"arc_blob_hash_value": iattachment["hash"]["value"],
},
"attachment_attr_1": {
"Conformance Report": {
"arc_display_name": "Conformance Report",
"arc_attribute_type": "arc_attachment",
"arc_blob_identity": rattachment["identity"],
Expand Down
Loading

0 comments on commit 31cd89e

Please sign in to comment.