Skip to content

Commit

Permalink
✨ Add depth to the files.find LR resource. (#4821)
Browse files Browse the repository at this point in the history
Signed-off-by: Preslav <[email protected]>
  • Loading branch information
preslavgerchev authored Nov 7, 2024
1 parent 5196dc2 commit d9eeec1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
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

0 comments on commit d9eeec1

Please sign in to comment.