-
Couldn't load subscription status.
- Fork 701
Fix hang when running as a subprocess #484
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
9d23bcd
use named pipe bit on stdin as indicator for piped input
wagoodman a767987
ensure stdin is ignored when the CLI hints are present
wagoodman 8a1d154
add CLI test to cover subprocess integration behavior
wagoodman 371afc2
added test case for java regression
wagoodman ff06728
remove extra line in makefile
wagoodman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,82 +1,21 @@ | ||
| package pkg | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "errors" | ||
| "fmt" | ||
| "io" | ||
| "io/ioutil" | ||
| "os" | ||
|
|
||
| "github.com/anchore/grype/internal/log" | ||
|
|
||
| "github.com/anchore/grype/internal" | ||
| "github.com/anchore/stereoscope/pkg/image" | ||
| "github.com/anchore/syft/syft/source" | ||
| ) | ||
|
|
||
| var errDoesNotProvide = fmt.Errorf("cannot provide packages from the given source") | ||
|
|
||
| type providerConfig struct { | ||
| userInput string | ||
| scopeOpt source.Scope | ||
| reader io.Reader | ||
| registryOptions *image.RegistryOptions | ||
| } | ||
|
|
||
| type provider func(cfg providerConfig) ([]Package, Context, error) | ||
|
|
||
| // Provide a set of packages and context metadata describing where they were sourced from. | ||
| func Provide(userInput string, scopeOpt source.Scope, registryOptions *image.RegistryOptions) ([]Package, Context, error) { | ||
| providers := []provider{ | ||
| syftJSONProvider, | ||
| syftProvider, // important: we should try syft last | ||
| } | ||
|
|
||
| // capture stdin bytes, so they can be used across multiple providers | ||
| capturedStdin := bytesFromStdin() | ||
|
|
||
| for _, provide := range providers { | ||
| config := determineProviderConfig(userInput, scopeOpt, registryOptions, capturedStdin) | ||
|
|
||
| packages, ctx, err := provide(config) | ||
| if !errors.Is(err, errDoesNotProvide) { | ||
| return packages, ctx, err | ||
| } | ||
| } | ||
|
|
||
| return nil, Context{}, errDoesNotProvide | ||
| } | ||
|
|
||
| func bytesFromStdin() []byte { | ||
| isPipedInput, err := internal.IsPipedInput() | ||
| if err != nil { | ||
| log.Warnf("unable to determine if there is piped input: %+v", err) | ||
| isPipedInput = false | ||
| } | ||
|
|
||
| if isPipedInput { | ||
| capturedStdin, err := ioutil.ReadAll(os.Stdin) | ||
| if err != nil { | ||
| return nil | ||
| } | ||
|
|
||
| return capturedStdin | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func determineProviderConfig(userInput string, scopeOpt source.Scope, registryOptions *image.RegistryOptions, stdin []byte) providerConfig { | ||
| config := providerConfig{ | ||
| userInput: userInput, | ||
| scopeOpt: scopeOpt, | ||
| registryOptions: registryOptions, | ||
| } | ||
|
|
||
| if len(stdin) > 0 { | ||
| config.reader = bytes.NewReader(stdin) | ||
| packages, ctx, err := syftSBOMProvider(userInput) | ||
| if !errors.Is(err, errDoesNotProvide) { | ||
| return packages, ctx, err | ||
| } | ||
|
|
||
| return config | ||
| return syftProvider(userInput, scopeOpt, registryOptions) | ||
| } | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.