def build_person(self, doc, entity): """Builds an organization object of of a string representation. Returns built organization. Raises SPDXValueError if failed to extract name. """ match = self.person_re.match(entity) if match and validations.validate_person_name(match.group(self.PERSON_NAME_GROUP)): name = match.group(self.PERSON_NAME_GROUP).strip() email = match.group(self.PERSON_EMAIL_GROUP) if (email is not None) and (len(email) != 0): return creationinfo.Person(name=name, email=email.strip()) else: return creationinfo.Person(name=name, email=None) else: raise SPDXValueError('Failed to extract person name')
def create_package(package_name: str, licenses_dict: dict, p_id: int) -> package.Package: logging.debug(f"Creating SBOM Package section") pkg = package.Package(name=package_name, spdx_id=f"SPDXRef-PACKAGE-{p_id}", download_location=extra_conf.get( 'package_location', NoAssert())) pkg.check_sum = Algorithm(identifier="SHA1", value=extra_conf.get('package_sha1', NoAssert())) pkg.license_declared = get_license_obj( extra_conf.get('package_license_identifier'), licenses_dict) pkg.conc_lics = get_license_obj(extra_conf.get('package_conc_licenses'), licenses_dict) pkg.cr_text = extra_conf.get('package_copyright_text', NoAssert()) pkg.supplier = creationinfo.Person( extra_conf.get('package_supplier', SPDXNone()), extra_conf.get('package_supplier_email', SPDXNone())) logging.debug(f"Finished SBOM package section") return pkg
def create_document(token: str) -> Document: logging.debug(f"Creating SBOM Document section") global ws_conn scope_name = ws_conn.get_scope_name_by_token(token) document = Document(name=f"WhiteSource {scope_name} SBOM report", namespace=extra_conf.get('namespace'), spdx_id="SPDXRef-DOCUMENT", version=version.Version(2, 2), data_license=License.from_identifier("CC0-1.0")) logging.debug(f"Creating SBOM Creation Info section") document.creation_info.set_created_now() org = creationinfo.Organization(ws_conn.get_name(), extra_conf.get('org_email')) tool = creationinfo.Tool("White Source SBOM Report Generator") person = creationinfo.Person(extra_conf.get('person'), extra_conf.get('person_email')) document.creation_info.add_creator(org) document.creation_info.add_creator(tool) document.creation_info.add_creator(person) logging.debug(f"Finished SBOM Document section") return document