Skip to content

Commit

Permalink
🐛 fix cnspec build (#170)
Browse files Browse the repository at this point in the history
follow up on #168
  • Loading branch information
chris-rock authored Nov 8, 2022
1 parent 5911b97 commit be2327e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 68 deletions.
31 changes: 0 additions & 31 deletions apps/cnspec/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"context"
"net/http"
"strings"
"time"

Expand All @@ -16,7 +15,6 @@ import (
"go.mondoo.com/cnquery/upstream"
"go.mondoo.com/ranger-rpc"
"go.mondoo.com/ranger-rpc/plugins/authentication/statictoken"
"go.mondoo.com/ranger-rpc/plugins/scope"
)

func init() {
Expand Down Expand Up @@ -223,32 +221,3 @@ func register(token string) {

log.Info().Msgf("client %s has logged in successfully", viper.Get("agent_mrn"))
}

func defaultRangerPlugins(sysInfo *sysinfo.SystemInfo, features cnquery.Features) []ranger.ClientPlugin {
plugins := []ranger.ClientPlugin{}
plugins = append(plugins, scope.NewRequestIDRangerPlugin())
plugins = append(plugins, sysInfoHeader(sysInfo, features))
return plugins
}

func sysInfoHeader(sysInfo *sysinfo.SystemInfo, features cnquery.Features) ranger.ClientPlugin {
const (
HttpHeaderUserAgent = "User-Client"
HttpHeaderClientFeatures = "Mondoo-Features"
HttpHeaderPlatformID = "Mondoo-PlatformID"
)

h := http.Header{}
h.Set(HttpHeaderUserAgent, scope.XInfoHeader(map[string]string{
"cnquery": cnquery.Version,
"build": cnquery.Build,
"PN": sysInfo.Platform.Name,
"PR": sysInfo.Platform.Version,
"PA": sysInfo.Platform.Arch,
"IP": sysInfo.IP,
"HN": sysInfo.Hostname,
}))
h.Set(HttpHeaderClientFeatures, features.Encode())
h.Set(HttpHeaderPlatformID, sysInfo.PlatformId)
return scope.NewCustomHeaderRangerPlugin(h)
}
38 changes: 38 additions & 0 deletions apps/cnspec/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"net/http"
"os"
"regexp"
"runtime"
Expand All @@ -12,10 +13,15 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"github.com/spf13/viper"
"go.mondoo.com/cnquery"
"go.mondoo.com/cnquery/cli/config"
"go.mondoo.com/cnquery/cli/sysinfo"
"go.mondoo.com/cnquery/cli/theme"
"go.mondoo.com/cnquery/cli/theme/colors"
"go.mondoo.com/cnquery/logger"
"go.mondoo.com/cnspec"
"go.mondoo.com/ranger-rpc"
"go.mondoo.com/ranger-rpc/plugins/scope"
)

const (
Expand Down Expand Up @@ -170,3 +176,35 @@ func GenerateMarkdown(dir string) error {

return nil
}

func defaultRangerPlugins(sysInfo *sysinfo.SystemInfo, features cnquery.Features) []ranger.ClientPlugin {
plugins := []ranger.ClientPlugin{}
plugins = append(plugins, scope.NewRequestIDRangerPlugin())
plugins = append(plugins, sysInfoHeader(sysInfo, features))
return plugins
}

func sysInfoHeader(sysInfo *sysinfo.SystemInfo, features cnquery.Features) ranger.ClientPlugin {
const (
HttpHeaderUserAgent = "User-Agent"
HttpHeaderClientFeatures = "Mondoo-Features"
HttpHeaderPlatformID = "Mondoo-PlatformID"
)

h := http.Header{}
info := map[string]string{
"cnspec": cnspec.Version,
"build": cnspec.Build,
}
if sysInfo != nil {
info["PN"] = sysInfo.Platform.Name
info["PR"] = sysInfo.Platform.Version
info["PA"] = sysInfo.Platform.Arch
info["IP"] = sysInfo.IP
info["HN"] = sysInfo.Hostname
h.Set(HttpHeaderPlatformID, sysInfo.PlatformId)
}
h.Set(HttpHeaderUserAgent, scope.XInfoHeader(info))
h.Set(HttpHeaderClientFeatures, features.Encode())
return scope.NewCustomHeaderRangerPlugin(h)
}
38 changes: 1 addition & 37 deletions apps/cnspec/cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,10 @@ package cmd
import (
"context"
"fmt"
"net/http"
"os"
"sort"
"strings"

"go.mondoo.com/cnquery/motor/discovery/common"
"go.mondoo.com/cnspec"
"go.mondoo.com/ranger-rpc/plugins/scope"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
Expand All @@ -24,6 +19,7 @@ import (
"go.mondoo.com/cnquery/cli/inventoryloader"
"go.mondoo.com/cnquery/cli/sysinfo"
"go.mondoo.com/cnquery/motor/asset"
"go.mondoo.com/cnquery/motor/discovery/common"
v1 "go.mondoo.com/cnquery/motor/inventory/v1"
"go.mondoo.com/cnquery/motor/providers"
"go.mondoo.com/cnquery/resources"
Expand Down Expand Up @@ -506,38 +502,6 @@ func getCobraScanConfig(cmd *cobra.Command, args []string, provider providers.Pr
return &conf, nil
}

func defaultRangerPlugins(sysInfo *sysinfo.SystemInfo, features cnquery.Features) []ranger.ClientPlugin {
plugins := []ranger.ClientPlugin{}
plugins = append(plugins, scope.NewRequestIDRangerPlugin())
plugins = append(plugins, sysInfoHeader(sysInfo, features))
return plugins
}

func sysInfoHeader(sysInfo *sysinfo.SystemInfo, features cnquery.Features) ranger.ClientPlugin {
const (
HttpHeaderUserAgent = "User-Client"
HttpHeaderClientFeatures = "Mondoo-Features"
HttpHeaderPlatformID = "Mondoo-PlatformID"
)

h := http.Header{}
info := map[string]string{
"cnspec": cnspec.Version,
"build": cnspec.Build,
}
if sysInfo != nil {
info["PN"] = sysInfo.Platform.Name
info["PR"] = sysInfo.Platform.Version
info["PA"] = sysInfo.Platform.Arch
info["IP"] = sysInfo.IP
info["HN"] = sysInfo.Hostname
h.Set(HttpHeaderPlatformID, sysInfo.PlatformId)
}
h.Set(HttpHeaderUserAgent, scope.XInfoHeader(info))
h.Set(HttpHeaderClientFeatures, features.Encode())
return scope.NewCustomHeaderRangerPlugin(h)
}

func (c *scanConfig) loadPolicies() error {
if c.IsIncognito {
if len(c.PolicyPaths) == 0 {
Expand Down

0 comments on commit be2327e

Please sign in to comment.