Skip to content

Commit

Permalink
adjust PHP composer.lock parser function to return relationships
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
  • Loading branch information
wagoodman committed Nov 16, 2021
1 parent 2b12d13 commit 77406a7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions syft/pkg/cataloger/php/parse_composer_lock.go
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"io"

"github.com/anchore/syft/syft/artifact"

"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/pkg/cataloger/common"
)
Expand All @@ -23,7 +25,7 @@ type Dependency struct {
var _ common.ParserFn = parseComposerLock

// parseComposerLock is a parser function for Composer.lock contents, returning "Default" php packages discovered.
func parseComposerLock(_ string, reader io.Reader) ([]pkg.Package, error) {
func parseComposerLock(_ string, reader io.Reader) ([]pkg.Package, []artifact.Relationship, error) {
packages := make([]pkg.Package, 0)
dec := json.NewDecoder(reader)

Expand All @@ -32,7 +34,7 @@ func parseComposerLock(_ string, reader io.Reader) ([]pkg.Package, error) {
if err := dec.Decode(&lock); err == io.EOF {
break
} else if err != nil {
return nil, fmt.Errorf("failed to parse composer.lock file: %w", err)
return nil, nil, fmt.Errorf("failed to parse composer.lock file: %w", err)
}
for _, pkgMeta := range lock.Packages {
version := pkgMeta.Version
Expand All @@ -46,5 +48,5 @@ func parseComposerLock(_ string, reader io.Reader) ([]pkg.Package, error) {
}
}

return packages, nil
return packages, nil, nil
}
3 changes: 2 additions & 1 deletion syft/pkg/cataloger/php/parse_composer_lock_test.go
Expand Up @@ -28,7 +28,8 @@ func TestParseComposerFileLock(t *testing.T) {
t.Fatalf("failed to open fixture: %+v", err)
}

actual, err := parseComposerLock(fixture.Name(), fixture)
// TODO: no relationships are under test yet
actual, _, err := parseComposerLock(fixture.Name(), fixture)
if err != nil {
t.Fatalf("failed to parse requirements: %+v", err)
}
Expand Down

0 comments on commit 77406a7

Please sign in to comment.