Skip to content

Commit

Permalink
fix: exclude bom info on namespace scope
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <hen.keinan@gmail.com>
  • Loading branch information
chen-keinan committed Nov 22, 2023
1 parent c7e2f80 commit 1c0593c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/trivy.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func main() {
fmt.Println(a.RawResource)
}

bi, err := trivyk8s.ListBomInfo(ctx)
bi, err := trivyk8s.ListClusterBomInfo(ctx)
if err != nil {
log.Fatal(err)
}
Expand Down
18 changes: 10 additions & 8 deletions pkg/trivyk8s/trivyk8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ type ArtifactsK8S interface {
GetArtifact(context.Context, string, string) (*artifacts.Artifact, error)
// ListArtifactAndNodeInfo return kubernete scanable artifact and node info
ListArtifactAndNodeInfo(context.Context, string, map[string]string, ...corev1.Toleration) ([]*artifacts.Artifact, error)
// ListBomInfo returns kubernetes Bom (node,core components) information.
ListBomInfo(context.Context) ([]*artifacts.Artifact, error)
// ListClusterBomInfo returns kubernetes Bom (node,core components) information.
ListClusterBomInfo(context.Context) ([]*artifacts.Artifact, error)
}

type client struct {
Expand Down Expand Up @@ -156,11 +156,13 @@ func (c *client) ListArtifacts(ctx context.Context) ([]*artifacts.Artifact, erro
artifactList = append(artifactList, artifact)
}
}
bomArtifacts, err := c.ListBomInfo(ctx)
if err != nil {
return nil, err
if !namespaced {
bomArtifacts, err := c.ListClusterBomInfo(ctx)
if err != nil {
return nil, err
}
artifactList = append(artifactList, bomArtifacts...)
}
artifactList = append(artifactList, bomArtifacts...)
return artifactList, nil
}

Expand Down Expand Up @@ -215,8 +217,8 @@ func (c *client) ListArtifactAndNodeInfo(ctx context.Context, namespace string,
return artifactList, err
}

// ListBomInfo returns kubernetes Bom (node,core components and etc) information.
func (c *client) ListBomInfo(ctx context.Context) ([]*artifacts.Artifact, error) {
// ListClusterBomInfo returns kubernetes Bom (node,core components and etc) information.
func (c *client) ListClusterBomInfo(ctx context.Context) ([]*artifacts.Artifact, error) {

b, err := c.cluster.CreateClusterBom(ctx)
if err != nil {
Expand Down

0 comments on commit 1c0593c

Please sign in to comment.