-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
refactor(misconf): simplify k8s scanner #7717
Conversation
Signed-off-by: nikpivkin <[email protected]>
Signed-off-by: nikpivkin <[email protected]>
Signed-off-by: nikpivkin <[email protected]>
Signed-off-by: nikpivkin <[email protected]>
func (p *Parser) ParseFS(ctx context.Context, target fs.FS, path string) (map[string][]any, error) { | ||
files := make(map[string][]any) | ||
if err := fs.WalkDir(target, filepath.ToSlash(path), func(path string, entry fs.DirEntry, err error) error { | ||
select { | ||
case <-ctx.Done(): | ||
return ctx.Err() | ||
default: | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
if entry.IsDir() { | ||
return nil | ||
} | ||
|
||
parsed, err := p.ParseFile(ctx, target, path) | ||
if err != nil { | ||
p.logger.Error("Parse error", log.FilePath(path), log.Err(err)) | ||
return nil | ||
} | ||
|
||
files[path] = parsed | ||
return nil | ||
}); err != nil { | ||
return nil, err | ||
} | ||
return files, nil | ||
} | ||
|
||
// ParseFile parses Kubernetes manifest from the provided filesystem path. | ||
func (p *Parser) ParseFile(_ context.Context, fsys fs.FS, path string) ([]any, error) { | ||
f, err := fsys.Open(filepath.ToSlash(path)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer func() { _ = f.Close() }() | ||
return p.Parse(f, path) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Were they not used? I'm a little skeptical because they are exported funcs which may have been used elsewhere (outside of the project).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This parser is specific to Trivy, I don't think it can be used anywhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK - I guess only one way to find out 😺
Description
In this PR:
Checklist