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

packages lib support test #7

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

packages lib support test #7

wants to merge 7 commits into from

Conversation

houdini91
Copy link

@houdini91 houdini91 commented Apr 17, 2022

Added a patch for syft to export packages command as library.

Library exported function

// LibPackagesExec run packages command as a library
// userInput: target
// cfg: syft configuration structure
// l: logger to attach to, nil  for default syft logger
// enable_ui: enable disable ui output
// Function return sbom or errors.
func LibPackagesExec(userInput string, cfg *config.Application, l logger.Logger, enable_ui bool) (*sbom.SBOM, error)```

Run library example
var cfg syft.Application
err := yaml.Unmarshal([]byte(SOME_CONFIG), &cfg)
if err != nil {
	return err
}

# Call packages with config
sbom, err := cmd.LibPackagesExec("busybox:latest", &cfg, nil, true)

    # Encode sbom to any supported output.
b, err := syft.Encode(*sbom, syft.FormatByID(syft.JSONFormatID))
if err != nil {
	os.Exit(1)
}

fmt.Println("Json output:", string(b))

@houdini91 houdini91 force-pushed the patch/packages_lib branch from 5cf3da8 to 85d5a6b Compare April 17, 2022 10:05
Signed-off-by: houdini91 <mdstrauss91@gmail.com>
Signed-off-by: houdini91 <mdstrauss91@gmail.com>
Signed-off-by: houdini91 <mdstrauss91@gmail.com>
@houdini91 houdini91 force-pushed the patch/packages_lib branch from 0a33c30 to c277661 Compare April 17, 2022 11:00
@github-actions
Copy link

github-actions bot commented Apr 17, 2022

Benchmark Test Results

Benchmark results from the latest changes vs base branch
name                                                       time/op
ImagePackageCatalogers/ruby-gemspec-cataloger-2            1.10ms ± 3%
ImagePackageCatalogers/python-package-cataloger-2          2.88ms ± 0%
ImagePackageCatalogers/php-composer-installed-cataloger-2   908µs ± 5%
ImagePackageCatalogers/javascript-package-cataloger-2       604µs ± 4%
ImagePackageCatalogers/dpkgdb-cataloger-2                   700µs ± 1%
ImagePackageCatalogers/rpmdb-cataloger-2                    633µs ± 2%
ImagePackageCatalogers/java-cataloger-2                    13.0ms ± 3%
ImagePackageCatalogers/apkdb-cataloger-2                   1.12ms ± 1%
ImagePackageCatalogers/go-module-binary-cataloger-2        1.94µs ± 1%

name                                                       alloc/op
ImagePackageCatalogers/ruby-gemspec-cataloger-2             184kB ± 0%
ImagePackageCatalogers/python-package-cataloger-2           896kB ± 0%
ImagePackageCatalogers/php-composer-installed-cataloger-2   196kB ± 0%
ImagePackageCatalogers/javascript-package-cataloger-2       140kB ± 0%
ImagePackageCatalogers/dpkgdb-cataloger-2                   174kB ± 0%
ImagePackageCatalogers/rpmdb-cataloger-2                    163kB ± 0%
ImagePackageCatalogers/java-cataloger-2                    3.30MB ± 0%
ImagePackageCatalogers/apkdb-cataloger-2                   1.24MB ± 0%
ImagePackageCatalogers/go-module-binary-cataloger-2          672B ± 0%

name                                                       allocs/op
ImagePackageCatalogers/ruby-gemspec-cataloger-2             3.66k ± 0%
ImagePackageCatalogers/python-package-cataloger-2           14.8k ± 0%
ImagePackageCatalogers/php-composer-installed-cataloger-2   4.94k ± 0%
ImagePackageCatalogers/javascript-package-cataloger-2       2.72k ± 0%
ImagePackageCatalogers/dpkgdb-cataloger-2                   3.93k ± 0%
ImagePackageCatalogers/rpmdb-cataloger-2                    4.01k ± 0%
ImagePackageCatalogers/java-cataloger-2                     52.2k ± 0%
ImagePackageCatalogers/apkdb-cataloger-2                    4.81k ± 0%
ImagePackageCatalogers/go-module-binary-cataloger-2          15.0 ± 0%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant