Skip to content

Commit c8bb9b4

Browse files
committed
Fix linting issues preventing releases
- Add missing Framework enum cases in switch statements - Fix errcheck issues with proper error handling - Add security suppressions for controlled file operations - Fix import formatting and parameter shadowing - Update file/directory permissions for better security Resolves 19 linting issues that were blocking CI/CD releases.
1 parent 844c866 commit c8bb9b4

File tree

3 files changed

+93
-24
lines changed

3 files changed

+93
-24
lines changed

cmd/init.go

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,13 +318,27 @@ func runInitCommand(cmd *cobra.Command, args []string) error {
318318
genErr = integrations.GenerateGoIntegration(absPath, project)
319319
case integrations.FrameworkNode:
320320
genErr = integrations.GenerateNodeIntegration(absPath, project)
321-
// TODO: Add other framework integrations
322-
case integrations.FrameworkVue, integrations.FrameworkAngular, integrations.FrameworkSvelte,
323-
integrations.FrameworkNuxt, integrations.FrameworkVanilla, integrations.FrameworkReactNative,
324-
integrations.FrameworkFlutter, integrations.FrameworkRuby, integrations.FrameworkJava,
325-
integrations.FrameworkCSharp, integrations.FrameworkUnknown:
321+
case integrations.FrameworkVue:
326322
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
327-
default:
323+
case integrations.FrameworkAngular:
324+
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
325+
case integrations.FrameworkSvelte:
326+
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
327+
case integrations.FrameworkNuxt:
328+
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
329+
case integrations.FrameworkVanilla:
330+
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
331+
case integrations.FrameworkReactNative:
332+
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
333+
case integrations.FrameworkFlutter:
334+
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
335+
case integrations.FrameworkRuby:
336+
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
337+
case integrations.FrameworkJava:
338+
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
339+
case integrations.FrameworkCSharp:
340+
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
341+
case integrations.FrameworkUnknown:
328342
fmt.Printf(" ℹ️ Code generation for %s coming soon!\n", project.GetFrameworkName())
329343
}
330344

@@ -387,6 +401,33 @@ func runInitCommand(cmd *cobra.Command, args []string) error {
387401
case integrations.FrameworkPython:
388402
fmt.Println(" - Configure webhook handlers for call events")
389403
fmt.Println(" - Set up assistant and call management endpoints")
404+
case integrations.FrameworkVue:
405+
fmt.Println(" - Follow the Vue.js integration guide in documentation")
406+
case integrations.FrameworkAngular:
407+
fmt.Println(" - Follow the Angular integration guide in documentation")
408+
case integrations.FrameworkSvelte:
409+
fmt.Println(" - Follow the Svelte integration guide in documentation")
410+
case integrations.FrameworkNuxt:
411+
fmt.Println(" - Follow the Nuxt.js integration guide in documentation")
412+
case integrations.FrameworkRemix:
413+
fmt.Println(" - Follow the Remix integration guide in documentation")
414+
case integrations.FrameworkVanilla:
415+
fmt.Println(" - Follow the vanilla JavaScript integration guide in documentation")
416+
case integrations.FrameworkReactNative:
417+
fmt.Println(" - Follow the React Native integration guide in documentation")
418+
case integrations.FrameworkFlutter:
419+
fmt.Println(" - Follow the Flutter integration guide in documentation")
420+
case integrations.FrameworkGolang:
421+
fmt.Println(" - Set up webhook endpoints for call events")
422+
fmt.Println(" - Create assistant configuration and call management routes")
423+
case integrations.FrameworkRuby:
424+
fmt.Println(" - Follow the Ruby integration guide in documentation")
425+
case integrations.FrameworkJava:
426+
fmt.Println(" - Follow the Java integration guide in documentation")
427+
case integrations.FrameworkCSharp:
428+
fmt.Println(" - Follow the C#/.NET integration guide in documentation")
429+
case integrations.FrameworkUnknown:
430+
fmt.Println(" - Follow the documentation for your specific framework")
390431
}
391432
fmt.Println()
392433
stepNum++

