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
83 #[serde(rename = "chef_cookbook_metadata_json")]
86 ChefCookbookMetadataJson,
87 #[serde(rename = "chef_cookbook_metadata_rb")]
89 ChefCookbookMetadataRb,
90
91 CocoapodsPodfile,
93 CocoapodsPodfileLock,
94 CocoapodsPodspec,
95 CocoapodsPodspecJson,
96
97 #[serde(rename = "conan_conandata_yml")]
99 ConanConanDataYml,
100 #[serde(rename = "conan_conanfile_py")]
101 ConanConanFilePy,
102 #[serde(rename = "conan_conanfile_txt")]
103 ConanConanFileTxt,
104 ConanLock,
105
106 #[serde(rename = "conda_yaml")]
109 CondaYaml,
110 CondaMetaJson,
111 CondaMetaYaml,
112
113 ClojureDepsEdn,
115 ClojureProjectClj,
116
117 CpanDistIni,
119 #[serde(rename = "cpan_makefile")]
121 CpanMakefile,
122 CpanManifest,
123 CpanMetaJson,
124 CpanMetaYml,
125
126 CranDescription,
128
129 PubspecLock,
131 PubspecYaml,
132
133 DebianControlExtractedDeb,
135 DebianControlInSource,
136 DebianCopyright,
137 DebianDeb,
138 #[serde(rename = "debian_source_metadata_tarball")]
140 DebianSourceMetadataTarball,
141 DebianDistrolessInstalledDb,
142 #[serde(rename = "debian_installed_files_list")]
144 DebianInstalledFilesList,
145 #[serde(rename = "debian_installed_md5sums")]
146 DebianInstalledMd5Sums,
147 DebianInstalledStatusDb,
148 #[serde(rename = "debian_md5sums_in_extracted_deb")]
149 DebianMd5SumsInExtractedDeb,
150 #[serde(rename = "debian_original_source_tarball")]
152 DebianOriginalSourceTarball,
153 DebianSourceControlDsc,
154
155 DenoJson,
157 DenoLock,
158
159 Dockerfile,
161
162 FreebsdCompactManifest,
164
165 Godeps,
167 GoMod,
168 GoModGraph,
169 GoSum,
170 GoWork,
171
172 HackageCabal,
174 HackageCabalProject,
175 HackageStackYaml,
176
177 BuildGradle,
179 GradleLockfile,
180 GradleModule,
181
182 HaxelibJson,
184
185 HelmChartLock,
187 HelmChartYaml,
188
189 HexMixLock,
191
192 AntIvyXml,
194 JavaEarApplicationXml,
195 JavaEarArchive,
196 JavaJar,
197 JavaJarManifest,
198 JavaOsgiManifest,
199 JavaWarArchive,
200 JavaWarWebXml,
201 JbossSar,
202 JbossServiceXml,
203
204 MavenPom,
206 MavenPomProperties,
207 MesonBuild,
208
209 SbtBuildSbt,
210
211 MicrosoftCabinet,
213 MicrosoftUpdateManifestMum,
214
215 AppleDmg,
217 ChromeCrx,
218 IosIpa,
219 MozillaXpi,
220
221 MeteorPackage,
223
224 NixDefaultNix,
225 NixFlakeLock,
226 NixFlakeNix,
227
228 NpmPackageJson,
230 NpmPackageLockJson,
231
232 NugetCsproj,
234 NugetDepsJson,
235 NugetDirectoryBuildProps,
236 NugetDirectoryPackagesProps,
237 NugetNupkg,
238 NugetProjectJson,
239 NugetProjectLockJson,
240 NugetPackagesConfig,
241 NugetPackagesLock,
242 #[serde(rename = "nuget_nupsec")]
244 NugetNuspec,
245 NugetVbproj,
246 NugetFsproj,
247
248 OpamFile,
250
251 PhpComposerJson,
253 PhpComposerLock,
254
255 PnpmLockYaml,
257 PnpmWorkspaceYaml,
258
259 Pipfile,
261 PipfileLock,
262 PipRequirements,
263 PixiLock,
264 PixiToml,
265 PypiPipOriginJson,
266 PypiEgg,
267 PypiInspectDeplock,
268 PypiJson,
269 PypiPoetryLock,
270 PypiPylockToml,
271 PypiPyprojectToml,
272 PypiSdistPkginfo,
273 PypiSetupCfg,
274 PypiSetupPy,
275 PypiUvLock,
276 PypiWheel,
277 PypiWheelMetadata,
278
279 RpmArchive,
281 RpmInstalledDatabaseBdb,
282 RpmInstalledDatabaseNdb,
283 RpmInstalledDatabaseSqlite,
284 RpmMarinerManifest,
285 RpmPackageLicenses,
286 #[serde(rename = "rpm_spefile")]
288 RpmSpecfile,
289 RpmYumdb,
290
291 Gemfile,
293 GemfileLock,
294 GemArchive,
295 #[serde(rename = "gem_archive_extracted")]
297 GemArchiveExtracted,
298 Gemspec,
299
300 InstallshieldInstaller,
302 IsoDiskImage,
303 NsisInstaller,
304 SharShellArchive,
305 SquashfsDiskImage,
306
307 SwiftPackageManifestJson,
309 SwiftPackageResolved,
310 SwiftPackageShowDependencies,
311
312 VcpkgJson,
314
315 YarnLock,
317
318 Gitmodules,
320}
321
322impl DatasourceId {
323 pub fn as_str(&self) -> &'static str {
327 match self {
328 Self::AboutFile => "about_file",
330 Self::Readme => "readme",
331 Self::EtcOsRelease => "etc_os_release",
332
333 Self::AlpineApkArchive => "alpine_apk_archive",
335 Self::AlpineApkbuild => "alpine_apkbuild",
336 Self::AlpineInstalledDb => "alpine_installed_db",
337
338 Self::ArchAurinfo => "arch_aurinfo",
340 Self::ArchPkginfo => "arch_pkginfo",
341 Self::ArchSrcinfo => "arch_srcinfo",
342
343 Self::AndroidAarLibrary => "android_aar_library",
345 Self::AndroidApk => "android_apk",
346
347 Self::Axis2Mar => "axis2_mar",
349 Self::Axis2ModuleXml => "axis2_module_xml",
350
351 Self::AutotoolsConfigure => "autotools_configure",
353
354 Self::BazelBuild => "bazel_build",
356
357 Self::BowerJson => "bower_json",
359
360 Self::BuckFile => "buck_file",
362 Self::BuckMetadata => "buck_metadata",
363
364 Self::CargoLock => "cargo_lock",
366 Self::CargoToml => "cargo_toml",
367
368 Self::ChefCookbookMetadataJson => "chef_cookbook_metadata_json",
370 Self::ChefCookbookMetadataRb => "chef_cookbook_metadata_rb",
371
372 Self::CocoapodsPodfile => "cocoapods_podfile",
374 Self::CocoapodsPodfileLock => "cocoapods_podfile_lock",
375 Self::CocoapodsPodspec => "cocoapods_podspec",
376 Self::CocoapodsPodspecJson => "cocoapods_podspec_json",
377
378 Self::ConanConanDataYml => "conan_conandata_yml",
380 Self::ConanConanFilePy => "conan_conanfile_py",
381 Self::ConanConanFileTxt => "conan_conanfile_txt",
382 Self::ConanLock => "conan_lock",
383
384 Self::CondaYaml => "conda_yaml",
386 Self::CondaMetaJson => "conda_meta_json",
387 Self::CondaMetaYaml => "conda_meta_yaml",
388
389 Self::ClojureDepsEdn => "clojure_deps_edn",
391 Self::ClojureProjectClj => "clojure_project_clj",
392
393 Self::CpanDistIni => "cpan_dist_ini",
395 Self::CpanMakefile => "cpan_makefile",
396 Self::CpanManifest => "cpan_manifest",
397 Self::CpanMetaJson => "cpan_meta_json",
398 Self::CpanMetaYml => "cpan_meta_yml",
399
400 Self::CranDescription => "cran_description",
402
403 Self::PubspecLock => "pubspec_lock",
405 Self::PubspecYaml => "pubspec_yaml",
406
407 Self::DebianControlExtractedDeb => "debian_control_extracted_deb",
409 Self::DebianControlInSource => "debian_control_in_source",
410 Self::DebianCopyright => "debian_copyright",
411 Self::DebianDeb => "debian_deb",
412 Self::DebianSourceMetadataTarball => "debian_source_metadata_tarball",
413 Self::DebianDistrolessInstalledDb => "debian_distroless_installed_db",
414 Self::DebianInstalledFilesList => "debian_installed_files_list",
415 Self::DebianInstalledMd5Sums => "debian_installed_md5sums",
416 Self::DebianInstalledStatusDb => "debian_installed_status_db",
417 Self::DebianMd5SumsInExtractedDeb => "debian_md5sums_in_extracted_deb",
418 Self::DebianOriginalSourceTarball => "debian_original_source_tarball",
419 Self::DebianSourceControlDsc => "debian_source_control_dsc",
420 Self::DenoJson => "deno_json",
421 Self::DenoLock => "deno_lock",
422 Self::Dockerfile => "dockerfile",
423 Self::BazelModule => "bazel_module",
424
425 Self::FreebsdCompactManifest => "freebsd_compact_manifest",
427
428 Self::Godeps => "godeps",
430 Self::GoMod => "go_mod",
431 Self::GoModGraph => "go_mod_graph",
432 Self::GoSum => "go_sum",
433 Self::GoWork => "go_work",
434
435 Self::HackageCabal => "hackage_cabal",
437 Self::HackageCabalProject => "hackage_cabal_project",
438 Self::HackageStackYaml => "hackage_stack_yaml",
439
440 Self::BuildGradle => "build_gradle",
442 Self::GradleLockfile => "gradle_lockfile",
443 Self::GradleModule => "gradle_module",
444
445 Self::HaxelibJson => "haxelib_json",
447
448 Self::HelmChartLock => "helm_chart_lock",
450 Self::HelmChartYaml => "helm_chart_yaml",
451
452 Self::HexMixLock => "hex_mix_lock",
454
455 Self::AntIvyXml => "ant_ivy_xml",
457 Self::JavaEarApplicationXml => "java_ear_application_xml",
458 Self::JavaEarArchive => "java_ear_archive",
459 Self::JavaJar => "java_jar",
460 Self::JavaJarManifest => "java_jar_manifest",
461 Self::JavaOsgiManifest => "java_osgi_manifest",
462 Self::JavaWarArchive => "java_war_archive",
463 Self::JavaWarWebXml => "java_war_web_xml",
464 Self::JbossSar => "jboss_sar",
465 Self::JbossServiceXml => "jboss_service_xml",
466
467 Self::MavenPom => "maven_pom",
469 Self::MavenPomProperties => "maven_pom_properties",
470 Self::MesonBuild => "meson_build",
471 Self::SbtBuildSbt => "sbt_build_sbt",
472
473 Self::MicrosoftCabinet => "microsoft_cabinet",
475 Self::MicrosoftUpdateManifestMum => "microsoft_update_manifest_mum",
476
477 Self::AppleDmg => "apple_dmg",
479 Self::ChromeCrx => "chrome_crx",
480 Self::IosIpa => "ios_ipa",
481 Self::MozillaXpi => "mozilla_xpi",
482
483 Self::MeteorPackage => "meteor_package",
485
486 Self::NixDefaultNix => "nix_default_nix",
487 Self::NixFlakeLock => "nix_flake_lock",
488 Self::NixFlakeNix => "nix_flake_nix",
489
490 Self::BunLock => "bun_lock",
492 Self::BunLockb => "bun_lockb",
493 Self::NpmPackageJson => "npm_package_json",
494 Self::NpmPackageLockJson => "npm_package_lock_json",
495
496 Self::NugetCsproj => "nuget_csproj",
498 Self::NugetDepsJson => "nuget_deps_json",
499 Self::NugetDirectoryBuildProps => "nuget_directory_build_props",
500 Self::NugetDirectoryPackagesProps => "nuget_directory_packages_props",
501 Self::NugetNupkg => "nuget_nupkg",
502 Self::NugetProjectJson => "nuget_project_json",
503 Self::NugetProjectLockJson => "nuget_project_lock_json",
504 Self::NugetPackagesConfig => "nuget_packages_config",
505 Self::NugetPackagesLock => "nuget_packages_lock",
506 Self::NugetNuspec => "nuget_nupsec",
507 Self::NugetVbproj => "nuget_vbproj",
508 Self::NugetFsproj => "nuget_fsproj",
509
510 Self::OpamFile => "opam_file",
512
513 Self::PhpComposerJson => "php_composer_json",
515 Self::PhpComposerLock => "php_composer_lock",
516
517 Self::PnpmLockYaml => "pnpm_lock_yaml",
519 Self::PnpmWorkspaceYaml => "pnpm_workspace_yaml",
520
521 Self::Pipfile => "pipfile",
523 Self::PipfileLock => "pipfile_lock",
524 Self::PipRequirements => "pip_requirements",
525 Self::PixiLock => "pixi_lock",
526 Self::PixiToml => "pixi_toml",
527 Self::PypiPipOriginJson => "pypi_pip_origin_json",
528 Self::PypiEgg => "pypi_egg",
529 Self::PypiInspectDeplock => "pypi_inspect_deplock",
530 Self::PypiJson => "pypi_json",
531 Self::PypiPoetryLock => "pypi_poetry_lock",
532 Self::PypiPylockToml => "pypi_pylock_toml",
533 Self::PypiPyprojectToml => "pypi_pyproject_toml",
534 Self::PypiSdistPkginfo => "pypi_sdist_pkginfo",
535 Self::PypiSetupCfg => "pypi_setup_cfg",
536 Self::PypiSetupPy => "pypi_setup_py",
537 Self::PypiUvLock => "pypi_uv_lock",
538 Self::PypiWheel => "pypi_wheel",
539 Self::PypiWheelMetadata => "pypi_wheel_metadata",
540
541 Self::RpmArchive => "rpm_archive",
543 Self::RpmInstalledDatabaseBdb => "rpm_installed_database_bdb",
544 Self::RpmInstalledDatabaseNdb => "rpm_installed_database_ndb",
545 Self::RpmInstalledDatabaseSqlite => "rpm_installed_database_sqlite",
546 Self::RpmMarinerManifest => "rpm_mariner_manifest",
547 Self::RpmPackageLicenses => "rpm_package_licenses",
548 Self::RpmSpecfile => "rpm_spefile",
549 Self::RpmYumdb => "rpm_yumdb",
550
551 Self::Gemfile => "gemfile",
553 Self::GemfileLock => "gemfile_lock",
554 Self::GemArchive => "gem_archive",
555 Self::GemArchiveExtracted => "gem_archive_extracted",
556 Self::Gemspec => "gemspec",
557
558 Self::InstallshieldInstaller => "installshield_installer",
560 Self::IsoDiskImage => "iso_disk_image",
561 Self::NsisInstaller => "nsis_installer",
562 Self::SharShellArchive => "shar_shell_archive",
563 Self::SquashfsDiskImage => "squashfs_disk_image",
564
565 Self::SwiftPackageManifestJson => "swift_package_manifest_json",
567 Self::SwiftPackageResolved => "swift_package_resolved",
568 Self::SwiftPackageShowDependencies => "swift_package_show_dependencies",
569
570 Self::VcpkgJson => "vcpkg_json",
572
573 Self::YarnLock => "yarn_lock",
575
576 Self::Gitmodules => "gitmodules",
578 }
579 }
580}
581
582impl AsRef<str> for DatasourceId {
583 fn as_ref(&self) -> &str {
584 self.as_str()
585 }
586}
587
588impl fmt::Display for DatasourceId {
589 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
590 f.write_str(self.as_str())
591 }
592}
593
594#[cfg(test)]
595mod tests {
596 use super::*;
597
598 #[test]
599 fn test_serialization() {
600 let id = DatasourceId::NpmPackageJson;
601 let json = serde_json::to_string(&id).unwrap();
602 assert_eq!(json, r#""npm_package_json""#);
603 }
604
605 #[test]
606 fn test_deserialization() {
607 let json = r#""npm_package_json""#;
608 let id: DatasourceId = serde_json::from_str(json).unwrap();
609 assert_eq!(id, DatasourceId::NpmPackageJson);
610 }
611
612 #[test]
613 fn test_as_str() {
614 assert_eq!(DatasourceId::NpmPackageJson.as_str(), "npm_package_json");
615 assert_eq!(DatasourceId::CargoLock.as_str(), "cargo_lock");
616 assert_eq!(
617 DatasourceId::PypiPyprojectToml.as_str(),
618 "pypi_pyproject_toml"
619 );
620 assert_eq!(DatasourceId::HackageCabal.as_str(), "hackage_cabal");
621 }
622
623 #[test]
624 fn test_display() {
625 assert_eq!(DatasourceId::NpmPackageJson.to_string(), "npm_package_json");
626 }
627
628 #[test]
629 fn test_as_ref() {
630 let id = DatasourceId::NpmPackageJson;
631 let s: &str = id.as_ref();
632 assert_eq!(s, "npm_package_json");
633 }
634
635 #[test]
636 fn test_python_rename_mappings() {
637 assert_eq!(DatasourceId::BuckFile.as_str(), "buck_file");
639 assert_eq!(DatasourceId::BuckMetadata.as_str(), "buck_metadata");
640 assert_eq!(
641 DatasourceId::ChefCookbookMetadataJson.as_str(),
642 "chef_cookbook_metadata_json"
643 );
644 assert_eq!(
645 DatasourceId::ChefCookbookMetadataRb.as_str(),
646 "chef_cookbook_metadata_rb"
647 );
648 assert_eq!(DatasourceId::CondaYaml.as_str(), "conda_yaml");
649 assert_eq!(DatasourceId::CpanMakefile.as_str(), "cpan_makefile");
650 assert_eq!(
651 DatasourceId::DebianInstalledFilesList.as_str(),
652 "debian_installed_files_list"
653 );
654 assert_eq!(
655 DatasourceId::DebianOriginalSourceTarball.as_str(),
656 "debian_original_source_tarball"
657 );
658 assert_eq!(
659 DatasourceId::DebianSourceMetadataTarball.as_str(),
660 "debian_source_metadata_tarball"
661 );
662 assert_eq!(
663 DatasourceId::GemArchiveExtracted.as_str(),
664 "gem_archive_extracted"
665 );
666 assert_eq!(DatasourceId::NugetNuspec.as_str(), "nuget_nupsec");
667 assert_eq!(DatasourceId::RpmSpecfile.as_str(), "rpm_spefile");
668 }
669}