|
| 1 | +# This file is part of CycloneDX Python |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# |
| 15 | +# SPDX-License-Identifier: Apache-2.0 |
| 16 | +# Copyright (c) OWASP Foundation. All Rights Reserved. |
| 17 | + |
| 18 | + |
| 19 | +""" |
| 20 | +Pure mapping data for URL -> ExternalReferenceType classification. |
| 21 | +
|
| 22 | +This module is DATA ONLY -- no logic. To extend classification, add rows here. |
| 23 | +Four match styles, applied by ``cdx.url_label_to_ert`` in this precedence order: |
| 24 | +
|
| 25 | +1. _MAP_KNOWN_URL_LABELS exact label (normalized: lowercased, non-[a-z] stripped) |
| 26 | +2. _MAP_URL_LABEL_PREFIXES label prefix (PyPI '*' semantics); first match wins |
| 27 | +3. _MAP_KNOWN_URL_HOST_SUFFIXES host == key OR host endswith '.'+key (domain + subdomains) |
| 28 | +4. _MAP_KNOWN_URL_HOST_PREFIXES host == key OR host startswith key+'.' (e.g. docs.*) |
| 29 | +
|
| 30 | +Label keys MUST already be normalized (lowercase, only [a-z]). |
| 31 | +Host keys MUST be lowercase. |
| 32 | +
|
| 33 | +see https://docs.pypi.org/project_metadata/#icons |
| 34 | +""" |
| 35 | + |
| 36 | +from cyclonedx.model import ExternalReferenceType |
| 37 | + |
| 38 | +# 1. exact label -> ERT |
| 39 | +_MAP_KNOWN_URL_LABELS: dict[str, ExternalReferenceType] = { |
| 40 | + # see https://peps.python.org/pep-0345/#project-url-multiple-use |
| 41 | + # see https://github.com/pypi/warehouse/issues/5947#issuecomment-699660629 |
| 42 | + 'bugtracker': ExternalReferenceType.ISSUE_TRACKER, |
| 43 | + 'issuetracker': ExternalReferenceType.ISSUE_TRACKER, |
| 44 | + 'issues': ExternalReferenceType.ISSUE_TRACKER, |
| 45 | + 'bugreports': ExternalReferenceType.ISSUE_TRACKER, |
| 46 | + 'tracker': ExternalReferenceType.ISSUE_TRACKER, |
| 47 | + 'home': ExternalReferenceType.WEBSITE, |
| 48 | + 'homepage': ExternalReferenceType.WEBSITE, |
| 49 | + 'download': ExternalReferenceType.DISTRIBUTION, |
| 50 | + 'documentation': ExternalReferenceType.DOCUMENTATION, |
| 51 | + 'docs': ExternalReferenceType.DOCUMENTATION, |
| 52 | + 'changelog': ExternalReferenceType.RELEASE_NOTES, |
| 53 | + 'changes': ExternalReferenceType.RELEASE_NOTES, |
| 54 | + 'releasenotes': ExternalReferenceType.RELEASE_NOTES, |
| 55 | + 'news': ExternalReferenceType.RELEASE_NOTES, |
| 56 | + 'whatsnew': ExternalReferenceType.RELEASE_NOTES, |
| 57 | + 'history': ExternalReferenceType.RELEASE_NOTES, |
| 58 | + 'repository': ExternalReferenceType.VCS, |
| 59 | + 'source': ExternalReferenceType.VCS, |
| 60 | + 'github': ExternalReferenceType.VCS, |
| 61 | + 'chat': ExternalReferenceType.CHAT, |
| 62 | +} |
| 63 | + |
| 64 | +# 2. label prefix -> ERT (ordered; first match wins). normalized prefixes. |
| 65 | +_MAP_URL_LABEL_PREFIXES: tuple[tuple[str, ExternalReferenceType], ...] = ( |
| 66 | + ('documentation', ExternalReferenceType.DOCUMENTATION), |
| 67 | + ('docs', ExternalReferenceType.DOCUMENTATION), |
| 68 | + ('bug', ExternalReferenceType.ISSUE_TRACKER), |
| 69 | + ('issue', ExternalReferenceType.ISSUE_TRACKER), |
| 70 | + ('tracker', ExternalReferenceType.ISSUE_TRACKER), |
| 71 | + ('report', ExternalReferenceType.ISSUE_TRACKER), |
| 72 | + ('funding', ExternalReferenceType.OTHER), |
| 73 | + ('sponsor', ExternalReferenceType.OTHER), |
| 74 | + ('donation', ExternalReferenceType.OTHER), |
| 75 | + ('donate', ExternalReferenceType.OTHER), |
| 76 | +) |
0 commit comments