1use serde::{Deserialize, Serialize};
8use std::fmt;
9use strum::{EnumCount, EnumIter};
10
11#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize, EnumCount, EnumIter)]
32#[serde(rename_all = "snake_case")]
33pub enum DatasourceId {
34 AboutFile,
36 Readme,
37 EtcOsRelease,
38
39 AlpineApkArchive,
41 AlpineApkbuild,
42 AlpineInstalledDb,
43
44 ArchAurinfo,
46 ArchPkginfo,
47 ArchSrcinfo,
48
49 AndroidAarLibrary,
51 AndroidApk,
52
53 Axis2Mar,
55 Axis2ModuleXml,
56
57 AutotoolsConfigure,
59
60 BazelBuild,
62 BazelModule,
63
64 BowerJson,
66
67 #[serde(rename = "buck_file")]
70 BuckFile,
71 #[serde(rename = "buck_metadata")]
73 BuckMetadata,
74
75 BunLock,
77 BunLockb,
78
79 CargoLock,
81 CargoToml,
82 RustBinary,
83
84 #[serde(rename = "chef_cookbook_metadata_json")]
87 ChefCookbookMetadataJson,
88 #[serde(rename = "chef_cookbook_metadata_rb")]
90 ChefCookbookMetadataRb,
91
92 CocoapodsPodfile,
94 CocoapodsPodfileLock,
95 CocoapodsPodspec,
96 CocoapodsPodspecJson,
97
98 #[serde(rename = "conan_conandata_yml")]
100 ConanConanDataYml,
101 #[serde(rename = "conan_conanfile_py")]
102 ConanConanFilePy,
103 #[serde(rename = "conan_conanfile_txt")]
104 ConanConanFileTxt,
105 ConanLock,
106
107 #[serde(rename = "conda_yaml")]
110 CondaYaml,
111 CondaMetaJson,
112 CondaMetaYaml,
113
114 ClojureDepsEdn,
116 ClojureProjectClj,
117
118 CpanDistIni,
120 #[serde(rename = "cpan_makefile")]
122 CpanMakefile,
123 CpanManifest,
124 CpanMetaJson,
125 CpanMetaYml,
126
127 CranDescription,
129
130 PubspecLock,
132 PubspecYaml,
133
134 DebianControlExtractedDeb,
136 DebianControlInSource,
137 DebianCopyright,
138 DebianCopyrightInSource,
139 DebianCopyrightInPackage,
140 DebianCopyrightStandalone,
141 DebianDeb,
142 #[serde(rename = "debian_source_metadata_tarball")]
144 DebianSourceMetadataTarball,
145 DebianDistrolessInstalledDb,
146 #[serde(rename = "debian_installed_files_list")]
148 DebianInstalledFilesList,
149 #[serde(rename = "debian_installed_md5sums")]
150 DebianInstalledMd5Sums,
151 DebianInstalledStatusDb,
152 #[serde(rename = "debian_md5sums_in_extracted_deb")]
153 DebianMd5SumsInExtractedDeb,
154 #[serde(rename = "debian_original_source_tarball")]
156 DebianOriginalSourceTarball,
157 DebianSourceControlDsc,
158
159 DenoJson,
161 DenoLock,
162
163 Dockerfile,
165
166 FreebsdCompactManifest,
168
169 Godeps,
171 GoBinary,
172 GoMod,
173 GoModGraph,
174 GoSum,
175 GoWork,
176
177 HackageCabal,
179 HackageCabalProject,
180 HackageStackYaml,
181
182 BuildGradle,
184 GradleLockfile,
185 GradleModule,
186
187 HaxelibJson,
189
190 HelmChartLock,
192 HelmChartYaml,
193
194 HexMixLock,
196
197 AntIvyXml,
199 JavaEarApplicationXml,
200 JavaEarArchive,
201 JavaJar,
202 JavaJarManifest,
203 JavaOsgiManifest,
204 JavaWarArchive,
205 JavaWarWebXml,
206 JbossSar,
207 JbossServiceXml,
208
209 MavenPom,
211 MavenPomProperties,
212 MesonBuild,
213
214 SbtBuildSbt,
215
216 MicrosoftCabinet,
218 MicrosoftUpdateManifestMum,
219
220 AppleDmg,
222 ChromeCrx,
223 IosIpa,
224 MozillaXpi,
225
226 MeteorPackage,
228
229 NixDefaultNix,
230 NixFlakeLock,
231 NixFlakeNix,
232
233 NpmPackageJson,
235 NpmPackageLockJson,
236
237 NugetCsproj,
239 NugetDepsJson,
240 NugetDirectoryBuildProps,
241 NugetDirectoryPackagesProps,
242 NugetNupkg,
243 NugetProjectJson,
244 NugetProjectLockJson,
245 NugetPackagesConfig,
246 NugetPackagesLock,
247 #[serde(rename = "nuget_nupsec")]
249 NugetNuspec,
250 NugetVbproj,
251 NugetFsproj,
252
253 OpamFile,
255
256 PhpComposerJson,
258 PhpComposerLock,
259
260 PnpmLockYaml,
262 PnpmWorkspaceYaml,
263
264 Pipfile,
266 PipfileLock,
267 PipRequirements,
268 PixiLock,
269 PixiToml,
270 PypiPipOriginJson,
271 PypiEgg,
272 PypiEggPkginfo,
273 PypiEditableEggPkginfo,
274 PypiInspectDeplock,
275 PypiJson,
276 PypiPoetryLock,
277 PypiPoetryPyprojectToml,
278 PypiSdist,
279 PypiPylockToml,
280 PypiPyprojectToml,
281 PypiSdistPkginfo,
282 PypiSetupCfg,
283 PypiSetupPy,
284 PypiUvLock,
285 PypiWheel,
286 PypiWheelMetadata,
287
288 RpmArchive,
290 RpmInstalledDatabaseBdb,
291 RpmInstalledDatabaseNdb,
292 RpmInstalledDatabaseSqlite,
293 RpmMarinerManifest,
294 RpmPackageLicenses,
295 #[serde(rename = "rpm_spefile")]
297 RpmSpecfile,
298 RpmYumdb,
299
300 Gemfile,
302 GemfileExtracted,
303 GemfileLock,
304 GemfileLockExtracted,
305 GemArchive,
306 #[serde(rename = "gem_archive_extracted")]
308 GemArchiveExtracted,
309 Gemspec,
310 GemspecExtracted,
311 GemGemspecInstalledSpecifications,
312
313 InstallshieldInstaller,
315 IsoDiskImage,
316 NsisInstaller,
317 SharShellArchive,
318 SquashfsDiskImage,
319
320 SwiftPackageManifestJson,
322 SwiftPackageResolved,
323 SwiftPackageShowDependencies,
324
325 VcpkgJson,
327
328 YarnLock,
330 YarnLockV1,
331 YarnLockV2,
332
333 Gitmodules,
335}
336
337impl DatasourceId {
338 pub fn as_str(&self) -> &'static str {
342 match self {
343 Self::AboutFile => "about_file",
345 Self::Readme => "readme",
346 Self::EtcOsRelease => "etc_os_release",
347
348 Self::AlpineApkArchive => "alpine_apk_archive",
350 Self::AlpineApkbuild => "alpine_apkbuild",
351 Self::AlpineInstalledDb => "alpine_installed_db",
352
353 Self::ArchAurinfo => "arch_aurinfo",
355 Self::ArchPkginfo => "arch_pkginfo",
356 Self::ArchSrcinfo => "arch_srcinfo",
357
358 Self::AndroidAarLibrary => "android_aar_library",
360 Self::AndroidApk => "android_apk",
361
362 Self::Axis2Mar => "axis2_mar",
364 Self::Axis2ModuleXml => "axis2_module_xml",
365
366 Self::AutotoolsConfigure => "autotools_configure",
368
369 Self::BazelBuild => "bazel_build",
371
372 Self::BowerJson => "bower_json",
374
375 Self::BuckFile => "buck_file",
377 Self::BuckMetadata => "buck_metadata",
378
379 Self::CargoLock => "cargo_lock",
381 Self::CargoToml => "cargo_toml",
382 Self::RustBinary => "rust_binary",
383
384 Self::ChefCookbookMetadataJson => "chef_cookbook_metadata_json",
386 Self::ChefCookbookMetadataRb => "chef_cookbook_metadata_rb",
387
388 Self::CocoapodsPodfile => "cocoapods_podfile",
390 Self::CocoapodsPodfileLock => "cocoapods_podfile_lock",
391 Self::CocoapodsPodspec => "cocoapods_podspec",
392 Self::CocoapodsPodspecJson => "cocoapods_podspec_json",
393
394 Self::ConanConanDataYml => "conan_conandata_yml",
396 Self::ConanConanFilePy => "conan_conanfile_py",
397 Self::ConanConanFileTxt => "conan_conanfile_txt",
398 Self::ConanLock => "conan_lock",
399
400 Self::CondaYaml => "conda_yaml",
402 Self::CondaMetaJson => "conda_meta_json",
403 Self::CondaMetaYaml => "conda_meta_yaml",
404
405 Self::ClojureDepsEdn => "clojure_deps_edn",
407 Self::ClojureProjectClj => "clojure_project_clj",
408
409 Self::CpanDistIni => "cpan_dist_ini",
411 Self::CpanMakefile => "cpan_makefile",
412 Self::CpanManifest => "cpan_manifest",
413 Self::CpanMetaJson => "cpan_meta_json",
414 Self::CpanMetaYml => "cpan_meta_yml",
415
416 Self::CranDescription => "cran_description",
418
419 Self::PubspecLock => "pubspec_lock",
421 Self::PubspecYaml => "pubspec_yaml",
422
423 Self::DebianControlExtractedDeb => "debian_control_extracted_deb",
425 Self::DebianControlInSource => "debian_control_in_source",
426 Self::DebianCopyright => "debian_copyright",
427 Self::DebianCopyrightInSource => "debian_copyright_in_source",
428 Self::DebianCopyrightInPackage => "debian_copyright_in_package",
429 Self::DebianCopyrightStandalone => "debian_copyright_standalone",
430 Self::DebianDeb => "debian_deb",
431 Self::DebianSourceMetadataTarball => "debian_source_metadata_tarball",
432 Self::DebianDistrolessInstalledDb => "debian_distroless_installed_db",
433 Self::DebianInstalledFilesList => "debian_installed_files_list",
434 Self::DebianInstalledMd5Sums => "debian_installed_md5sums",
435 Self::DebianInstalledStatusDb => "debian_installed_status_db",
436 Self::DebianMd5SumsInExtractedDeb => "debian_md5sums_in_extracted_deb",
437 Self::DebianOriginalSourceTarball => "debian_original_source_tarball",
438 Self::DebianSourceControlDsc => "debian_source_control_dsc",
439 Self::DenoJson => "deno_json",
440 Self::DenoLock => "deno_lock",
441 Self::Dockerfile => "dockerfile",
442 Self::BazelModule => "bazel_module",
443
444 Self::FreebsdCompactManifest => "freebsd_compact_manifest",
446
447 Self::Godeps => "godeps",
449 Self::GoBinary => "go_binary",
450 Self::GoMod => "go_mod",
451 Self::GoModGraph => "go_mod_graph",
452 Self::GoSum => "go_sum",
453 Self::GoWork => "go_work",
454
455 Self::HackageCabal => "hackage_cabal",
457 Self::HackageCabalProject => "hackage_cabal_project",
458 Self::HackageStackYaml => "hackage_stack_yaml",
459
460 Self::BuildGradle => "build_gradle",
462 Self::GradleLockfile => "gradle_lockfile",
463 Self::GradleModule => "gradle_module",
464
465 Self::HaxelibJson => "haxelib_json",
467
468 Self::HelmChartLock => "helm_chart_lock",
470 Self::HelmChartYaml => "helm_chart_yaml",
471
472 Self::HexMixLock => "hex_mix_lock",
474
475 Self::AntIvyXml => "ant_ivy_xml",
477 Self::JavaEarApplicationXml => "java_ear_application_xml",
478 Self::JavaEarArchive => "java_ear_archive",
479 Self::JavaJar => "java_jar",
480 Self::JavaJarManifest => "java_jar_manifest",
481 Self::JavaOsgiManifest => "java_osgi_manifest",
482 Self::JavaWarArchive => "java_war_archive",
483 Self::JavaWarWebXml => "java_war_web_xml",
484 Self::JbossSar => "jboss_sar",
485 Self::JbossServiceXml => "jboss_service_xml",
486
487 Self::MavenPom => "maven_pom",
489 Self::MavenPomProperties => "maven_pom_properties",
490 Self::MesonBuild => "meson_build",
491 Self::SbtBuildSbt => "sbt_build_sbt",
492
493 Self::MicrosoftCabinet => "microsoft_cabinet",
495 Self::MicrosoftUpdateManifestMum => "microsoft_update_manifest_mum",
496
497 Self::AppleDmg => "apple_dmg",
499 Self::ChromeCrx => "chrome_crx",
500 Self::IosIpa => "ios_ipa",
501 Self::MozillaXpi => "mozilla_xpi",
502
503 Self::MeteorPackage => "meteor_package",
505
506 Self::NixDefaultNix => "nix_default_nix",
507 Self::NixFlakeLock => "nix_flake_lock",
508 Self::NixFlakeNix => "nix_flake_nix",
509
510 Self::BunLock => "bun_lock",
512 Self::BunLockb => "bun_lockb",
513 Self::NpmPackageJson => "npm_package_json",
514 Self::NpmPackageLockJson => "npm_package_lock_json",
515
516 Self::NugetCsproj => "nuget_csproj",
518 Self::NugetDepsJson => "nuget_deps_json",
519 Self::NugetDirectoryBuildProps => "nuget_directory_build_props",
520 Self::NugetDirectoryPackagesProps => "nuget_directory_packages_props",
521 Self::NugetNupkg => "nuget_nupkg",
522 Self::NugetProjectJson => "nuget_project_json",
523 Self::NugetProjectLockJson => "nuget_project_lock_json",
524 Self::NugetPackagesConfig => "nuget_packages_config",
525 Self::NugetPackagesLock => "nuget_packages_lock",
526 Self::NugetNuspec => "nuget_nupsec",
527 Self::NugetVbproj => "nuget_vbproj",
528 Self::NugetFsproj => "nuget_fsproj",
529
530 Self::OpamFile => "opam_file",
532
533 Self::PhpComposerJson => "php_composer_json",
535 Self::PhpComposerLock => "php_composer_lock",
536
537 Self::PnpmLockYaml => "pnpm_lock_yaml",
539 Self::PnpmWorkspaceYaml => "pnpm_workspace_yaml",
540
541 Self::Pipfile => "pipfile",
543 Self::PipfileLock => "pipfile_lock",
544 Self::PipRequirements => "pip_requirements",
545 Self::PixiLock => "pixi_lock",
546 Self::PixiToml => "pixi_toml",
547 Self::PypiPipOriginJson => "pypi_pip_origin_json",
548 Self::PypiEgg => "pypi_egg",
549 Self::PypiEggPkginfo => "pypi_egg_pkginfo",
550 Self::PypiEditableEggPkginfo => "pypi_editable_egg_pkginfo",
551 Self::PypiInspectDeplock => "pypi_inspect_deplock",
552 Self::PypiJson => "pypi_json",
553 Self::PypiPoetryLock => "pypi_poetry_lock",
554 Self::PypiPoetryPyprojectToml => "pypi_poetry_pyproject_toml",
555 Self::PypiSdist => "pypi_sdist",
556 Self::PypiPylockToml => "pypi_pylock_toml",
557 Self::PypiPyprojectToml => "pypi_pyproject_toml",
558 Self::PypiSdistPkginfo => "pypi_sdist_pkginfo",
559 Self::PypiSetupCfg => "pypi_setup_cfg",
560 Self::PypiSetupPy => "pypi_setup_py",
561 Self::PypiUvLock => "pypi_uv_lock",
562 Self::PypiWheel => "pypi_wheel",
563 Self::PypiWheelMetadata => "pypi_wheel_metadata",
564
565 Self::RpmArchive => "rpm_archive",
567 Self::RpmInstalledDatabaseBdb => "rpm_installed_database_bdb",
568 Self::RpmInstalledDatabaseNdb => "rpm_installed_database_ndb",
569 Self::RpmInstalledDatabaseSqlite => "rpm_installed_database_sqlite",
570 Self::RpmMarinerManifest => "rpm_mariner_manifest",
571 Self::RpmPackageLicenses => "rpm_package_licenses",
572 Self::RpmSpecfile => "rpm_spefile",
573 Self::RpmYumdb => "rpm_yumdb",
574
575 Self::Gemfile => "gemfile",
577 Self::GemfileExtracted => "gemfile_extracted",
578 Self::GemfileLock => "gemfile_lock",
579 Self::GemfileLockExtracted => "gemfile_lock_extracted",
580 Self::GemArchive => "gem_archive",
581 Self::GemArchiveExtracted => "gem_archive_extracted",
582 Self::Gemspec => "gemspec",
583 Self::GemspecExtracted => "gemspec_extracted",
584 Self::GemGemspecInstalledSpecifications => "gem_gemspec_installed_specifications",
585
586 Self::InstallshieldInstaller => "installshield_installer",
588 Self::IsoDiskImage => "iso_disk_image",
589 Self::NsisInstaller => "nsis_installer",
590 Self::SharShellArchive => "shar_shell_archive",
591 Self::SquashfsDiskImage => "squashfs_disk_image",
592
593 Self::SwiftPackageManifestJson => "swift_package_manifest_json",
595 Self::SwiftPackageResolved => "swift_package_resolved",
596 Self::SwiftPackageShowDependencies => "swift_package_show_dependencies",
597
598 Self::VcpkgJson => "vcpkg_json",
600
601 Self::YarnLock => "yarn_lock",
603 Self::YarnLockV1 => "yarn_lock_v1",
604 Self::YarnLockV2 => "yarn_lock_v2",
605
606 Self::Gitmodules => "gitmodules",
608 }
609 }
610}
611
612impl AsRef<str> for DatasourceId {
613 fn as_ref(&self) -> &str {
614 self.as_str()
615 }
616}
617
618impl fmt::Display for DatasourceId {
619 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
620 f.write_str(self.as_str())
621 }
622}
623
624#[cfg(test)]
625mod tests {
626 use super::*;
627
628 #[test]
629 fn test_serialization() {
630 let id = DatasourceId::NpmPackageJson;
631 let json = serde_json::to_string(&id).unwrap();
632 assert_eq!(json, r#""npm_package_json""#);
633 }
634
635 #[test]
636 fn test_deserialization() {
637 let json = r#""npm_package_json""#;
638 let id: DatasourceId = serde_json::from_str(json).unwrap();
639 assert_eq!(id, DatasourceId::NpmPackageJson);
640 }
641
642 #[test]
643 fn test_as_str() {
644 assert_eq!(DatasourceId::NpmPackageJson.as_str(), "npm_package_json");
645 assert_eq!(DatasourceId::CargoLock.as_str(), "cargo_lock");
646 assert_eq!(
647 DatasourceId::PypiPyprojectToml.as_str(),
648 "pypi_pyproject_toml"
649 );
650 assert_eq!(DatasourceId::HackageCabal.as_str(), "hackage_cabal");
651 }
652
653 #[test]
654 fn test_display() {
655 assert_eq!(DatasourceId::NpmPackageJson.to_string(), "npm_package_json");
656 }
657
658 #[test]
659 fn test_as_ref() {
660 let id = DatasourceId::NpmPackageJson;
661 let s: &str = id.as_ref();
662 assert_eq!(s, "npm_package_json");
663 }
664
665 #[test]
666 fn test_python_rename_mappings() {
667 assert_eq!(DatasourceId::BuckFile.as_str(), "buck_file");
669 assert_eq!(DatasourceId::BuckMetadata.as_str(), "buck_metadata");
670 assert_eq!(
671 DatasourceId::ChefCookbookMetadataJson.as_str(),
672 "chef_cookbook_metadata_json"
673 );
674 assert_eq!(
675 DatasourceId::ChefCookbookMetadataRb.as_str(),
676 "chef_cookbook_metadata_rb"
677 );
678 assert_eq!(DatasourceId::CondaYaml.as_str(), "conda_yaml");
679 assert_eq!(DatasourceId::CpanMakefile.as_str(), "cpan_makefile");
680 assert_eq!(
681 DatasourceId::DebianInstalledFilesList.as_str(),
682 "debian_installed_files_list"
683 );
684 assert_eq!(
685 DatasourceId::DebianOriginalSourceTarball.as_str(),
686 "debian_original_source_tarball"
687 );
688 assert_eq!(
689 DatasourceId::DebianSourceMetadataTarball.as_str(),
690 "debian_source_metadata_tarball"
691 );
692 assert_eq!(
693 DatasourceId::GemArchiveExtracted.as_str(),
694 "gem_archive_extracted"
695 );
696 assert_eq!(DatasourceId::NugetNuspec.as_str(), "nuget_nupsec");
697 assert_eq!(DatasourceId::RpmSpecfile.as_str(), "rpm_spefile");
698 }
699}