diff --git a/internal/constants.go b/internal/constants.go index 6fcf68a47938..71a134a72a92 100644 --- a/internal/constants.go +++ b/internal/constants.go @@ -6,5 +6,5 @@ const ( // JSONSchemaVersion is the current schema version output by the JSON encoder // This is roughly following the "SchemaVer" guidelines for versioning the JSON schema. Please see schema/json/README.md for details on how to increment. - JSONSchemaVersion = "3.3.2" + JSONSchemaVersion = "4.0.0" ) diff --git a/schema/json/generate.go b/schema/json/generate.go index e5833e5ffd6b..4175ca29b36e 100644 --- a/schema/json/generate.go +++ b/schema/json/generate.go @@ -28,20 +28,24 @@ can be extended to include specific package metadata struct shapes in the future // When a new package metadata definition is created it will need to be manually added here. The variable name does // not matter as long as it is exported. type artifactMetadataContainer struct { - Apk pkg.ApkMetadata - Alpm pkg.AlpmMetadata - Dpkg pkg.DpkgMetadata - Gem pkg.GemMetadata - Java pkg.JavaMetadata - Npm pkg.NpmPackageJSONMetadata - Python pkg.PythonPackageMetadata - Rpm pkg.RpmMetadata - Cargo pkg.CargoPackageMetadata - Go pkg.GolangBinMetadata - Php pkg.PhpComposerJSONMetadata - Dart pkg.DartPubMetadata - Dotnet pkg.DotnetDepsMetadata - Portage pkg.PortageMetadata + Apk pkg.ApkMetadata + Alpm pkg.AlpmMetadata + Dpkg pkg.DpkgMetadata + Gem pkg.GemMetadata + Java pkg.JavaMetadata + Npm pkg.NpmPackageJSONMetadata + Python pkg.PythonPackageMetadata + Rpm pkg.RpmMetadata + Cargo pkg.CargoPackageMetadata + Go pkg.GolangBinMetadata + Php pkg.PhpComposerJSONMetadata + Dart pkg.DartPubMetadata + Dotnet pkg.DotnetDepsMetadata + Portage pkg.PortageMetadata + Conan pkg.ConanMetadata + ConanLock pkg.ConanLockMetadata + KbPackage pkg.KbPackageMetadata + Hackage pkg.HackageMetadata } func main() { diff --git a/schema/json/schema-4.0.0.json b/schema/json/schema-4.0.0.json new file mode 100644 index 000000000000..c12add6ba1c0 --- /dev/null +++ b/schema/json/schema-4.0.0.json @@ -0,0 +1,1574 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Document", + "definitions": { + "AlpmFileRecord": { + "properties": { + "path": { + "type": "string" + }, + "type": { + "type": "string" + }, + "uid": { + "type": "string" + }, + "gid": { + "type": "string" + }, + "time": { + "type": "string", + "format": "date-time" + }, + "size": { + "type": "string" + }, + "link": { + "type": "string" + }, + "digest": { + "items": { + "$ref": "#/definitions/Digest" + }, + "type": "array" + } + }, + "additionalProperties": true, + "type": "object" + }, + "AlpmMetadata": { + "required": [ + "basepackage", + "package", + "version", + "description", + "architecture", + "size", + "packager", + "license", + "url", + "validation", + "reason", + "files", + "backup" + ], + "properties": { + "basepackage": { + "type": "string" + }, + "package": { + "type": "string" + }, + "version": { + "type": "string" + }, + "description": { + "type": "string" + }, + "architecture": { + "type": "string" + }, + "size": { + "type": "integer" + }, + "packager": { + "type": "string" + }, + "license": { + "type": "string" + }, + "url": { + "type": "string" + }, + "validation": { + "type": "string" + }, + "reason": { + "type": "integer" + }, + "files": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/AlpmFileRecord" + }, + "type": "array" + }, + "backup": { + "items": { + "$ref": "#/definitions/AlpmFileRecord" + }, + "type": "array" + } + }, + "additionalProperties": true, + "type": "object" + }, + "ApkFileRecord": { + "required": [ + "path" + ], + "properties": { + "path": { + "type": "string" + }, + "ownerUid": { + "type": "string" + }, + "ownerGid": { + "type": "string" + }, + "permissions": { + "type": "string" + }, + "digest": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Digest" + } + }, + "additionalProperties": true, + "type": "object" + }, + "ApkMetadata": { + "required": [ + "package", + "originPackage", + "maintainer", + "version", + "license", + "architecture", + "url", + "description", + "size", + "installedSize", + "pullDependencies", + "pullChecksum", + "gitCommitOfApkPort", + "files" + ], + "properties": { + "package": { + "type": "string" + }, + "originPackage": { + "type": "string" + }, + "maintainer": { + "type": "string" + }, + "version": { + "type": "string" + }, + "license": { + "type": "string" + }, + "architecture": { + "type": "string" + }, + "url": { + "type": "string" + }, + "description": { + "type": "string" + }, + "size": { + "type": "integer" + }, + "installedSize": { + "type": "integer" + }, + "pullDependencies": { + "type": "string" + }, + "pullChecksum": { + "type": "string" + }, + "gitCommitOfApkPort": { + "type": "string" + }, + "files": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/ApkFileRecord" + }, + "type": "array" + } + }, + "additionalProperties": true, + "type": "object" + }, + "CargoPackageMetadata": { + "required": [ + "name", + "version", + "source", + "checksum", + "dependencies" + ], + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "source": { + "type": "string" + }, + "checksum": { + "type": "string" + }, + "dependencies": { + "items": { + "type": "string" + }, + "type": "array" + } + }, + "additionalProperties": true, + "type": "object" + }, + "Classification": { + "required": [ + "class", + "metadata" + ], + "properties": { + "class": { + "type": "string" + }, + "metadata": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + } + }, + "additionalProperties": true, + "type": "object" + }, + "ConanLockMetadata": { + "required": [ + "ref" + ], + "properties": { + "ref": { + "type": "string" + }, + "package_id": { + "type": "string" + }, + "prev": { + "type": "string" + }, + "requires": { + "type": "string" + }, + "build_requires": { + "type": "string" + }, + "py_requires": { + "type": "string" + }, + "options": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, + "path": { + "type": "string" + }, + "context": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "ConanMetadata": { + "required": [ + "ref" + ], + "properties": { + "ref": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "Coordinates": { + "required": [ + "path" + ], + "properties": { + "path": { + "type": "string" + }, + "layerID": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "DartPubMetadata": { + "required": [ + "name", + "version" + ], + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "hosted_url": { + "type": "string" + }, + "vcs_url": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "Descriptor": { + "required": [ + "name", + "version" + ], + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "configuration": { + "additionalProperties": true + } + }, + "additionalProperties": true, + "type": "object" + }, + "Digest": { + "required": [ + "algorithm", + "value" + ], + "properties": { + "algorithm": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "Document": { + "required": [ + "artifacts", + "artifactRelationships", + "source", + "distro", + "descriptor", + "schema" + ], + "properties": { + "artifacts": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Package" + }, + "type": "array" + }, + "artifactRelationships": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Relationship" + }, + "type": "array" + }, + "files": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/File" + }, + "type": "array" + }, + "secrets": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Secrets" + }, + "type": "array" + }, + "source": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Source" + }, + "distro": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/LinuxRelease" + }, + "descriptor": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Descriptor" + }, + "schema": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Schema" + } + }, + "additionalProperties": true, + "type": "object" + }, + "DotnetDepsMetadata": { + "required": [ + "name", + "version", + "path", + "sha512", + "hashPath" + ], + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "path": { + "type": "string" + }, + "sha512": { + "type": "string" + }, + "hashPath": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "DpkgFileRecord": { + "required": [ + "path", + "isConfigFile" + ], + "properties": { + "path": { + "type": "string" + }, + "digest": { + "$ref": "#/definitions/Digest" + }, + "isConfigFile": { + "type": "boolean" + } + }, + "additionalProperties": true, + "type": "object" + }, + "DpkgMetadata": { + "required": [ + "package", + "source", + "version", + "sourceVersion", + "architecture", + "maintainer", + "installedSize", + "files" + ], + "properties": { + "package": { + "type": "string" + }, + "source": { + "type": "string" + }, + "version": { + "type": "string" + }, + "sourceVersion": { + "type": "string" + }, + "architecture": { + "type": "string" + }, + "maintainer": { + "type": "string" + }, + "installedSize": { + "type": "integer" + }, + "files": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/DpkgFileRecord" + }, + "type": "array" + } + }, + "additionalProperties": true, + "type": "object" + }, + "File": { + "required": [ + "id", + "location" + ], + "properties": { + "id": { + "type": "string" + }, + "location": { + "$ref": "#/definitions/Coordinates" + }, + "metadata": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/FileMetadataEntry" + }, + "contents": { + "type": "string" + }, + "digests": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Digest" + }, + "type": "array" + }, + "classifications": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Classification" + }, + "type": "array" + } + }, + "additionalProperties": true, + "type": "object" + }, + "FileMetadataEntry": { + "required": [ + "mode", + "type", + "userID", + "groupID", + "mimeType" + ], + "properties": { + "mode": { + "type": "integer" + }, + "type": { + "type": "string" + }, + "linkDestination": { + "type": "string" + }, + "userID": { + "type": "integer" + }, + "groupID": { + "type": "integer" + }, + "mimeType": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "GemMetadata": { + "required": [ + "name", + "version" + ], + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "files": { + "items": { + "type": "string" + }, + "type": "array" + }, + "authors": { + "items": { + "type": "string" + }, + "type": "array" + }, + "licenses": { + "items": { + "type": "string" + }, + "type": "array" + }, + "homepage": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "GolangBinMetadata": { + "required": [ + "goCompiledVersion", + "architecture" + ], + "properties": { + "goBuildSettings": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, + "goCompiledVersion": { + "type": "string" + }, + "architecture": { + "type": "string" + }, + "h1Digest": { + "type": "string" + }, + "mainModule": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "HackageMetadata": { + "required": [ + "name", + "version" + ], + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "pkgHash": { + "type": "string" + }, + "snapshotURL": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "JavaManifest": { + "properties": { + "main": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, + "namedSections": { + "patternProperties": { + ".*": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + } + }, + "type": "object" + } + }, + "additionalProperties": true, + "type": "object" + }, + "JavaMetadata": { + "required": [ + "virtualPath" + ], + "properties": { + "virtualPath": { + "type": "string" + }, + "manifest": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/JavaManifest" + }, + "pomProperties": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/PomProperties" + }, + "pomProject": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/PomProject" + }, + "digest": { + "items": { + "$ref": "#/definitions/Digest" + }, + "type": "array" + } + }, + "additionalProperties": true, + "type": "object" + }, + "KbPackageMetadata": { + "required": [ + "product_id", + "kb" + ], + "properties": { + "product_id": { + "type": "string" + }, + "kb": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "LinuxRelease": { + "properties": { + "prettyName": { + "type": "string" + }, + "name": { + "type": "string" + }, + "id": { + "type": "string" + }, + "idLike": { + "items": { + "type": "string" + }, + "type": "array" + }, + "version": { + "type": "string" + }, + "versionID": { + "type": "string" + }, + "versionCodename": { + "type": "string" + }, + "buildID": { + "type": "string" + }, + "imageID": { + "type": "string" + }, + "imageVersion": { + "type": "string" + }, + "variant": { + "type": "string" + }, + "variantID": { + "type": "string" + }, + "homeURL": { + "type": "string" + }, + "supportURL": { + "type": "string" + }, + "bugReportURL": { + "type": "string" + }, + "privacyPolicyURL": { + "type": "string" + }, + "cpeName": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "NpmPackageJSONMetadata": { + "required": [ + "name", + "version", + "author", + "licenses", + "homepage", + "description", + "url", + "private" + ], + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "files": { + "items": { + "type": "string" + }, + "type": "array" + }, + "author": { + "type": "string" + }, + "licenses": { + "items": { + "type": "string" + }, + "type": "array" + }, + "homepage": { + "type": "string" + }, + "description": { + "type": "string" + }, + "url": { + "type": "string" + }, + "private": { + "type": "boolean" + } + }, + "additionalProperties": true, + "type": "object" + }, + "Package": { + "required": [ + "id", + "name", + "version", + "type", + "foundBy", + "locations", + "licenses", + "language", + "cpes", + "purl" + ], + "properties": { + "id": { + "type": "string" + }, + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "type": { + "type": "string" + }, + "foundBy": { + "type": "string" + }, + "locations": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/Coordinates" + }, + "type": "array" + }, + "licenses": { + "items": { + "type": "string" + }, + "type": "array" + }, + "language": { + "type": "string" + }, + "cpes": { + "items": { + "type": "string" + }, + "type": "array" + }, + "purl": { + "type": "string" + }, + "metadataType": { + "type": "string" + }, + "metadata": { + "anyOf": [ + { + "type": "null" + }, + { + "$ref": "#/definitions/AlpmMetadata" + }, + { + "$ref": "#/definitions/ApkMetadata" + }, + { + "$ref": "#/definitions/CargoPackageMetadata" + }, + { + "$ref": "#/definitions/ConanLockMetadata" + }, + { + "$ref": "#/definitions/ConanMetadata" + }, + { + "$ref": "#/definitions/DartPubMetadata" + }, + { + "$ref": "#/definitions/DotnetDepsMetadata" + }, + { + "$ref": "#/definitions/DpkgMetadata" + }, + { + "$ref": "#/definitions/GemMetadata" + }, + { + "$ref": "#/definitions/GolangBinMetadata" + }, + { + "$ref": "#/definitions/HackageMetadata" + }, + { + "$ref": "#/definitions/JavaMetadata" + }, + { + "$ref": "#/definitions/KbPackageMetadata" + }, + { + "$ref": "#/definitions/NpmPackageJSONMetadata" + }, + { + "$ref": "#/definitions/PhpComposerJSONMetadata" + }, + { + "$ref": "#/definitions/PortageMetadata" + }, + { + "$ref": "#/definitions/PythonPackageMetadata" + }, + { + "$ref": "#/definitions/RpmMetadata" + } + ] + } + }, + "additionalProperties": true, + "type": "object" + }, + "PhpComposerAuthors": { + "required": [ + "name" + ], + "properties": { + "name": { + "type": "string" + }, + "email": { + "type": "string" + }, + "homepage": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PhpComposerExternalReference": { + "required": [ + "type", + "url", + "reference" + ], + "properties": { + "type": { + "type": "string" + }, + "url": { + "type": "string" + }, + "reference": { + "type": "string" + }, + "shasum": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PhpComposerJSONMetadata": { + "required": [ + "name", + "version", + "source", + "dist" + ], + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "source": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/PhpComposerExternalReference" + }, + "dist": { + "$ref": "#/definitions/PhpComposerExternalReference" + }, + "require": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, + "provide": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, + "require-dev": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, + "suggest": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + }, + "type": { + "type": "string" + }, + "notification-url": { + "type": "string" + }, + "bin": { + "items": { + "type": "string" + }, + "type": "array" + }, + "license": { + "items": { + "type": "string" + }, + "type": "array" + }, + "authors": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/PhpComposerAuthors" + }, + "type": "array" + }, + "description": { + "type": "string" + }, + "homepage": { + "type": "string" + }, + "keywords": { + "items": { + "type": "string" + }, + "type": "array" + }, + "time": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PomParent": { + "required": [ + "groupId", + "artifactId", + "version" + ], + "properties": { + "groupId": { + "type": "string" + }, + "artifactId": { + "type": "string" + }, + "version": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PomProject": { + "required": [ + "path", + "groupId", + "artifactId", + "version", + "name" + ], + "properties": { + "path": { + "type": "string" + }, + "parent": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/PomParent" + }, + "groupId": { + "type": "string" + }, + "artifactId": { + "type": "string" + }, + "version": { + "type": "string" + }, + "name": { + "type": "string" + }, + "description": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PomProperties": { + "required": [ + "path", + "name", + "groupId", + "artifactId", + "version", + "extraFields" + ], + "properties": { + "path": { + "type": "string" + }, + "name": { + "type": "string" + }, + "groupId": { + "type": "string" + }, + "artifactId": { + "type": "string" + }, + "version": { + "type": "string" + }, + "extraFields": { + "patternProperties": { + ".*": { + "type": "string" + } + }, + "type": "object" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PortageFileRecord": { + "required": [ + "path" + ], + "properties": { + "path": { + "type": "string" + }, + "digest": { + "$ref": "#/definitions/Digest" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PortageMetadata": { + "required": [ + "package", + "version", + "installedSize", + "files" + ], + "properties": { + "package": { + "type": "string" + }, + "version": { + "type": "string" + }, + "installedSize": { + "type": "integer" + }, + "files": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/PortageFileRecord" + }, + "type": "array" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PythonDirectURLOriginInfo": { + "required": [ + "url" + ], + "properties": { + "url": { + "type": "string" + }, + "commitId": { + "type": "string" + }, + "vcs": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PythonFileDigest": { + "required": [ + "algorithm", + "value" + ], + "properties": { + "algorithm": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PythonFileRecord": { + "required": [ + "path" + ], + "properties": { + "path": { + "type": "string" + }, + "digest": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/PythonFileDigest" + }, + "size": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "PythonPackageMetadata": { + "required": [ + "name", + "version", + "license", + "author", + "authorEmail", + "platform", + "sitePackagesRootPath" + ], + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "license": { + "type": "string" + }, + "author": { + "type": "string" + }, + "authorEmail": { + "type": "string" + }, + "platform": { + "type": "string" + }, + "files": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/PythonFileRecord" + }, + "type": "array" + }, + "sitePackagesRootPath": { + "type": "string" + }, + "topLevelPackages": { + "items": { + "type": "string" + }, + "type": "array" + }, + "directUrlOrigin": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/PythonDirectURLOriginInfo" + } + }, + "additionalProperties": true, + "type": "object" + }, + "Relationship": { + "required": [ + "parent", + "child", + "type" + ], + "properties": { + "parent": { + "type": "string" + }, + "child": { + "type": "string" + }, + "type": { + "type": "string" + }, + "metadata": { + "additionalProperties": true + } + }, + "additionalProperties": true, + "type": "object" + }, + "RpmMetadata": { + "required": [ + "name", + "version", + "epoch", + "architecture", + "release", + "sourceRpm", + "size", + "license", + "vendor", + "modularityLabel", + "files" + ], + "properties": { + "name": { + "type": "string" + }, + "version": { + "type": "string" + }, + "epoch": { + "oneOf": [ + { + "type": "integer" + }, + { + "type": "null" + } + ] + }, + "architecture": { + "type": "string" + }, + "release": { + "type": "string" + }, + "sourceRpm": { + "type": "string" + }, + "size": { + "type": "integer" + }, + "license": { + "type": "string" + }, + "vendor": { + "type": "string" + }, + "modularityLabel": { + "type": "string" + }, + "files": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/RpmdbFileRecord" + }, + "type": "array" + } + }, + "additionalProperties": true, + "type": "object" + }, + "RpmdbFileRecord": { + "required": [ + "path", + "mode", + "size", + "digest", + "userName", + "groupName", + "flags" + ], + "properties": { + "path": { + "type": "string" + }, + "mode": { + "type": "integer" + }, + "size": { + "type": "integer" + }, + "digest": { + "$ref": "#/definitions/Digest" + }, + "userName": { + "type": "string" + }, + "groupName": { + "type": "string" + }, + "flags": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "Schema": { + "required": [ + "version", + "url" + ], + "properties": { + "version": { + "type": "string" + }, + "url": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "SearchResult": { + "required": [ + "classification", + "lineNumber", + "lineOffset", + "seekPosition", + "length" + ], + "properties": { + "classification": { + "type": "string" + }, + "lineNumber": { + "type": "integer" + }, + "lineOffset": { + "type": "integer" + }, + "seekPosition": { + "type": "integer" + }, + "length": { + "type": "integer" + }, + "value": { + "type": "string" + } + }, + "additionalProperties": true, + "type": "object" + }, + "Secrets": { + "required": [ + "location", + "secrets" + ], + "properties": { + "location": { + "$ref": "#/definitions/Coordinates" + }, + "secrets": { + "items": { + "$schema": "http://json-schema.org/draft-04/schema#", + "$ref": "#/definitions/SearchResult" + }, + "type": "array" + } + }, + "additionalProperties": true, + "type": "object" + }, + "Source": { + "required": [ + "type", + "target" + ], + "properties": { + "type": { + "type": "string" + }, + "target": { + "additionalProperties": true + } + }, + "additionalProperties": true, + "type": "object" + } + } +} diff --git a/syft/formats/syftjson/model/package.go b/syft/formats/syftjson/model/package.go index 7249af296e01..b2fd9190322e 100644 --- a/syft/formats/syftjson/model/package.go +++ b/syft/formats/syftjson/model/package.go @@ -163,12 +163,18 @@ func unpackMetadata(p *Package, unpacker packageMetadataUnpacker) error { return err } p.Metadata = payload - case pkg.ConanaMetadataType: + case pkg.ConanMetadataType: var payload pkg.ConanMetadata if err := json.Unmarshal(unpacker.Metadata, &payload); err != nil { return err } p.Metadata = payload + case pkg.ConanLockMetadataType: + var payload pkg.ConanLockMetadata + if err := json.Unmarshal(unpacker.Metadata, &payload); err != nil { + return err + } + p.Metadata = payload case pkg.DotnetDepsMetadataType: var payload pkg.DotnetDepsMetadata if err := json.Unmarshal(unpacker.Metadata, &payload); err != nil { diff --git a/syft/formats/syftjson/test-fixtures/snapshot/TestDirectoryEncoder.golden b/syft/formats/syftjson/test-fixtures/snapshot/TestDirectoryEncoder.golden index 19a8f5044f14..f7118ea6d234 100644 --- a/syft/formats/syftjson/test-fixtures/snapshot/TestDirectoryEncoder.golden +++ b/syft/formats/syftjson/test-fixtures/snapshot/TestDirectoryEncoder.golden @@ -88,7 +88,7 @@ } }, "schema": { - "version": "3.3.2", - "url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.3.2.json" + "version": "4.0.0", + "url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-4.0.0.json" } } diff --git a/syft/formats/syftjson/test-fixtures/snapshot/TestEncodeFullJSONDocument.golden b/syft/formats/syftjson/test-fixtures/snapshot/TestEncodeFullJSONDocument.golden index 2b474a2810db..664b82f9cb5e 100644 --- a/syft/formats/syftjson/test-fixtures/snapshot/TestEncodeFullJSONDocument.golden +++ b/syft/formats/syftjson/test-fixtures/snapshot/TestEncodeFullJSONDocument.golden @@ -184,7 +184,7 @@ } }, "schema": { - "version": "3.3.2", - "url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.3.2.json" + "version": "4.0.0", + "url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-4.0.0.json" } } diff --git a/syft/formats/syftjson/test-fixtures/snapshot/TestImageEncoder.golden b/syft/formats/syftjson/test-fixtures/snapshot/TestImageEncoder.golden index ae948591c5ff..a7dda4af6cb0 100644 --- a/syft/formats/syftjson/test-fixtures/snapshot/TestImageEncoder.golden +++ b/syft/formats/syftjson/test-fixtures/snapshot/TestImageEncoder.golden @@ -111,7 +111,7 @@ } }, "schema": { - "version": "3.3.2", - "url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-3.3.2.json" + "version": "4.0.0", + "url": "https://raw.githubusercontent.com/anchore/syft/main/schema/json/schema-4.0.0.json" } } diff --git a/syft/pkg/cataloger/cpp/cataloger.go b/syft/pkg/cataloger/cpp/cataloger.go index a8f02877d114..0fb822259b07 100644 --- a/syft/pkg/cataloger/cpp/cataloger.go +++ b/syft/pkg/cataloger/cpp/cataloger.go @@ -8,6 +8,7 @@ import ( func NewConanfileCataloger() *common.GenericCataloger { globParsers := map[string]common.ParserFn{ "**/conanfile.txt": parseConanfile, + "**/conan.lock": parseConanlock, } return common.NewGenericCataloger(nil, globParsers, "conan-cataloger") diff --git a/syft/pkg/cataloger/cpp/parse_conanfile.go b/syft/pkg/cataloger/cpp/parse_conanfile.go index d3a6481bd39f..e3c70a90d40f 100644 --- a/syft/pkg/cataloger/cpp/parse_conanfile.go +++ b/syft/pkg/cataloger/cpp/parse_conanfile.go @@ -40,21 +40,23 @@ func parseConanfile(_ string, reader io.Reader) ([]*pkg.Package, []artifact.Rela inRequirements = false } - splits := strings.Split(strings.TrimSpace(line), "/") - if len(splits) < 2 || !inRequirements { + m := pkg.ConanMetadata{ + Ref: strings.Trim(line, "\n"), + } + + pkgName, pkgVersion := m.NameAndVersion() + + if pkgName == "" || pkgVersion == "" || !inRequirements { continue } - pkgName, pkgVersion := splits[0], splits[1] + pkgs = append(pkgs, &pkg.Package{ Name: pkgName, Version: pkgVersion, Language: pkg.CPP, Type: pkg.ConanPkg, - MetadataType: pkg.ConanaMetadataType, - Metadata: pkg.ConanMetadata{ - Name: pkgName, - Version: pkgVersion, - }, + MetadataType: pkg.ConanMetadataType, + Metadata: m, }) } } diff --git a/syft/pkg/cataloger/cpp/parse_conanfile_test.go b/syft/pkg/cataloger/cpp/parse_conanfile_test.go index 4500f0bd8dbd..253fc6b0a939 100644 --- a/syft/pkg/cataloger/cpp/parse_conanfile_test.go +++ b/syft/pkg/cataloger/cpp/parse_conanfile_test.go @@ -16,10 +16,9 @@ func TestParseConanfile(t *testing.T) { Version: "2.13.8", Language: pkg.CPP, Type: pkg.ConanPkg, - MetadataType: pkg.ConanaMetadataType, + MetadataType: pkg.ConanMetadataType, Metadata: pkg.ConanMetadata{ - Name: "catch2", - Version: "2.13.8", + Ref: "catch2/2.13.8", }, }, { @@ -27,10 +26,9 @@ func TestParseConanfile(t *testing.T) { Version: "0.6.3", Language: pkg.CPP, Type: pkg.ConanPkg, - MetadataType: pkg.ConanaMetadataType, + MetadataType: pkg.ConanMetadataType, Metadata: pkg.ConanMetadata{ - Name: "docopt.cpp", - Version: "0.6.3", + Ref: "docopt.cpp/0.6.3", }, }, { @@ -38,10 +36,9 @@ func TestParseConanfile(t *testing.T) { Version: "8.1.1", Language: pkg.CPP, Type: pkg.ConanPkg, - MetadataType: pkg.ConanaMetadataType, + MetadataType: pkg.ConanMetadataType, Metadata: pkg.ConanMetadata{ - Name: "fmt", - Version: "8.1.1", + Ref: "fmt/8.1.1", }, }, { @@ -49,10 +46,9 @@ func TestParseConanfile(t *testing.T) { Version: "1.9.2", Language: pkg.CPP, Type: pkg.ConanPkg, - MetadataType: pkg.ConanaMetadataType, + MetadataType: pkg.ConanMetadataType, Metadata: pkg.ConanMetadata{ - Name: "spdlog", - Version: "1.9.2", + Ref: "spdlog/1.9.2", }, }, { @@ -60,10 +56,9 @@ func TestParseConanfile(t *testing.T) { Version: "2.0.20", Language: pkg.CPP, Type: pkg.ConanPkg, - MetadataType: pkg.ConanaMetadataType, + MetadataType: pkg.ConanMetadataType, Metadata: pkg.ConanMetadata{ - Name: "sdl", - Version: "2.0.20", + Ref: "sdl/2.0.20", }, }, { @@ -71,10 +66,9 @@ func TestParseConanfile(t *testing.T) { Version: "1.3.8", Language: pkg.CPP, Type: pkg.ConanPkg, - MetadataType: pkg.ConanaMetadataType, + MetadataType: pkg.ConanMetadataType, Metadata: pkg.ConanMetadata{ - Name: "fltk", - Version: "1.3.8", + Ref: "fltk/1.3.8", }, }, } diff --git a/syft/pkg/cataloger/cpp/parse_conanlock.go b/syft/pkg/cataloger/cpp/parse_conanlock.go new file mode 100644 index 000000000000..85fcf1c035fe --- /dev/null +++ b/syft/pkg/cataloger/cpp/parse_conanlock.go @@ -0,0 +1,82 @@ +package cpp + +import ( + "encoding/json" + "io" + "strings" + + "github.com/anchore/syft/syft/artifact" + "github.com/anchore/syft/syft/pkg" + "github.com/anchore/syft/syft/pkg/cataloger/common" +) + +// integrity check +var _ common.ParserFn = parseConanlock + +type conanLock struct { + GraphLock struct { + Nodes map[string]struct { + Ref string `json:"ref"` + PackageID string `json:"package_id"` + Context string `json:"context"` + Prev string `json:"prev"` + Requires string `json:"requires"` + BuildRequires string `json:"build_requires"` + PythonRequires string `json:"py_requires"` + Options string `json:"options"` + Path string `json:"path"` + } `json:"nodes"` + } `json:"graph_lock"` + Version string `json:"version"` + ProfileHost string `json:"profile_host"` +} + +// parseConanlock is a parser function for conan.lock contents, returning all packages discovered. +func parseConanlock(_ string, reader io.Reader) ([]*pkg.Package, []artifact.Relationship, error) { + pkgs := []*pkg.Package{} + var cl conanLock + if err := json.NewDecoder(reader).Decode(&cl); err != nil { + return nil, nil, err + } + for _, node := range cl.GraphLock.Nodes { + metadata := pkg.ConanLockMetadata{ + Ref: node.Ref, + Options: parseOptions(node.Options), + Path: node.Path, + Context: node.Context, + } + + pkgName, pkgVersion := metadata.NameAndVersion() + if pkgName == "" || pkgVersion == "" { + continue + } + + pkgs = append(pkgs, &pkg.Package{ + Name: pkgName, + Version: pkgVersion, + Language: pkg.CPP, + Type: pkg.ConanPkg, + MetadataType: pkg.ConanLockMetadataType, + Metadata: metadata, + }) + } + + return pkgs, nil, nil +} + +func parseOptions(options string) map[string]string { + o := make(map[string]string) + if len(options) == 0 { + return nil + } + + kvps := strings.Split(options, "\n") + for _, kvp := range kvps { + kv := strings.Split(kvp, "=") + if len(kv) == 2 { + o[kv[0]] = kv[1] + } + } + + return o +} diff --git a/syft/pkg/cataloger/cpp/parse_conanlock_test.go b/syft/pkg/cataloger/cpp/parse_conanlock_test.go new file mode 100644 index 000000000000..ffb2b7c84b61 --- /dev/null +++ b/syft/pkg/cataloger/cpp/parse_conanlock_test.go @@ -0,0 +1,47 @@ +package cpp + +import ( + "os" + "testing" + + "github.com/go-test/deep" + + "github.com/anchore/syft/syft/pkg" +) + +func TestParseConanlock(t *testing.T) { + expected := []*pkg.Package{ + { + Name: "zlib", + Version: "1.2.12", + Language: pkg.CPP, + Type: pkg.ConanPkg, + MetadataType: pkg.ConanLockMetadataType, + Metadata: pkg.ConanLockMetadata{ + Ref: "zlib/1.2.12", + Options: map[string]string{ + "fPIC": "True", + "shared": "False", + }, + Path: "all/conanfile.py", + Context: "host", + }, + }, + } + + fixture, err := os.Open("test-fixtures/conan.lock") + if err != nil { + t.Fatalf("failed to open fixture: %+v", err) + } + + // TODO: no relationships are under test yet + actual, _, err := parseConanlock(fixture.Name(), fixture) + if err != nil { + t.Error(err) + } + + differences := deep.Equal(expected, actual) + if differences != nil { + t.Errorf("returned package list differed from expectation: %+v", differences) + } +} diff --git a/syft/pkg/cataloger/cpp/test-fixtures/conan.lock b/syft/pkg/cataloger/cpp/test-fixtures/conan.lock new file mode 100644 index 000000000000..b63008d90bba --- /dev/null +++ b/syft/pkg/cataloger/cpp/test-fixtures/conan.lock @@ -0,0 +1,15 @@ +{ + "graph_lock": { + "nodes": { + "0": { + "ref": "zlib/1.2.12", + "options": "fPIC=True\nshared=False", + "path": "all/conanfile.py", + "context": "host" + } + }, + "revisions_enabled": false + }, + "version": "0.4", + "profile_host": "[settings]\narch=x86_64\narch_build=x86_64\nbuild_type=Release\ncompiler=gcc\ncompiler.libcxx=libstdc++\ncompiler.version=9\nos=Linux\nos_build=Linux\n[options]\n[build_requires]\n[env]\n" +} diff --git a/syft/pkg/conan_lock_metadata.go b/syft/pkg/conan_lock_metadata.go new file mode 100644 index 000000000000..401c6748131b --- /dev/null +++ b/syft/pkg/conan_lock_metadata.go @@ -0,0 +1,50 @@ +package pkg + +import ( + "strings" + + "github.com/anchore/packageurl-go" + "github.com/anchore/syft/syft/linux" +) + +type ConanLockMetadata struct { + Ref string `json:"ref"` + PackageID string `json:"package_id,omitempty"` + Prev string `json:"prev,omitempty"` + Requires string `json:"requires,omitempty"` + BuildRequires string `json:"build_requires,omitempty"` + PythonRequires string `json:"py_requires,omitempty"` + Options map[string]string `json:"options,omitempty"` + Path string `json:"path,omitempty"` + Context string `json:"context,omitempty"` +} + +func (m ConanLockMetadata) PackageURL(_ *linux.Release) string { + var qualifiers packageurl.Qualifiers + + name, version := m.NameAndVersion() + + return packageurl.NewPackageURL( + packageurl.TypeConan, + "", + name, + version, + qualifiers, + "", + ).ToString() +} + +// NameAndVersion returns the name and version of the package. +// If ref is not in the format of "name/version@user/channel", then an empty string is returned for both. +func (m ConanLockMetadata) NameAndVersion() (name, version string) { + if len(m.Ref) < 1 { + return name, version + } + + splits := strings.Split(strings.Split(m.Ref, "@")[0], "/") + if len(splits) < 2 { + return name, version + } + + return splits[0], splits[1] +} diff --git a/syft/pkg/conan_lock_metadata_test.go b/syft/pkg/conan_lock_metadata_test.go new file mode 100644 index 000000000000..9c215d6ac3ba --- /dev/null +++ b/syft/pkg/conan_lock_metadata_test.go @@ -0,0 +1,27 @@ +package pkg + +import "testing" + +func TestConanLockMetadata_PackageURL(t *testing.T) { + tests := []struct { + name string + m ConanLockMetadata + want string + }{ + { + name: "happy path", + m: ConanLockMetadata{ + Ref: "farmerbrown5/3.13.9", + }, + want: "pkg:conan/farmerbrown5@3.13.9", + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if got := test.m.PackageURL(nil); got != test.want { + t.Errorf("ConanMetadata.PackageURL() = %v, want %v", got, test.want) + } + }) + } +} diff --git a/syft/pkg/conan_metadata.go b/syft/pkg/conan_metadata.go index 9717e8f3d8f6..1e287ba735b4 100644 --- a/syft/pkg/conan_metadata.go +++ b/syft/pkg/conan_metadata.go @@ -1,24 +1,44 @@ package pkg import ( + "strings" + "github.com/anchore/packageurl-go" "github.com/anchore/syft/syft/linux" ) type ConanMetadata struct { - Name string `mapstructure:"name" json:"name"` - Version string `mapstructure:"version" json:"version"` + Ref string `mapstructure:"ref" json:"ref"` } func (m ConanMetadata) PackageURL(_ *linux.Release) string { var qualifiers packageurl.Qualifiers + name, version := m.NameAndVersion() + return packageurl.NewPackageURL( packageurl.TypeConan, "", - m.Name, - m.Version, + name, + version, qualifiers, "", ).ToString() } + +// NameAndVersion tries to return the name and version of a cpp package +// given the ref format: pkg/version +// it returns empty strings if ref is empty or parsing is unsuccessful +func (m ConanMetadata) NameAndVersion() (name, version string) { + if len(m.Ref) < 1 { + return name, version + } + + splits := strings.Split(strings.TrimSpace(m.Ref), "/") + + if len(splits) < 2 { + return name, version + } + + return splits[0], splits[1] +} diff --git a/syft/pkg/conan_metadata_test.go b/syft/pkg/conan_metadata_test.go new file mode 100644 index 000000000000..7bf13cf41017 --- /dev/null +++ b/syft/pkg/conan_metadata_test.go @@ -0,0 +1,27 @@ +package pkg + +import "testing" + +func TestConanMetadata_PackageURL(t *testing.T) { + tests := []struct { + name string + m ConanMetadata + want string + }{ + { + name: "happy path", + m: ConanMetadata{ + Ref: "catch2/2.13.8", + }, + want: "pkg:conan/catch2@2.13.8", + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + if got := test.m.PackageURL(nil); got != test.want { + t.Errorf("ConanMetadata.PackageURL() = %v, want %v", got, test.want) + } + }) + } +} diff --git a/syft/pkg/metadata.go b/syft/pkg/metadata.go index 99e8d0839fa2..6a93f78723f8 100644 --- a/syft/pkg/metadata.go +++ b/syft/pkg/metadata.go @@ -26,7 +26,8 @@ const ( GolangBinMetadataType MetadataType = "GolangBinMetadata" PhpComposerJSONMetadataType MetadataType = "PhpComposerJsonMetadata" CocoapodsMetadataType MetadataType = "CocoapodsMetadataType" - ConanaMetadataType MetadataType = "ConanaMetadataType" + ConanMetadataType MetadataType = "ConanMetadataType" + ConanLockMetadataType MetadataType = "ConanLockMetadataType" PortageMetadataType MetadataType = "PortageMetadata" HackageMetadataType MetadataType = "HackageMetadataType" ) @@ -47,7 +48,8 @@ var AllMetadataTypes = []MetadataType{ GolangBinMetadataType, PhpComposerJSONMetadataType, CocoapodsMetadataType, - ConanaMetadataType, + ConanMetadataType, + ConanLockMetadataType, PortageMetadataType, HackageMetadataType, } @@ -68,7 +70,8 @@ var MetadataTypeByName = map[MetadataType]reflect.Type{ GolangBinMetadataType: reflect.TypeOf(GolangBinMetadata{}), PhpComposerJSONMetadataType: reflect.TypeOf(PhpComposerJSONMetadata{}), CocoapodsMetadataType: reflect.TypeOf(CocoapodsMetadata{}), - ConanaMetadataType: reflect.TypeOf(ConanMetadata{}), + ConanMetadataType: reflect.TypeOf(ConanMetadata{}), + ConanLockMetadataType: reflect.TypeOf(ConanLockMetadata{}), PortageMetadataType: reflect.TypeOf(PortageMetadata{}), HackageMetadataType: reflect.TypeOf(HackageMetadata{}), } diff --git a/syft/pkg/url_test.go b/syft/pkg/url_test.go index 03b689d2d64a..e2a01af91a4e 100644 --- a/syft/pkg/url_test.go +++ b/syft/pkg/url_test.go @@ -239,14 +239,29 @@ func TestPackageURL(t *testing.T) { Version: "2.13.8", Type: ConanPkg, Language: CPP, - MetadataType: ConanaMetadataType, + MetadataType: ConanMetadataType, Metadata: ConanMetadata{ - Name: "catch2", - Version: "2.13.8", + Ref: "catch2/2.13.8", }, }, expected: "pkg:conan/catch2@2.13.8", }, + // note both Ref should parse the same for conan ecosystem + { + name: "conan lock", + pkg: Package{ + Name: "catch2", + Version: "2.13.8", + Type: ConanPkg, + Language: CPP, + MetadataType: ConanLockMetadataType, + Metadata: ConanLockMetadata{ + Ref: "catch2/2.13.8", + }, + }, + expected: "pkg:conan/catch2@2.13.8", + }, + { name: "hackage", pkg: Package{