Skip to content

Commit 7bdb1b6

Browse files
Use configs for source symbol extensions
Signed-off-by: Ayan Sinha Mahapatra <ayansmahapatra@gmail.com>
1 parent 1b736ca commit 7bdb1b6

3 files changed

Lines changed: 53 additions & 25 deletions

File tree

scanpipe/pipelines/deploy_to_develop.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def match_archives_to_purldb(self):
156156

157157
d2d.match_purldb_resources(
158158
project=self.project,
159-
extensions=self.purldb_package_extensions,
159+
extensions=self.matchable_package_extensions,
160160
matcher_func=d2d.match_purldb_package,
161161
logger=self.log,
162162
)
@@ -234,7 +234,7 @@ def match_resources_to_purldb(self):
234234

235235
d2d.match_purldb_resources(
236236
project=self.project,
237-
extensions=self.purldb_resource_extensions,
237+
extensions=self.matchable_resource_extensions,
238238
matcher_func=d2d.match_purldb_resource,
239239
logger=self.log,
240240
)
@@ -290,7 +290,7 @@ def perform_house_keeping_tasks(self):
290290
)
291291
d2d.match_unmapped_resources(
292292
project=self.project,
293-
matched_extensions=self.ecosystem_config.purldb_resource_extensions,
293+
matched_extensions=self.ecosystem_config.matchable_resource_extensions,
294294
logger=self.log,
295295
)
296296
d2d.flag_undeployed_resources(project=self.project)

scanpipe/pipes/d2d.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from scanpipe.models import CodebaseRelation
5555
from scanpipe.models import CodebaseResource
5656
from scanpipe.models import convert_glob_to_django_regex
57+
from scanpipe.pipes import d2d_config
5758
from scanpipe.pipes import flag
5859
from scanpipe.pipes import get_resource_diff_ratio
5960
from scanpipe.pipes import js
@@ -1939,7 +1940,10 @@ def map_rust_binaries_with_symbols(project, logger=None):
19391940
)
19401941

19411942
# Collect source symbols from rust source files
1942-
rust_from_resources = from_resources.filter(extension=".rs")
1943+
rust_config = d2d_config.get_ecosystem_config(ecosystem="Rust")
1944+
rust_from_resources = from_resources.filter(
1945+
extension__in=rust_config.source_symbol_extensions
1946+
)
19431947

19441948
map_binaries_with_symbols(
19451949
project=project,
@@ -1959,7 +1963,10 @@ def map_elfs_binaries_with_symbols(project, logger=None):
19591963
)
19601964

19611965
# Collect source symbols from elf related source files
1962-
elf_from_resources = from_resources.filter(extension__in=[".c", ".cpp", ".h"])
1966+
elf_config = d2d_config.get_ecosystem_config(ecosystem="Elf")
1967+
elf_from_resources = from_resources.filter(
1968+
extension__in=elf_config.source_symbol_extensions
1969+
)
19631970

19641971
map_binaries_with_symbols(
19651972
project=project,
@@ -1982,8 +1989,9 @@ def map_macho_binaries_with_symbols(project, logger=None):
19821989
)
19831990

19841991
# Collect source symbols from macos related source files
1992+
macos_config = d2d_config.get_ecosystem_config(ecosystem="MacOS")
19851993
mac_from_resources = from_resources.filter(
1986-
extension__in=[".c", ".cpp", ".h", ".m", ".swift"]
1994+
extension__in=macos_config.source_symbol_extensions,
19871995
)
19881996

19891997
map_binaries_with_symbols(
@@ -2004,8 +2012,9 @@ def map_winpe_binaries_with_symbols(project, logger=None):
20042012
)
20052013

20062014
# Collect source symbols from windows related source files
2015+
windows_config = d2d_config.get_ecosystem_config(ecosystem="Windows")
20072016
windows_from_resources = from_resources.filter(
2008-
extension__in=[".c", ".cpp", ".h", ".cs"]
2017+
extension__in=windows_config.source_symbol_extensions,
20092018
)
20102019

