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

✨ Add depth to the files.find LR resource. #4821

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion providers/os/resources/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ func (l *mqlFilesFind) list() ([]interface{}, error) {
perm = &p
}

foundFiles, err = fsSearch.Find(l.From.Data, compiledRegexp, l.Type.Data, perm, nil)
var depth *int
if l.Depth.IsSet() {
d := int(l.Depth.Data)
depth = &d
}

foundFiles, err = fsSearch.Find(l.From.Data, compiledRegexp, l.Type.Data, perm, depth)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -124,6 +130,11 @@ func (l *mqlFilesFind) list() ([]interface{}, error) {
call.WriteString(l.Name.Data)
}

if l.Depth.IsSet() {
call.WriteString(" -maxdepth ")
call.WriteString(octal2string(l.Depth.Data))
}

rawCmd, err := CreateResource(l.MqlRuntime, "command", map[string]*llx.RawData{
"command": llx.StringData(call.String()),
})
Expand Down
2 changes: 2 additions & 0 deletions providers/os/resources/os.lr
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ files.find {
permissions int
// Search name
name string
// The depth of the file search.
depth int
}

// Parse INI files
Expand Down
12 changes: 12 additions & 0 deletions providers/os/resources/os.lr.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions providers/os/resources/os.lr.manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ resources:
min_mondoo_version: latest
files.find:
fields:
depth:
min_mondoo_version: 9.0.0
from: {}
list:
min_mondoo_version: latest
Expand Down
Loading