Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo.lock file support #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Supports:
- Python
- Ruby
- Java
- Rust

Dependencies are printed in PackageURL format.

Expand Down
2 changes: 2 additions & 0 deletions dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func GetLanguageStr(bm Bitmask) string {
return "pypi"
} else if bm&LangRuby != 0 {
return "gem"
} else if bm&LangRust != 0 {
return "cargo"
}
return "unknown"
}
13 changes: 12 additions & 1 deletion deplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
LangNodeJS
LangPython
LangRuby
LangRust
)

func init() {
Expand Down Expand Up @@ -70,6 +71,7 @@ var defaultIgnore []string = []string{
"scripts",
"test",
"test_scripts",
"testing",
"tests",
"vendor",
".git",
Expand Down Expand Up @@ -166,6 +168,15 @@ func getDeps(fullPath string, ignoreDirs []string) ([]Dependency, Bitmask, error
Files: []string{},
})
}
case "Cargo.lock":
pkgs, err := scan.GetCrates(path)
if err != nil {
// ignore error
log.Debugf("failed to scan rust crates: %s", path)
return nil
}

discovered = addPackagesToDeps(discovered, pkgs, LangRust)
default:
ext := filepath.Ext(filename)
// java
Expand Down Expand Up @@ -221,7 +232,7 @@ func getDeps(fullPath string, ignoreDirs []string) ([]Dependency, Bitmask, error
path = strings.Replace(path, "Gemfile.lock", "Gemfile", 1)

// comparisons here are against the full filepath, so will not match if
// these filesames are found in subdirectories, only the top level
// these filenames are found in subdirectories, only the top level
switch path {
case goPkgPath:
pkgs, err := scan.GetGoPkgDeps(path)
Expand Down
289 changes: 158 additions & 131 deletions deplist_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,126 +151,126 @@ func BuildWant() []Dependency {
"d3-interpolate",
}

rubySet := []string{
"concurrent-ruby",
"lru_redux",
"zeitwerk",
"async",
"fluent-plugin-systemd",
"http-parser",
"ltsv",
"public_suffix",
"faraday-multipart",
"fluent-config-regexp-type",
"recursive-open-struct",
"unf_ext",
"aws-eventstream",
"webrick",
"faraday-em_http",
"fluentd",
"yajl-ruby",
"fluent-plugin-elasticsearch",
"faraday-patron",
"mini_mime",
"tzinfo",
"connection_pool",
"fluent-plugin-kubernetes_metadata_filter",
"fluent-plugin-prometheus",
"nio4r",
"oj",
"openid_connect",
"rack",
"sigdump",
"digest-crc",
"ethon",
"multipart-post",
"addressable",
"faraday-net_http_persistent",
"rack-oauth2",
"excon",
"fluent-plugin-label-router",
"bindata",
"fluent-plugin-record-modifier",
"http",
"systemd-journal",
"faraday-retry",
"ruby2_keywords",
"mime-types",
"timers",
"unf",
"fluent-plugin-detect-exceptions",
"jsonpath",
"rake",
"validate_email",
"aws-sdk-cloudwatchlogs",
"jmespath",
"prometheus-client",
"protocol-http1",
"ffi",
"fluent-plugin-grafana-loki",
"bigdecimal",
"protocol-http",
"aws-partitions",
"faraday-httpclient",
"fluent-plugin-multi-format-parser",
"http_parser.rb",
"protocol-http2",
"rest-client",
"activesupport",
"ffi-compiler",
"fluent-plugin-splunk-hec",
"json-jwt",
"msgpack",
"protocol-hpack",
"strptime",
"validate_url",
"faraday",
"async-pool",
"faraday-net_http",
"fluent-plugin-concat",
"fluent-plugin-kafka",
"multi_json",
"net-http-persistent",
"uuidtools",
"activemodel",
"elasticsearch-transport",
"mail",
"ruby-kafka",
"serverengine",
"tzinfo-data",
"webfinger",
"aws-sigv4",
"elasticsearch-api",
"fiber-local",
"fluent-plugin-remote-syslog",
"attr_required",
"http-form_data",
"syslog_protocol",
"faraday-em_synchrony",
"httpclient",
"fluent-mixin-config-placeholders",
"fluent-plugin-cloudwatch-logs",
"i18n",
"async-io",
"elasticsearch",
"http-cookie",
"kubeclient",
"minitest",
"aes_key_wrap",
"mime-types-data",
"netrc",
"console",
"cool.io",
"domain_name",
"async-http",
"http-accept",
"traces",
"typhoeus",
"faraday-rack",
"faraday-excon",
"fluent-plugin-rewrite-tag-filter",
"swd",
"aws-sdk-core",
rubySet := []Dependency{
{DepType: LangRuby, Path: "concurrent-ruby"},
{DepType: LangRuby, Path: "lru_redux"},
{DepType: LangRuby, Path: "zeitwerk"},
{DepType: LangRuby, Path: "async"},
{DepType: LangRuby, Path: "fluent-plugin-systemd"},
{DepType: LangRuby, Path: "http-parser"},
{DepType: LangRuby, Path: "ltsv"},
{DepType: LangRuby, Path: "public_suffix"},
{DepType: LangRuby, Path: "faraday-multipart"},
{DepType: LangRuby, Path: "fluent-config-regexp-type"},
{DepType: LangRuby, Path: "recursive-open-struct"},
{DepType: LangRuby, Path: "unf_ext"},
{DepType: LangRuby, Path: "aws-eventstream"},
{DepType: LangRuby, Path: "webrick"},
{DepType: LangRuby, Path: "faraday-em_http"},
{DepType: LangRuby, Path: "fluentd"},
{DepType: LangRuby, Path: "yajl-ruby"},
{DepType: LangRuby, Path: "fluent-plugin-elasticsearch"},
{DepType: LangRuby, Path: "faraday-patron"},
{DepType: LangRuby, Path: "mini_mime"},
{DepType: LangRuby, Path: "tzinfo"},
{DepType: LangRuby, Path: "connection_pool"},
{DepType: LangRuby, Path: "fluent-plugin-kubernetes_metadata_filter"},
{DepType: LangRuby, Path: "fluent-plugin-prometheus"},
{DepType: LangRuby, Path: "nio4r"},
{DepType: LangRuby, Path: "oj"},
{DepType: LangRuby, Path: "openid_connect"},
{DepType: LangRuby, Path: "rack"},
{DepType: LangRuby, Path: "sigdump"},
{DepType: LangRuby, Path: "digest-crc"},
{DepType: LangRuby, Path: "ethon"},
{DepType: LangRuby, Path: "multipart-post"},
{DepType: LangRuby, Path: "addressable"},
{DepType: LangRuby, Path: "faraday-net_http_persistent"},
{DepType: LangRuby, Path: "rack-oauth2"},
{DepType: LangRuby, Path: "excon"},
{DepType: LangRuby, Path: "fluent-plugin-label-router"},
{DepType: LangRuby, Path: "bindata"},
{DepType: LangRuby, Path: "fluent-plugin-record-modifier"},
{DepType: LangRuby, Path: "http"},
{DepType: LangRuby, Path: "systemd-journal"},
{DepType: LangRuby, Path: "faraday-retry"},
{DepType: LangRuby, Path: "ruby2_keywords"},
{DepType: LangRuby, Path: "mime-types"},
{DepType: LangRuby, Path: "timers"},
{DepType: LangRuby, Path: "unf"},
{DepType: LangRuby, Path: "fluent-plugin-detect-exceptions"},
{DepType: LangRuby, Path: "jsonpath"},
{DepType: LangRuby, Path: "rake"},
{DepType: LangRuby, Path: "validate_email"},
{DepType: LangRuby, Path: "aws-sdk-cloudwatchlogs"},
{DepType: LangRuby, Path: "jmespath"},
{DepType: LangRuby, Path: "prometheus-client"},
{DepType: LangRuby, Path: "protocol-http1"},
{DepType: LangRuby, Path: "ffi"},
{DepType: LangRuby, Path: "fluent-plugin-grafana-loki"},
{DepType: LangRuby, Path: "bigdecimal"},
{DepType: LangRuby, Path: "protocol-http"},
{DepType: LangRuby, Path: "aws-partitions"},
{DepType: LangRuby, Path: "faraday-httpclient"},
{DepType: LangRuby, Path: "fluent-plugin-multi-format-parser"},
{DepType: LangRuby, Path: "http_parser.rb"},
{DepType: LangRuby, Path: "protocol-http2"},
{DepType: LangRuby, Path: "rest-client"},
{DepType: LangRuby, Path: "activesupport"},
{DepType: LangRuby, Path: "ffi-compiler"},
{DepType: LangRuby, Path: "fluent-plugin-splunk-hec"},
{DepType: LangRuby, Path: "json-jwt"},
{DepType: LangRuby, Path: "msgpack"},
{DepType: LangRuby, Path: "protocol-hpack"},
{DepType: LangRuby, Path: "strptime"},
{DepType: LangRuby, Path: "validate_url"},
{DepType: LangRuby, Path: "faraday"},
{DepType: LangRuby, Path: "async-pool"},
{DepType: LangRuby, Path: "faraday-net_http"},
{DepType: LangRuby, Path: "fluent-plugin-concat"},
{DepType: LangRuby, Path: "fluent-plugin-kafka"},
{DepType: LangRuby, Path: "multi_json"},
{DepType: LangRuby, Path: "net-http-persistent"},
{DepType: LangRuby, Path: "uuidtools"},
{DepType: LangRuby, Path: "activemodel"},
{DepType: LangRuby, Path: "elasticsearch-transport"},
{DepType: LangRuby, Path: "mail"},
{DepType: LangRuby, Path: "ruby-kafka"},
{DepType: LangRuby, Path: "serverengine"},
{DepType: LangRuby, Path: "tzinfo-data"},
{DepType: LangRuby, Path: "webfinger"},
{DepType: LangRuby, Path: "aws-sigv4"},
{DepType: LangRuby, Path: "elasticsearch-api"},
{DepType: LangRuby, Path: "fiber-local"},
{DepType: LangRuby, Path: "fluent-plugin-remote-syslog"},
{DepType: LangRuby, Path: "attr_required"},
{DepType: LangRuby, Path: "http-form_data"},
{DepType: LangRuby, Path: "syslog_protocol"},
{DepType: LangRuby, Path: "faraday-em_synchrony"},
{DepType: LangRuby, Path: "httpclient"},
{DepType: LangRuby, Path: "fluent-mixin-config-placeholders"},
{DepType: LangRuby, Path: "fluent-plugin-cloudwatch-logs"},
{DepType: LangRuby, Path: "i18n"},
{DepType: LangRuby, Path: "async-io"},
{DepType: LangRuby, Path: "elasticsearch"},
{DepType: LangRuby, Path: "http-cookie"},
{DepType: LangRuby, Path: "kubeclient"},
{DepType: LangRuby, Path: "minitest"},
{DepType: LangRuby, Path: "aes_key_wrap"},
{DepType: LangRuby, Path: "mime-types-data"},
{DepType: LangRuby, Path: "netrc"},
{DepType: LangRuby, Path: "console"},
{DepType: LangRuby, Path: "cool.io"},
{DepType: LangRuby, Path: "domain_name"},
{DepType: LangRuby, Path: "async-http"},
{DepType: LangRuby, Path: "http-accept"},
{DepType: LangRuby, Path: "traces"},
{DepType: LangRuby, Path: "typhoeus"},
{DepType: LangRuby, Path: "faraday-rack"},
{DepType: LangRuby, Path: "faraday-excon"},
{DepType: LangRuby, Path: "fluent-plugin-rewrite-tag-filter"},
{DepType: LangRuby, Path: "swd"},
{DepType: LangRuby, Path: "aws-sdk-core"},
}

pythonSet := []Dependency{
Expand All @@ -290,6 +290,38 @@ func BuildWant() []Dependency {
{DepType: LangPython, Path: "m2crypto"},
}

rustSet := []Dependency{
{DepType: LangRust, Path: "cc", Version: "1.0.79"},
{DepType: LangRust, Path: "hermit-abi", Version: "0.3.1"},
{DepType: LangRust, Path: "num-traits", Version: "0.2.15"},
{DepType: LangRust, Path: "windows-sys", Version: "0.48.0"},
{DepType: LangRust, Path: "bitflags", Version: "1.3.2"},
{DepType: LangRust, Path: "io-uring", Version: "0.6.0"},
{DepType: LangRust, Path: "memmap2", Version: "0.5.10"},
{DepType: LangRust, Path: "rustix", Version: "0.37.15"},
{DepType: LangRust, Path: "autocfg", Version: "1.1.0"},
{DepType: LangRust, Path: "paste", Version: "1.0.12"},
{DepType: LangRust, Path: "virtio-bindings", Version: "0.2.0"},
{DepType: LangRust, Path: "windows_aarch64_gnullvm", Version: "0.48.0"},
{DepType: LangRust, Path: "libc", Version: "0.2.142"},
{DepType: LangRust, Path: "lazy_static", Version: "1.4.0"},
{DepType: LangRust, Path: "virtio-driver", Version: "0.5.0"},
{DepType: LangRust, Path: "windows-targets", Version: "0.48.0"},
{DepType: LangRust, Path: "errno", Version: "0.3.1"},
{DepType: LangRust, Path: "io-lifetimes", Version: "1.0.10"},
{DepType: LangRust, Path: "windows_aarch64_msvc", Version: "0.48.0"},
{DepType: LangRust, Path: "windows_i686_msvc", Version: "0.48.0"},
{DepType: LangRust, Path: "blkio", Version: "0.4.0"},
{DepType: LangRust, Path: "linux-raw-sys", Version: "0.3.4"},
{DepType: LangRust, Path: "windows_i686_gnu", Version: "0.48.0"},
{DepType: LangRust, Path: "errno-dragonfly", Version: "0.1.2"},
{DepType: LangRust, Path: "windows_x86_64_gnu", Version: "0.48.0"},
{DepType: LangRust, Path: "libblkio", Version: "1.3.0"},
{DepType: LangRust, Path: "windows_x86_64_gnullvm", Version: "0.48.0"},
{DepType: LangRust, Path: "windows_x86_64_msvc", Version: "0.48.0"},
{DepType: LangRust, Path: "pci-driver", Version: "0.1.3"},
}

for _, n := range golangPaths {
d := Dependency{
DepType: 1,
Expand Down Expand Up @@ -327,17 +359,11 @@ func BuildWant() []Dependency {
}
deps = append(deps, d)
}
deps = append(deps, Dependency{DepType: 2, Path: "com.amazonaws:aws-lambda-java-core:jar", Version: "1.0.0"}) // java

for _, n := range rubySet {
d := Dependency{
DepType: LangRuby,
Path: n,
}
deps = append(deps, d)
}

deps = append(deps, Dependency{DepType: 2, Path: "com.amazonaws:aws-lambda-java-core:jar", Version: "1.0.0"}) // java
deps = append(deps, rubySet...)
deps = append(deps, pythonSet...)
deps = append(deps, rustSet...)

return deps
}
Expand All @@ -358,8 +384,9 @@ func TestGetDeps(t *testing.T) {
return
}

if gotBitmask != 31 {
t.Errorf("GotBitmask() != 31; got: %d", gotBitmask)
expectedBitmask := 63
if gotBitmask != Bitmask(expectedBitmask) {
t.Errorf("GotBitmask() != %d; got: %d", expectedBitmask, gotBitmask)
}

gotMap := make(map[string]Dependency)
Expand Down
Loading
Loading