20112020
map_binaries_with_symbols(
@@ -2071,16 +2080,17 @@ def map_javascript_symbols(project, logger=None):
20712080
"""Map deployed JavaScript, TypeScript to its sources using symbols."""
20722081
project_files = project.codebaseresources.files()
20732082

2083+
js_config = d2d_config.get_ecosystem_config(ecosystem="JavaScript")
20742084
javascript_to_resources = (
20752085
project_files.to_codebase()
20762086
.has_no_relation()
2077-
.filter(extension__in=[".ts", ".js"])
2087+
.filter(extension__in=js_config.source_symbol_extensions)
20782088
)
20792089

20802090
javascript_from_resources = (
20812091
project_files.from_codebase()
20822092
.exclude(path__contains="/test/")
2083-
.filter(extension__in=[".ts", ".js"])
2093+
.filter(extension__in=js_config.source_symbol_extensions)
20842094
)
20852095

20862096
if not (javascript_from_resources.exists() and javascript_to_resources.exists()):

scanpipe/pipes/d2d_config.py

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class EcosystemConfig:
3636
# are options in the pipelines
3737
ecosystem_option: str = "Default"
3838

39-
# These are extensions for packages of this ecosystem which
40-
# need to be matched from purldb
41-
purldb_package_extensions: list = field(default_factory=list)
39+
# These are extensions for package archive files for this ecosystem
40+
# that are matchable against the purldb using matchcode
41+
matchable_package_extensions: list = field(default_factory=list)
4242

43-
# These are extensions for resources of this ecosystem which
44-
# need to be matched from purldb
45-
purldb_resource_extensions: list = field(default_factory=list)
43+
# These are extensions for file of this ecosystem that are
44+
# matchable against the purldb using matchcode
45+
matchable_resource_extensions: list = field(default_factory=list)
4646

4747
# Extensions for document files which do not require review
4848
doc_extensions: list = field(default_factory=list)
@@ -60,11 +60,15 @@ class EcosystemConfig:
6060
# which are not so useful in mapping
6161
standard_symbols_to_exclude: list = field(default_factory=list)
6262

63+
# File extesions which should be looked at for source symbol extraction
64+
# for mapping using symbols for a specific selected option/ecosystem
65+
source_symbol_extensions: list = field(default_factory=list)
66+
6367

6468
# Dictionary of ecosystem configurations
6569
ECOSYSTEM_CONFIGS = {
6670
"Default": EcosystemConfig(
67-
purldb_package_extensions=[".zip", ".tar.gz", ".tar.xz"],
71+
matchable_package_extensions=[".zip", ".tar.gz", ".tar.xz"],
6872
devel_resource_path_exclusions=["*/tests/*"],
6973
doc_extensions=[
7074
".pdf",
@@ -79,12 +83,12 @@ class EcosystemConfig:
7983
),
8084
"Java": EcosystemConfig(
8185
ecosystem_option="Java",
82-
purldb_package_extensions=[".jar", ".war"],
83-
purldb_resource_extensions=[".class"],
86+
matchable_package_extensions=[".jar", ".war"],
87+
matchable_resource_extensions=[".class"],
8488
),
8589
"JavaScript": EcosystemConfig(
8690
ecosystem_option="JavaScript",
87-
purldb_resource_extensions=[
91+
matchable_resource_extensions=[
8892
".map",
8993
".js",
9094
".mjs",
@@ -98,21 +102,35 @@ class EcosystemConfig:
98102
".sass",
99103
".soy",
100104
],
105+
source_symbol_extensions=[".ts", ".js"],
101106
),
102107
"Go": EcosystemConfig(
103108
ecosystem_option="Go",
104-
purldb_resource_extensions=[".go"],
109+
matchable_resource_extensions=[".go"],
105110
),
106111
"Rust": EcosystemConfig(
107112
ecosystem_option="Rust",
108-
purldb_resource_extensions=[".rs"],
113+
matchable_resource_extensions=[".rs"],
114+
source_symbol_extensions=[".rs"],
109115
),
110116
"Ruby": EcosystemConfig(
111117
ecosystem_option="Ruby",
112-
purldb_package_extensions=[".gem"],
113-
purldb_resource_extensions=[".rb"],
118+
matchable_package_extensions=[".gem"],
119+
matchable_resource_extensions=[".rb"],
114120
deployed_resource_path_exclusions=["*checksums.yaml.gz*", "*metadata.gz*"],
115121
),
122+
"Elf": EcosystemConfig(
123+
ecosystem_option="Elf",
124+
source_symbol_extensions=[".c", ".cpp", ".h"],
125+
),
126+
"MacOS": EcosystemConfig(
127+
ecosystem_option="MacOS",
128+
source_symbol_extensions=[".c", ".cpp", ".h", ".m", ".swift"],
129+
),
130+
"Windows": EcosystemConfig(
131+
ecosystem_option="Windows",
132+
source_symbol_extensions=[".c", ".cpp", ".h", ".cs"],
133+
),
116134
}
117135

118136

@@ -150,8 +168,8 @@ def add_ecosystem_config(pipeline_ecosystem_config, ecosystem_config):
150168
based configuration defined in `ecosystem_config`.
151169
"""
152170
d2d_pipeline_configs = [
153-
"purldb_package_extensions",
154-
"purldb_resource_extensions",
171+
"matchable_package_extensions",
172+
"matchable_resource_extensions",
155173
"deployed_resource_path_exclusions",
156174
]
157175

0 commit comments

Comments
 (0)