Skip to content

Commit 8d767f7

Browse files
committed
fix more linter warnings
Signed-off-by: Juan Antonio Osorio <[email protected]>
1 parent 73c1c4d commit 8d767f7

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

cmd/import-from-toolhive/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func runImport(cmd *cobra.Command, args []string) error {
6363
if verbose {
6464
log.Printf("Loading registry from file: %s", sourceFile)
6565
}
66-
registryData, err = os.ReadFile(sourceFile)
66+
registryData, err = os.ReadFile(sourceFile) // #nosec G304 - file path comes from command line flag
6767
if err != nil {
6868
return fmt.Errorf("failed to read file: %w", err)
6969
}
@@ -72,7 +72,7 @@ func runImport(cmd *cobra.Command, args []string) error {
7272
if verbose {
7373
log.Printf("Fetching registry from URL: %s", sourceURL)
7474
}
75-
resp, err := http.Get(sourceURL)
75+
resp, err := http.Get(sourceURL) // #nosec G107 - URL comes from command line flag
7676
if err != nil {
7777
return fmt.Errorf("failed to fetch registry: %w", err)
7878
}
@@ -153,7 +153,7 @@ func importEntry(name string, server *toolhiveRegistry.ImageMetadata, outputDir
153153
}
154154

155155
// Create the directory
156-
if err := os.MkdirAll(entryDir, 0755); err != nil {
156+
if err := os.MkdirAll(entryDir, 0750); err != nil {
157157
return fmt.Errorf("failed to create directory: %w", err)
158158
}
159159

@@ -180,15 +180,15 @@ func importEntry(name string, server *toolhiveRegistry.ImageMetadata, outputDir
180180
finalContent := header + string(yamlData)
181181

182182
// Write the spec.yaml file
183-
if err := os.WriteFile(specPath, []byte(finalContent), 0644); err != nil {
183+
if err := os.WriteFile(specPath, []byte(finalContent), 0600); err != nil {
184184
return fmt.Errorf("failed to write spec.yaml: %w", err)
185185
}
186186

187187
// Optionally create a README for complex entries
188188
if shouldCreateReadme(server) {
189189
readmePath := filepath.Join(entryDir, "README.md")
190190
readmeContent := generateReadme(name, server)
191-
if err := os.WriteFile(readmePath, []byte(readmeContent), 0644); err != nil {
191+
if err := os.WriteFile(readmePath, []byte(readmeContent), 0600); err != nil {
192192
// Non-fatal error
193193
if verbose {
194194
log.Printf("Warning: Failed to write README for %s: %v", name, err)

cmd/registry-builder/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func buildToolhiveFormat(loader *registry.Loader, outputDir string) error {
188188
}
189189

190190
// Ensure output directory exists
191-
if err := os.MkdirAll(outputDir, 0755); err != nil {
191+
if err := os.MkdirAll(outputDir, 0750); err != nil {
192192
return fmt.Errorf("failed to create output directory: %w", err)
193193
}
194194

cmd/regup/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func loadSpec(path string) (serverWithName, error) {
113113
}
114114

115115
// Read the spec file
116-
data, err := os.ReadFile(path)
116+
data, err := os.ReadFile(path) // #nosec G304 - file path is constructed from known directory
117117
if err != nil {
118118
return serverWithName{}, fmt.Errorf("failed to read spec file: %w", err)
119119
}
@@ -236,7 +236,7 @@ func updateServerInfo(server serverWithName) error {
236236
// updateYAMLPreservingStructure updates the YAML file while preserving comments and structure
237237
func updateYAMLPreservingStructure(path string, stars, pulls int) error {
238238
// Read the original file
239-
data, err := os.ReadFile(path)
239+
data, err := os.ReadFile(path) // #nosec G304 - file path is constructed from known directory
240240
if err != nil {
241241
return fmt.Errorf("failed to read file: %w", err)
242242
}
@@ -261,7 +261,7 @@ func updateYAMLPreservingStructure(path string, stars, pulls int) error {
261261
}
262262

263263
// Write back to file
264-
return os.WriteFile(path, buf.Bytes(), 0644)
264+
return os.WriteFile(path, buf.Bytes(), 0600)
265265
}
266266

267267
// updateMetadataInNode updates metadata fields in the YAML node tree

pkg/registry/loader.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (l *Loader) LoadAll() error {
8686

8787
// LoadEntry loads a single registry entry from a YAML file
8888
func (l *Loader) LoadEntry(path string) (*types.RegistryEntry, error) {
89-
file, err := os.Open(path)
89+
file, err := os.Open(path) // #nosec G304 - path is constructed from known directory structure
9090
if err != nil {
9191
return nil, fmt.Errorf("failed to open file: %w", err)
9292
}
@@ -410,7 +410,7 @@ func (b *Builder) WriteJSON(path string) error {
410410

411411
// Create the directory if it doesn't exist
412412
dir := filepath.Dir(path)
413-
if err := os.MkdirAll(dir, 0755); err != nil {
413+
if err := os.MkdirAll(dir, 0750); err != nil {
414414
return fmt.Errorf("failed to create directory: %w", err)
415415
}
416416

@@ -433,7 +433,7 @@ func (b *Builder) WriteJSON(path string) error {
433433
}
434434

435435
// Write to file
436-
if err := os.WriteFile(path, data, 0644); err != nil {
436+
if err := os.WriteFile(path, data, 0600); err != nil {
437437
return fmt.Errorf("failed to write file: %w", err)
438438
}
439439

0 commit comments

Comments
 (0)