Skip to content

Commit da6a022

Browse files
committed
🟢 rebase on main for rc-release + lint extensively
Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
1 parent 70dfcb1 commit da6a022

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+258
-437
lines changed

apps/cnspec/cmd/backgroundjob/serve_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func Serve(timer time.Duration, splay time.Duration, handler JobRunner) {
2121
log.Info().Msg("start cnspec background service")
2222
log.Info().Msgf("scan interval is %d minute(s) with a splay of %d minute(s)", int(timer.Minutes()), int(splay.Minutes()))
2323

24-
quitChannel := make(chan os.Signal)
24+
quitChannel := make(chan os.Signal, 1)
2525
signal.Notify(quitChannel, syscall.SIGINT, syscall.SIGTERM)
2626

2727
shutdownChannel := make(chan struct{})

apps/cnspec/cmd/bundle.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ var policyLintDeprecatedCmd = &cobra.Command{
7979
Short: "Lint a policy bundle",
8080
Args: cobra.ExactArgs(1),
8181
PreRun: func(cmd *cobra.Command, args []string) {
82-
viper.BindPFlag("output", cmd.Flags().Lookup("output"))
83-
viper.BindPFlag("output-file", cmd.Flags().Lookup("output-file"))
82+
_ = viper.BindPFlag("output", cmd.Flags().Lookup("output"))
83+
_ = viper.BindPFlag("output-file", cmd.Flags().Lookup("output-file"))
8484
},
8585
Run: runPolicyLint,
8686
}
@@ -93,8 +93,8 @@ var policyPublishCmd = &cobra.Command{
9393
Short: "Add a user-owned policy to the Mondoo Security Registry",
9494
Args: cobra.ExactArgs(1),
9595
PreRun: func(cmd *cobra.Command, args []string) {
96-
viper.BindPFlag("policy-version", cmd.Flags().Lookup("policy-version"))
97-
viper.BindPFlag("no-lint", cmd.Flags().Lookup("no-lint"))
96+
_ = viper.BindPFlag("policy-version", cmd.Flags().Lookup("policy-version"))
97+
_ = viper.BindPFlag("no-lint", cmd.Flags().Lookup("no-lint"))
9898
},
9999
Run: func(cmd *cobra.Command, args []string) {
100100
opts, optsErr := config.Read()
@@ -151,7 +151,7 @@ var policyPublishCmd = &cobra.Command{
151151
log.Fatal().Err(err).Msg("could not install requirements")
152152
}
153153

154-
log.Info().Str("space", opts.SpaceMrn).Msg("add policy bundle to space")
154+
log.Info().Str("space", opts.SpaceMrn).Msg("add policy bundle to space") //nolint:staticcheck // SA1019: opts.SpaceMrn is deprecated but still used for backward compatibility
155155
overrideVersionFlag := false
156156
overrideVersion := viper.GetString("policy-version")
157157
if len(overrideVersion) > 0 {
@@ -179,7 +179,7 @@ var policyPublishCmd = &cobra.Command{
179179
}
180180

181181
// set the owner mrn for spaces
182-
policyBundle.OwnerMrn = opts.SpaceMrn
182+
policyBundle.OwnerMrn = opts.SpaceMrn //nolint:staticcheck // SA1019: opts.SpaceMrn is deprecated but still used for backward compatibility
183183
ctx := context.Background()
184184

185185
// override version and/or labels
@@ -210,8 +210,8 @@ var policyDocsDeprecatedCmd = &cobra.Command{
210210
Short: "Retrieve only the docs for a bundle",
211211
Args: cobra.MinimumNArgs(1),
212212
PreRun: func(cmd *cobra.Command, args []string) {
213-
viper.BindPFlag("no-ids", cmd.Flags().Lookup("no-ids"))
214-
viper.BindPFlag("no-code", cmd.Flags().Lookup("no-code"))
213+
_ = viper.BindPFlag("no-ids", cmd.Flags().Lookup("no-ids"))
214+
_ = viper.BindPFlag("no-code", cmd.Flags().Lookup("no-code"))
215215
},
216216
Run: func(cmd *cobra.Command, args []string) {
217217
bundleLoader := policy.DefaultBundleLoader()

apps/cnspec/cmd/config/config_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ scan_interval:
3636
`
3737

3838
viper.SetConfigType("yaml")
39-
viper.ReadConfig(strings.NewReader(data))
39+
_ = viper.ReadConfig(strings.NewReader(data))
4040

4141
cfg, err := ReadConfig()
4242
require.NoError(t, err)

apps/cnspec/cmd/root.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package cmd
55

66
import (
7-
"net/http"
87
"os"
98
"regexp"
109
"runtime"
@@ -16,18 +15,13 @@ import (
1615
"github.com/spf13/cobra"
1716
"github.com/spf13/cobra/doc"
1817
"github.com/spf13/viper"
19-
"go.mondoo.com/cnspec/v13"
20-
"go.mondoo.com/mql/v13"
2118
cnquery_app "go.mondoo.com/mql/v13/apps/mql/cmd"
2219
"go.mondoo.com/mql/v13/cli/config"
2320
cli_errors "go.mondoo.com/mql/v13/cli/errors"
2421
"go.mondoo.com/mql/v13/cli/providers"
2522
"go.mondoo.com/mql/v13/cli/theme"
2623
"go.mondoo.com/mql/v13/cli/theme/colors"
2724
"go.mondoo.com/mql/v13/logger"
28-
"go.mondoo.com/mql/v13/providers-sdk/v1/sysinfo"
29-
"go.mondoo.com/ranger-rpc"
30-
"go.mondoo.com/ranger-rpc/plugins/scope"
3125
)
3226

3327
const (
@@ -230,35 +224,3 @@ func GenerateMarkdown(dir string) error {
230224

231225
return nil
232226
}
233-
234-
func defaultRangerPlugins(sysInfo *sysinfo.SystemInfo, features mql.Features) []ranger.ClientPlugin {
235-
plugins := []ranger.ClientPlugin{}
236-
plugins = append(plugins, scope.NewRequestIDRangerPlugin())
237-
plugins = append(plugins, sysInfoHeader(sysInfo, features))
238-
return plugins
239-
}
240-
241-
func sysInfoHeader(sysInfo *sysinfo.SystemInfo, features mql.Features) ranger.ClientPlugin {
242-
const (
243-
HttpHeaderUserAgent = "User-Agent"
244-
HttpHeaderClientFeatures = "Mondoo-Features"
245-
HttpHeaderPlatformID = "Mondoo-PlatformID"
246-
)
247-
248-
h := http.Header{}
249-
info := map[string]string{
250-
"cnspec": cnspec.Version,
251-
"build": cnspec.Build,
252-
}
253-
if sysInfo != nil {
254-
info["PN"] = sysInfo.Platform.Name
255-
info["PR"] = sysInfo.Platform.Version
256-
info["PA"] = sysInfo.Platform.Arch
257-
info["IP"] = sysInfo.IP
258-
info["HN"] = sysInfo.Hostname
259-
h.Set(HttpHeaderPlatformID, sysInfo.PlatformId)
260-
}
261-
h.Set(HttpHeaderUserAgent, scope.XInfoHeader(info))
262-
h.Set(HttpHeaderClientFeatures, features.Encode())
263-
return scope.NewCustomHeaderRangerPlugin(h)
264-
}

apps/cnspec/cmd/scan.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ import (
3030
"go.mondoo.com/mql/v13/providers-sdk/v1/upstream"
3131
)
3232

33-
const (
34-
// allow sending reports to alternative URLs
35-
featureReportAlternateUrlEnv = "REPORT_URL"
36-
)
37-
3833
func init() {
3934
rootCmd.AddCommand(scanCmd)
4035

apps/cnspec/cmd/serve.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ var serveCmd = &cobra.Command{
120120
autoUpdate = viper.GetBool("auto_update")
121121
}
122122

123-
bj.Run(func() error {
123+
_ = bj.Run(func() error {
124124
// Try to update the os provider before each scan
125125
if autoUpdate {
126126
err = updateProviders()
@@ -162,7 +162,7 @@ func getServeConfig() (*scanConfig, *cnspec_config.CliConfig, error) {
162162
}
163163
config.DisplayUsedConfig()
164164

165-
logClientInfo(opts.SpaceMrn, opts.AgentMrn, opts.ServiceAccountMrn)
165+
logClientInfo(opts.SpaceMrn, opts.AgentMrn, opts.ServiceAccountMrn) //nolint:staticcheck // SA1019: opts.SpaceMrn is deprecated but still used for backward compatibility
166166

167167
if len(opts.Features) > 0 {
168168
log.Info().Strs("features", opts.Features).Msg("user activated features")

apps/cnspec/cmd/serve_api.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func init() {
2929
serveApiCmd.Flags().String("address", "127.0.0.1", "Set the address to listen on")
3030
serveApiCmd.Flags().Uint("port", 8080, "Set the port to listen on")
3131
serveApiCmd.Flags().Uint("http-timeout", 30, "Set the timeout for HTTP requests in seconds")
32-
serveApiCmd.Flags().MarkHidden("http-timeout")
32+
_ = serveApiCmd.Flags().MarkHidden("http-timeout")
3333
rootCmd.AddCommand(serveApiCmd)
3434
}
3535

@@ -38,9 +38,9 @@ var serveApiCmd = &cobra.Command{
3838
Hidden: true,
3939
Short: "EXPERIMENTAL: Serve a REST API for running scans",
4040
PreRun: func(cmd *cobra.Command, args []string) {
41-
viper.BindPFlag("port", cmd.Flags().Lookup("port"))
42-
viper.BindPFlag("address", cmd.Flags().Lookup("address"))
43-
viper.BindPFlag("http-timeout", cmd.Flags().Lookup("http-timeout"))
41+
_ = viper.BindPFlag("port", cmd.Flags().Lookup("port"))
42+
_ = viper.BindPFlag("address", cmd.Flags().Lookup("address"))
43+
_ = viper.BindPFlag("http-timeout", cmd.Flags().Lookup("http-timeout"))
4444

4545
logger.StandardZerologLogger()
4646

apps/cnspec/cmd/shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var shellCmd = &cobra.Command{
2424
Short: "Interactive query shell for MQL",
2525
Long: `Allows the interactive exploration of MQL queries.`,
2626
PreRun: func(cmd *cobra.Command, args []string) {
27-
viper.BindPFlag("platform-id", cmd.Flags().Lookup("platform-id"))
27+
_ = viper.BindPFlag("platform-id", cmd.Flags().Lookup("platform-id"))
2828
},
2929
}
3030

cli/components/advisory_results.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ func (a AdvisoryResultTable) Render(r *mvd.VulnReport) (string, error) {
117117
}
118118

119119
line := []string{icon, fmt.Sprintf("%v", score), advisory.ID, currentVersion, fixedVersion, patch}
120-
table.Append(line)
120+
_ = table.Append(line)
121121
}
122-
table.Render()
122+
_ = table.Render()
123123
}
124124

125125
// packages advisories
@@ -232,7 +232,7 @@ func (c *CliTableWriter) renderRow(row *advisories.ReportFindingRow, overrideInd
232232

233233
line := append([]string{icon}, record...)
234234

235-
c.table.Append(line)
235+
_ = c.table.Append(line)
236236
}
237237

238238
func (c *CliTableWriter) Write(row advisories.ReportFindingRow) error {
@@ -301,7 +301,7 @@ func (c *CliTableWriter) Flush() {
301301
}
302302

303303
// and render the table
304-
c.table.Render()
304+
_ = c.table.Render()
305305
}
306306

307307
func IntScore2Float(score int32) float32 {

cli/components/paper.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,14 @@ func (p *Paper) Render(width int, height int) string {
7575
b := strings.Builder{}
7676

7777
for i := 0; i < height; i++ {
78-
firstChar := p.theme.Vertical
79-
if i == 0 {
78+
var firstChar rune
79+
switch i {
80+
case 0:
8081
firstChar = p.theme.TopLeft
81-
} else if i == height-1 {
82+
case height - 1:
8283
firstChar = p.theme.BottomLeft
84+
default:
85+
firstChar = p.theme.Vertical
8386
}
8487
b.WriteRune(firstChar)
8588

@@ -90,11 +93,14 @@ func (p *Paper) Render(width int, height int) string {
9093
}
9194
b.WriteString(strings.Repeat(horizontal, width-2))
9295

93-
lastChar := p.theme.Vertical
94-
if i == 0 {
96+
var lastChar rune
97+
switch i {
98+
case 0:
9599
lastChar = p.theme.TopRight
96-
} else if i == height-1 {
100+
case height - 1:
97101
lastChar = p.theme.BottomRight
102+
default:
103+
lastChar = p.theme.Vertical
98104
}
99105
b.WriteRune(lastChar)
100106
b.WriteByte('\n')

0 commit comments

Comments
 (0)