cmd/manual.go

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ package cmd
2121
import (
2222
"fmt"
2323
"os"
24+
"os/exec"
2425
"path/filepath"
2526
"time"
2627

2728
"github.com/spf13/cobra"
2829
"github.com/spf13/cobra/doc"
2930

30-
"os/exec"
31-
3231
versionpkg "github.com/VapiAI/cli/pkg/version"
3332
)
3433

@@ -66,7 +65,11 @@ func installManualPages(cmd *cobra.Command, args []string) error {
6665
if err := os.MkdirAll(tmpDir, 0o750); err != nil {
6766
return fmt.Errorf("failed to create temporary directory: %w", err)
6867
}
69-
defer os.RemoveAll(tmpDir) // Clean up temp directory
68+
defer func() {
69+
if err := os.RemoveAll(tmpDir); err != nil {
70+
fmt.Printf("Warning: failed to clean up temporary directory: %v\n", err)
71+
}
72+
}() // Clean up temp directory
7073

7174
// Generate man pages
7275
fmt.Printf(" 📝 Generating manual pages...\n")
@@ -115,7 +118,7 @@ func installManualPages(cmd *cobra.Command, args []string) error {
115118
}
116119

117120
// Set appropriate permissions
118-
if err := os.Chmod(destPath, 0o644); err != nil {
121+
if err := os.Chmod(destPath, 0o600); err != nil {
119122
fmt.Printf(" ⚠️ Warning: failed to set permissions on %s\n", fileName)
120123
}
121124
}
@@ -164,7 +167,7 @@ func ensureManDirWritable(dir string) error {
164167
stat, err := os.Stat(dir)
165168
if err != nil {
166169
// Try to create the directory
167-
if err := os.MkdirAll(dir, 0o755); err != nil {
170+
if err := os.MkdirAll(dir, 0o750); err != nil {
168171
return fmt.Errorf("directory does not exist and cannot be created: %w", err)
169172
}
170173
return nil
@@ -176,28 +179,43 @@ func ensureManDirWritable(dir string) error {
176179

177180
// Test write permissions by creating a temporary file
178181
testFile := filepath.Join(dir, ".vapi-test-write")
182+
// #nosec G304 - testFile is constructed from known safe directory path
179183
if file, err := os.Create(testFile); err != nil {
180184
return fmt.Errorf("directory is not writable: %w", err)
181185
} else {
182-
file.Close()
183-
os.Remove(testFile) // Clean up test file
186+
if err := file.Close(); err != nil {
187+
fmt.Printf("Warning: failed to close test file: %v\n", err)
188+
}
189+
if err := os.Remove(testFile); err != nil {
190+
fmt.Printf("Warning: failed to remove test file: %v\n", err)
191+
}
184192
}
185193

186194
return nil
187195
}
188196

189197
func copyFile(src, dst string) error {
198+
// #nosec G304 - src and dst are paths controlled by this application
190199
srcFile, err := os.Open(src)
191200
if err != nil {
192201
return err
193202
}
194-
defer srcFile.Close()
203+
defer func() {
204+
if err := srcFile.Close(); err != nil {
205+
fmt.Printf("Warning: failed to close source file: %v\n", err)
206+
}
207+
}()
195208

209+
// #nosec G304 - dst is a path controlled by this application
196210
dstFile, err := os.Create(dst)
197211
if err != nil {
198212
return err
199213
}
200-
defer dstFile.Close()
214+
defer func() {
215+
if err := dstFile.Close(); err != nil {
216+
fmt.Printf("Warning: failed to close destination file: %v\n", err)
217+
}
218+
}()
201219

202220
_, err = srcFile.WriteTo(dstFile)
203221
return err
@@ -212,6 +230,7 @@ func updateManDatabase() error {
212230
}
213231

214232
for _, cmdArgs := range commands {
233+
// #nosec G204 - command arguments are from a predefined safe list
215234
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
216235
if err := cmd.Run(); err == nil {
217236
return nil // Success

cmd/update.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ import (
3131
"strings"
3232
"time"
3333

34-
versionpkg "github.com/VapiAI/cli/pkg/version"
3534
"github.com/spf13/cobra"
3635
"github.com/spf13/cobra/doc"
36+
37+
versionpkg "github.com/VapiAI/cli/pkg/version"
3738
)
3839

3940
// GitHubRelease represents a GitHub release
@@ -291,7 +292,9 @@ func installUpdate(release *GitHubRelease) error {
291292
return fmt.Errorf("failed to create temp directory: %w", err)
292293
}
293294
defer func() {
294-
_ = os.RemoveAll(tmpDir) // Ignore cleanup errors
295+
if err := os.RemoveAll(tmpDir); err != nil {
296+
fmt.Printf("Warning: failed to clean up temporary directory: %v\n", err)
297+
}
295298
}()
296299

297300
// Download the archive
@@ -493,7 +496,7 @@ func getArchiveFileName() string {
493496
return fmt.Sprintf("cli_%s_%s.tar.gz", getOSName(), getArchName())
494497
}
495498

496-
func downloadFile(url, filepath string) error {
499+
func downloadFile(url, filePath string) error {
497500
// #nosec G107 - URL is from GitHub releases API, considered safe
498501
resp, err := http.Get(url)
499502
if err != nil {
@@ -507,8 +510,8 @@ func downloadFile(url, filepath string) error {
507510
return fmt.Errorf("download failed with status %d", resp.StatusCode)
508511
}
509512

510-
// #nosec G304 - filepath is controlled by this function
511-
file, err := os.Create(filepath)
513+
// #nosec G304 - filePath is controlled by this function
514+
file, err := os.Create(filePath)
512515
if err != nil {
513516
return err
514517
}
@@ -596,7 +599,11 @@ func autoInstallManPages() error {
596599
if err := os.MkdirAll(tmpDir, 0o750); err != nil {
597600
return fmt.Errorf("failed to create temp directory: %w", err)
598601
}
599-
defer os.RemoveAll(tmpDir)
602+
defer func() {
603+
if err := os.RemoveAll(tmpDir); err != nil {
604+
fmt.Printf("Warning: failed to clean up temporary directory: %v\n", err)
605+
}
606+
}()
600607

601608
// Generate man pages (simplified version of the manual command)
602609
if err := generateManPagesTo(tmpDir); err != nil {
@@ -615,7 +622,9 @@ func autoInstallManPages() error {
615622
}
616623

617624
// Try to update man database
618-
updateManDatabase()
625+
if err := updateManDatabase(); err != nil {
626+
fmt.Printf("Warning: failed to update man database: %v\n", err)
627+
}
619628

620629
return nil
621630
}
@@ -636,7 +645,7 @@ func generateManPagesTo(outputDir string) error {
636645
// installManPagesTo copies man pages from source to destination directory
637646
func installManPagesTo(sourceDir, destDir string) error {
638647
// Ensure destination directory exists
639-
if err := os.MkdirAll(destDir, 0o755); err != nil {
648+
if err := os.MkdirAll(destDir, 0o750); err != nil {
640649
return fmt.Errorf("failed to create destination directory: %w", err)
641650
}
642651

@@ -656,7 +665,7 @@ func installManPagesTo(sourceDir, destDir string) error {
656665
}
657666

658667
// Set appropriate permissions
659-
if err := os.Chmod(destPath, 0o644); err != nil {
668+
if err := os.Chmod(destPath, 0o600); err != nil {
660669
// Don't fail on permission errors, just warn
661670
fmt.Printf("Warning: failed to set permissions on %s\n", fileName)
662671
}

0 commit comments

Comments
 (0)