Skip to content

Commit

Permalink
Merge branch 'main' of github.com:mondoohq/cnquery into afiune/parall…
Browse files Browse the repository at this point in the history
…el_asset_discovery

Signed-off-by: Salim Afiune Maya <[email protected]>
  • Loading branch information
afiune committed Dec 12, 2024
2 parents 842e1e7 + 949f0ce commit e785c76
Show file tree
Hide file tree
Showing 36 changed files with 63 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/env
Original file line number Diff line number Diff line change
@@ -1 +1 @@
golang-version=1.23.0
golang-version=1.23.4
2 changes: 2 additions & 0 deletions .github/workflows/pr-test-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ jobs:
contents: write
pull-requests: write
steps:
- name: Checkout code
uses: actions/checkout@v4
# figure out the PR for this commit
- uses: cloudposse-github-actions/[email protected]
id: pr
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Mondoo, Inc.
# SPDX-License-Identifier: BUSL-1.1

FROM alpine:3.20 AS root
FROM alpine:3.21 AS root
RUN apk update &&\
apk add ca-certificates wget tar &&\
rm -rf /var/cache/apk/*
Expand Down
2 changes: 1 addition & 1 deletion providers/ansible/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "ansible",
ID: "go.mondoo.com/cnquery/v11/providers/ansible",
Version: "11.0.31",
Version: "11.0.32",
ConnectionTypes: []string{provider.DefaultConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/arista/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "arista",
ID: "go.mondoo.com/cnquery/v9/providers/arista",
Version: "11.0.44",
Version: "11.0.45",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/atlassian/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
var Config = plugin.Provider{
Name: "atlassian",
ID: "go.mondoo.com/cnquery/v9/providers/atlassian",
Version: "11.0.47",
Version: "11.0.48",
ConnectionTypes: []string{
provider.DefaultConnectionType,
"jira",
Expand Down
2 changes: 1 addition & 1 deletion providers/aws/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
var Config = plugin.Provider{
Name: "aws",
ID: "go.mondoo.com/cnquery/v9/providers/aws",
Version: "11.5.10",
Version: "11.5.11",
ConnectionTypes: []string{provider.DefaultConnectionType, string(awsec2ebsconn.EBSConnectionType)},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/azure/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
var Config = plugin.Provider{
Name: "azure",
ID: "go.mondoo.com/cnquery/v9/providers/azure",
Version: "11.3.18",
Version: "11.3.19",
ConnectionTypes: []string{
provider.ConnectionType,
string(azureinstancesnapshot.SnapshotConnectionType),
Expand Down
2 changes: 1 addition & 1 deletion providers/cloudflare/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var Config = plugin.Provider{
Name: "cloudflare",
ID: "go.mondoo.com/cnquery/v11/providers/cloudflare",
Version: "11.0.1",
Version: "11.0.2",
ConnectionTypes: []string{provider.DefaultConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/cloudformation/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "cloudformation",
ID: "go.mondoo.com/cnquery/v11/providers/cloudformation",
Version: "11.0.36",
Version: "11.0.37",
ConnectionTypes: []string{provider.DefaultConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var Config = plugin.Provider{
Name: "core",
ID: "go.mondoo.com/cnquery/v9/providers/core",
Version: "11.0.23",
Version: "11.0.24",
Connectors: []plugin.Connector{},
AssetUrlTrees: []*inventory.AssetUrlBranch{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/equinix/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var Config = plugin.Provider{
Name: "equinix",
ID: "go.mondoo.com/cnquery/v9/providers/equinix",
Version: "11.0.44",
Version: "11.0.45",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/gcp/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
var Config = plugin.Provider{
Name: "gcp",
ID: "go.mondoo.com/cnquery/v9/providers/gcp",
Version: "11.0.50",
Version: "11.0.51",
ConnectionTypes: []string{
provider.ConnectionType,
string(gcpinstancesnapshot.SnapshotConnectionType),
Expand Down
2 changes: 1 addition & 1 deletion providers/github/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var Config = plugin.Provider{
Name: "github",
ID: "go.mondoo.com/cnquery/v9/providers/github",
Version: "11.4.28",
Version: "11.4.29",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/gitlab/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "gitlab",
ID: "go.mondoo.com/cnquery/v9/providers/gitlab",
Version: "11.1.38",
Version: "11.1.39",
ConnectionTypes: []string{
provider.ConnectionType,
provider.GitlabGroupConnection,
Expand Down
2 changes: 1 addition & 1 deletion providers/google-workspace/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "google-workspace",
ID: "go.mondoo.com/cnquery/v9/providers/google-workspace",
Version: "11.1.22",
Version: "11.1.23",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/ipmi/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "ipmi",
ID: "go.mondoo.com/cnquery/v9/providers/ipmi",
Version: "11.0.44",
Version: "11.0.45",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/k8s/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var Config = plugin.Provider{
Name: "k8s",
ID: "go.mondoo.com/cnquery/v9/providers/k8s",
Version: "11.1.38",
Version: "11.1.39",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/mondoo/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var Config = plugin.Provider{
Name: "mondoo",
ID: "go.mondoo.com/cnquery/v11/providers/mondoo",
Version: "11.1.22",
Version: "11.1.23",
ConnectionTypes: []string{provider.DefaultConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/ms365/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "ms365",
ID: "go.mondoo.com/cnquery/v9/providers/ms365",
Version: "11.1.0",
Version: "11.1.1",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/network/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "network",
ID: "go.mondoo.com/cnquery/v9/providers/network",
Version: "11.0.39",
Version: "11.0.40",
ConnectionTypes: []string{provider.HostConnectionType},
CrossProviderTypes: []string{
"go.mondoo.com/cnquery/providers/os",
Expand Down
2 changes: 1 addition & 1 deletion providers/oci/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "oci",
ID: "go.mondoo.com/cnquery/v9/providers/oci",
Version: "11.0.44",
Version: "11.0.45",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/okta/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "okta",
ID: "go.mondoo.com/cnquery/v9/providers/okta",
Version: "11.0.44",
Version: "11.0.45",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/opcua/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var Config = plugin.Provider{
Name: "opcua",
ID: "go.mondoo.com/cnquery/v9/providers/opcua",
Version: "11.0.44",
Version: "11.0.45",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/os/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var Config = plugin.Provider{
Name: "os",
ID: "go.mondoo.com/cnquery/v9/providers/os",
Version: "11.3.12",
Version: "11.3.13",
ConnectionTypes: []string{
shared.Type_Local.String(),
shared.Type_SSH.String(),
Expand Down
4 changes: 2 additions & 2 deletions providers/os/connection/container/image_connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,11 +231,11 @@ func TestImageConnections(t *testing.T) {
fSearch := fs.(*tar.FS)

if test.testfile == "/etc/alpine-release" {
infos, err := fSearch.Find("/", regexp.MustCompile(`alpine-release`), "file")
infos, err := fSearch.Find("/", regexp.MustCompile(`alpine-release`), "file", nil, nil)
require.NoError(t, err)
assert.Equal(t, 1, len(infos))
} else if test.testfile == "/etc/centos-release" {
infos, err := fSearch.Find("/", regexp.MustCompile(`centos-release`), "file")
infos, err := fSearch.Find("/", regexp.MustCompile(`centos-release`), "file", nil, nil)
require.NoError(t, err)
assert.Equal(t, 6, len(infos))
}
Expand Down
2 changes: 1 addition & 1 deletion providers/os/connection/tar/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func TestTarFileFind(t *testing.T) {

fSearch := fs.(*tar.FS)

infos, err := fSearch.Find("/", regexp.MustCompile(`alpine-release`), "file")
infos, err := fSearch.Find("/", regexp.MustCompile(`alpine-release`), "file", nil, nil)
require.NoError(t, err)

assert.Equal(t, 1, len(infos))
Expand Down
22 changes: 20 additions & 2 deletions providers/os/connection/tar/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@ import (

"github.com/rs/zerolog/log"
"github.com/spf13/afero"
"go.mondoo.com/cnquery/v11/providers/os/connection/shared"
"go.mondoo.com/cnquery/v11/providers/os/fsutil"
)

var _ shared.FileSearch = (*FS)(nil)

func NewFs(source string) *FS {
return &FS{
Source: source,
Expand Down Expand Up @@ -192,18 +195,21 @@ func (fs *FS) tar(path string, header *tar.Header) (io.ReadCloser, error) {

// searches for files and returns the file info
// regex can be nil
func (fs *FS) Find(from string, r *regexp.Regexp, typ string) ([]string, error) {
func (fs *FS) Find(from string, r *regexp.Regexp, typ string, perm *uint32, depth *int) ([]string, error) {
list := []string{}
for k := range fs.FileMap {
p := strings.HasPrefix(k, from)
m := true
if r != nil {
m = r.MatchString(k)
}
if !depthMatch(from, k, depth) {
continue
}
log.Trace().Str("path", k).Str("from", from).Str("prefix", from).Bool("prefix", p).Bool("m", m).Msg("check if matches")
if p && m {
entry := fs.FileMap[k]
if (typ == "directory" && entry.Typeflag == tar.TypeDir) || (typ == "file" && entry.Typeflag == tar.TypeReg) {
if (typ == "directory" && entry.Typeflag == tar.TypeDir) || (typ == "file" && entry.Typeflag == tar.TypeReg) || typ == "" {
list = append(list, k)
log.Debug().Msg("matches")
continue
Expand All @@ -212,3 +218,15 @@ func (fs *FS) Find(from string, r *regexp.Regexp, typ string) ([]string, error)
}
return list, nil
}

func depthMatch(from, filepath string, depth *int) bool {
if depth == nil {
return true
}

trimmed := strings.TrimPrefix(filepath, from)
// WalkDir always uses slash for separating, ignoring the OS separator. This is why we need to replace it.
normalized := strings.ReplaceAll(trimmed, string(os.PathSeparator), "/")
fileDepth := strings.Count(normalized, "/")
return fileDepth <= *depth
}
3 changes: 3 additions & 0 deletions providers/os/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import (
"time"

"github.com/spf13/afero"
"go.mondoo.com/cnquery/v11/providers/os/connection/shared"
)

var _ shared.FileSearch = (*MountedFs)(nil)

var notSupported = errors.New("not supported")

type MountedFs struct {
Expand Down
5 changes: 5 additions & 0 deletions providers/os/resources/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func (l *mqlFilesFind) list() ([]interface{}, error) {
if err != nil {
return nil, err
}
} else if len(l.Name.Data) > 0 {
compiledRegexp, err = regexp.Compile(l.Name.Data)
if err != nil {
return nil, err
}
}

var foundFiles []string
Expand Down
2 changes: 1 addition & 1 deletion providers/shodan/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var Config = plugin.Provider{
Name: "shodan",
ID: "go.mondoo.com/cnquery/v11/providers/shodan",
Version: "11.0.33",
Version: "11.0.34",
ConnectionTypes: []string{provider.DefaultConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/slack/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "slack",
ID: "go.mondoo.com/cnquery/v9/providers/slack",
Version: "11.0.46",
Version: "11.0.47",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/snowflake/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var Config = plugin.Provider{
Name: "snowflake",
ID: "go.mondoo.com/cnquery/v11/providers/snowflake",
Version: "11.0.30",
Version: "11.0.31",
ConnectionTypes: []string{provider.DefaultConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/terraform/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
var Config = plugin.Provider{
Name: "terraform",
ID: "go.mondoo.com/cnquery/v9/providers/terraform",
Version: "11.0.44",
Version: "11.0.45",
ConnectionTypes: []string{
provider.StateConnectionType,
provider.PlanConnectionType,
Expand Down
2 changes: 1 addition & 1 deletion providers/vcd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
var Config = plugin.Provider{
Name: "vcd",
ID: "go.mondoo.com/cnquery/v9/providers/vcd",
Version: "11.0.44",
Version: "11.0.45",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down
2 changes: 1 addition & 1 deletion providers/vsphere/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var Config = plugin.Provider{
Name: "vsphere",
ID: "go.mondoo.com/cnquery/v9/providers/vsphere",
Version: "11.0.44",
Version: "11.0.45",
ConnectionTypes: []string{provider.ConnectionType},
Connectors: []plugin.Connector{
{
Expand Down

0 comments on commit e785c76

Please sign in to comment.