Skip to content

Commit d992cfd

Browse files
hi-leiclaude
andcommitted
fix: resolve gosec, errcheck, staticcheck, and trivy CI failures
- Fix errcheck: add _ discard for fmt.Fprintf/Fprintln in auth/use and version - Fix gosec G304: add nolint for os.ReadFile on controlled config paths - Fix gosec G302: add nolint for 0700 directory chmod (intentional) - Fix staticcheck SA1019: use PricePerMonthPerGB instead of deprecated MonthlyPerGB - Fix staticcheck QF1001: apply De Morgan's law in hostname validation - Fix trivy DS-0002/DS-0029: add non-root user and --no-install-recommends to Dockerfile Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 8a54571 commit d992cfd

8 files changed

Lines changed: 21 additions & 22 deletions

File tree

internal/verda-cli/cmd/auth/use.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewCmdUse(_ cmdutil.Factory, ioStreams cmdutil.IOStreams) *cobra.Command {
4040
return err
4141
}
4242

43-
fmt.Fprintf(ioStreams.Out, "Active auth profile: %s\n", profile)
43+
_, _ = fmt.Fprintf(ioStreams.Out, "Active auth profile: %s\n", profile)
4444
return nil
4545
},
4646
}
@@ -51,7 +51,7 @@ func NewCmdUse(_ cmdutil.Factory, ioStreams cmdutil.IOStreams) *cobra.Command {
5151

5252
func writeActiveProfile(path string, profile string) error {
5353
cfg := map[string]any{}
54-
if data, err := os.ReadFile(path); err == nil {
54+
if data, err := os.ReadFile(path); err == nil { //nolint:gosec // path is from our own config
5555
if err := yaml.Unmarshal(data, &cfg); err != nil {
5656
return err
5757
}

internal/verda-cli/cmd/util/hostname.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func ValidateHostname(s string) error {
2121
for _, c := range s {
2222
if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') {
2323
hasLetter = true
24-
} else if !((c >= '0' && c <= '9') || c == '-') {
24+
} else if (c < '0' || c > '9') && c != '-' {
2525
return fmt.Errorf("hostname must contain only letters, digits, hyphens and underscores")
2626
}
2727
}

internal/verda-cli/cmd/version/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ func NewCmdVersion(f cmdutil.Factory, ioStreams cmdutil.IOStreams) *cobra.Comman
1616
Short: "Print the version information",
1717
Long: cmdutil.LongDesc("Print the build and version information for verda."),
1818
Run: func(cmd *cobra.Command, args []string) {
19-
fmt.Fprintln(ioStreams.Out, version.Get().ToJSON())
19+
_, _ = fmt.Fprintln(ioStreams.Out, version.Get().ToJSON())
2020
},
2121
}
2222
}

internal/verda-cli/cmd/vm/wizard.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,11 +532,11 @@ func promptAddVolume(ctx context.Context, prompter tui.Prompter, store *wizard.S
532532
nvmeLabel := "NVMe (fast SSD)"
533533
hddLabel := "HDD (large capacity)"
534534
if cache != nil && cache.volumeTypes != nil {
535-
if vt, ok := cache.volumeTypes[verda.VolumeTypeNVMe]; ok && vt.Price.MonthlyPerGB > 0 {
536-
nvmeLabel = fmt.Sprintf("NVMe (fast SSD) $%.2f/GB/mo", vt.Price.MonthlyPerGB)
535+
if vt, ok := cache.volumeTypes[verda.VolumeTypeNVMe]; ok && vt.Price.PricePerMonthPerGB > 0 {
536+
nvmeLabel = fmt.Sprintf("NVMe (fast SSD) $%.2f/GB/mo", vt.Price.PricePerMonthPerGB)
537537
}
538-
if vt, ok := cache.volumeTypes[verda.VolumeTypeHDD]; ok && vt.Price.MonthlyPerGB > 0 {
539-
hddLabel = fmt.Sprintf("HDD (large capacity) $%.2f/GB/mo", vt.Price.MonthlyPerGB)
538+
if vt, ok := cache.volumeTypes[verda.VolumeTypeHDD]; ok && vt.Price.PricePerMonthPerGB > 0 {
539+
hddLabel = fmt.Sprintf("HDD (large capacity) $%.2f/GB/mo", vt.Price.PricePerMonthPerGB)
540540
}
541541
}
542542
typeIdx, err := prompter.Select(ctx, "Volume type", []string{
@@ -1006,7 +1006,7 @@ func renderDeploymentSummary(opts *createOptions, cache *apiCache) {
10061006
var osVolUnitPrice float64
10071007
if opts.OSVolumeSize > 0 {
10081008
if vt, ok := cache.volumeTypes[verda.VolumeTypeNVMe]; ok {
1009-
osVolUnitPrice = vt.Price.MonthlyPerGB
1009+
osVolUnitPrice = vt.Price.PricePerMonthPerGB
10101010
osVolPrice = volumeHourlyPrice(osVolUnitPrice, opts.OSVolumeSize)
10111011
storageHourly += osVolPrice
10121012
}
@@ -1029,7 +1029,7 @@ func renderDeploymentSummary(opts *createOptions, cache *apiCache) {
10291029
size, _ := strconv.Atoi(sizeStr)
10301030
var hourly, unitP float64
10311031
if vt, ok := cache.volumeTypes[vType]; ok {
1032-
unitP = vt.Price.MonthlyPerGB
1032+
unitP = vt.Price.PricePerMonthPerGB
10331033
hourly = volumeHourlyPrice(unitP, size)
10341034
storageHourly += hourly
10351035
}

internal/verda-cli/cmd/volume/create.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,11 @@ func runCreate(cmd *cobra.Command, f cmdutil.Factory, ioStreams cmdutil.IOStream
8686
if opts.Type == "" {
8787
nvmeLabel := "NVMe (fast SSD)"
8888
hddLabel := "HDD (large capacity)"
89-
if vt, ok := vtMap[verda.VolumeTypeNVMe]; ok && vt.Price.MonthlyPerGB > 0 {
90-
nvmeLabel = fmt.Sprintf("NVMe (fast SSD) $%.2f/GB/mo", vt.Price.MonthlyPerGB)
89+
if vt, ok := vtMap[verda.VolumeTypeNVMe]; ok && vt.Price.PricePerMonthPerGB > 0 {
90+
nvmeLabel = fmt.Sprintf("NVMe (fast SSD) $%.2f/GB/mo", vt.Price.PricePerMonthPerGB)
9191
}
92-
if vt, ok := vtMap[verda.VolumeTypeHDD]; ok && vt.Price.MonthlyPerGB > 0 {
93-
hddLabel = fmt.Sprintf("HDD (large capacity) $%.2f/GB/mo", vt.Price.MonthlyPerGB)
92+
if vt, ok := vtMap[verda.VolumeTypeHDD]; ok && vt.Price.PricePerMonthPerGB > 0 {
93+
hddLabel = fmt.Sprintf("HDD (large capacity) $%.2f/GB/mo", vt.Price.PricePerMonthPerGB)
9494
}
9595
idx, err := prompter.Select(ctx, "Volume type", []string{nvmeLabel, hddLabel})
9696
if err != nil {
@@ -157,7 +157,7 @@ func runCreate(cmd *cobra.Command, f cmdutil.Factory, ioStreams cmdutil.IOStream
157157

158158
var monthlyPerGB float64
159159
if vt, ok := vtMap[opts.Type]; ok {
160-
monthlyPerGB = vt.Price.MonthlyPerGB
160+
monthlyPerGB = vt.Price.PricePerMonthPerGB
161161
}
162162
const hoursInMonth = 730 // 365*24/12, matching web frontend
163163
hourly := math.Ceil(monthlyPerGB*float64(opts.Size)/hoursInMonth*10000) / 10000

internal/verda-cli/options/paths.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func mkdirSecure(dir string) error {
6666
}
6767
// On Unix, enforce 0700 on the leaf directory.
6868
if runtime.GOOS != "windows" {
69-
_ = os.Chmod(dir, 0o700)
69+
_ = os.Chmod(dir, 0o700) //nolint:gosec // 0700 is correct for a config directory
7070
}
7171
return nil
7272
}

internal/verda-cli/options/settings.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func SaveSetting(key string, value any) error {
1717
path := filepath.Join(dir, "config.yaml")
1818

1919
cfg := map[string]any{}
20-
if data, err := os.ReadFile(path); err == nil {
20+
if data, err := os.ReadFile(path); err == nil { //nolint:gosec // path is from our own config dir
2121
if err := yaml.Unmarshal(data, &cfg); err != nil {
2222
return err
2323
}
@@ -42,7 +42,7 @@ func GetSetting(key string) (any, bool) {
4242
}
4343
path := filepath.Join(dir, "config.yaml")
4444

45-
data, err := os.ReadFile(path)
45+
data, err := os.ReadFile(path) //nolint:gosec // path is from our own config dir
4646
if err != nil {
4747
return nil, false
4848
}

scripts/test-install.Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
FROM ubuntu:24.04
2-
RUN apt-get update && apt-get install -y curl ca-certificates && rm -rf /var/lib/apt/lists/*
2+
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates && rm -rf /var/lib/apt/lists/*
3+
RUN useradd -m testuser
4+
USER testuser
35
COPY scripts/install.sh /tmp/install.sh
4-
RUN chmod +x /tmp/install.sh
5-
# Test the install script (will fail until first release exists)
6-
# RUN VERDA_VERSION=v1.0.0 sh /tmp/install.sh
76
CMD ["sh", "/tmp/install.sh"]

0 commit comments

Comments
 (0)