diff --git a/bindings/go/osvschema/constants.go b/bindings/go/osvschema/constants.go index 7088f12..4dfdea9 100644 --- a/bindings/go/osvschema/constants.go +++ b/bindings/go/osvschema/constants.go @@ -8,17 +8,22 @@ const ( EcosystemAndroid Ecosystem = "Android" EcosystemBioconductor Ecosystem = "Bioconductor" EcosystemBitnami Ecosystem = "Bitnami" + EcosystemChainguard Ecosystem = "Chainguard" EcosystemConanCenter Ecosystem = "ConanCenter" EcosystemCRAN Ecosystem = "CRAN" EcosystemCratesIO Ecosystem = "crates.io" EcosystemDebian Ecosystem = "Debian" + EcosystemGHC Ecosystem = "GHC" EcosystemGitHubActions Ecosystem = "GitHub Actions" EcosystemGo Ecosystem = "Go" + EcosystemHackage Ecosystem = "Hackage" EcosystemHex Ecosystem = "Hex" EcosystemLinux Ecosystem = "Linux" + EcosystemMageia Ecosystem = "Mageia" EcosystemMaven Ecosystem = "Maven" EcosystemNPM Ecosystem = "npm" EcosystemNuGet Ecosystem = "NuGet" + EcosystemOpenSUSE Ecosystem = "openSUSE" EcosystemOSSFuzz Ecosystem = "OSS-Fuzz" EcosystemPackagist Ecosystem = "Packagist" EcosystemPhotonOS Ecosystem = "Photon OS" @@ -27,8 +32,10 @@ const ( EcosystemRedHat Ecosystem = "Red Hat" EcosystemRockyLinux Ecosystem = "Rocky Linux" EcosystemRubyGems Ecosystem = "RubyGems" + EcosystemSUSE Ecosystem = "SUSE" EcosystemSwiftURL Ecosystem = "SwiftURL" EcosystemUbuntu Ecosystem = "Ubuntu" + EcosystemWolfi Ecosystem = "Wolfi" ) type SeverityType string diff --git a/scripts/update-ecosystems-lists.py b/scripts/update-ecosystems-lists.py index 3544a11..420d6c3 100755 --- a/scripts/update-ecosystems-lists.py +++ b/scripts/update-ecosystems-lists.py @@ -71,5 +71,65 @@ def update_schema_md(): open('docs/schema.md', 'w').write(md) +def convert_to_go_constant_name(name: str) -> str: + """ + Converts the "human" name of an ecosystem to a Go constant name, mostly + by removing spaces and dashes and converting to PascalCase. + + Some ecosystems have special cases, like "crates.io" which is converted to "CratesIO". + + :param name: + :return: + """ + if name == 'crates.io': + return 'EcosystemCratesIO' + + if name == 'npm': + return 'EcosystemNPM' + + name = name[0].upper() + name[1:] + name = name.replace('-', '').replace(' ', '') + + return f'Ecosystem{name}' + + +def generate_ecosystems_go_constants() -> str: + """ + Generates a list of Go constants, with a constant per ecosystem + :return: + """ + + constants = list(map(lambda x: (convert_to_go_constant_name(x), x), ecosystems.keys())) + longest = max(map(lambda x: len(x[0]), constants)) + + code = 'const (\n' + for constant, name in constants: + code += f'\t{constant.ljust(longest)} Ecosystem = "{name}"\n' + code += ')\n' + + return code + + +def update_go_constants(): + """ + Updates the Go constants with the list of ecosystems + :return: + """ + go = open('bindings/go/osvschema/constants.go').read() + + ecosystem_constants_start = go.index('type Ecosystem string\n\nconst (\n') + ecosystems_constants_end = go.index(')', ecosystem_constants_start) + + go = '{0}{1}\n\n{2}{3}'.format( + go[:ecosystem_constants_start], + 'type Ecosystem string', + generate_ecosystems_go_constants(), + go[ecosystems_constants_end + 2:] + ) + + open('bindings/go/osvschema/constants.go', 'w').write(go) + + +update_go_constants() update_json_schema() update_schema_md()