refactor: update HTTP request handling and improve documentation

- Replaced http.NewRequest with http.NewRequestWithContext in client tests for better context management.
- Updated method names and comments for clarity, including renaming GetWsdlUrl to GetWsdlURL and StorageUri to StorageURI for consistency.
- Enhanced comments across various files to provide clearer descriptions of functionality and ONVIF specifications.
This commit is contained in:
0x524a
2025-12-02 08:41:37 -05:00
parent 9e3b5e0170
commit 96ac509c24
32 changed files with 248 additions and 184 deletions
+11 -5
View File
@@ -145,6 +145,7 @@ var (
captureXML = flag.Bool("capture-xml", false, "Capture raw SOAP XML traffic and create tar.gz archive")
)
//nolint:gocognit // Main function has high complexity due to multiple diagnostic operations
func main() {
flag.Parse()
@@ -191,7 +192,7 @@ func main() {
if *captureXML {
timestamp := time.Now().Format("20060102-150405")
xmlCaptureDir = filepath.Join(*outputDir, "temp_"+timestamp)
if err := os.MkdirAll(xmlCaptureDir, 0755); err != nil {
if err := os.MkdirAll(xmlCaptureDir, 0750); err != nil { //nolint:gosec // 0750 is appropriate for diagnostic output directory
log.Fatalf("Failed to create XML capture directory: %v", err)
}
@@ -876,15 +877,20 @@ func saveReport(report *CameraReport, filename string) error {
return fmt.Errorf("failed to marshal report: %w", err)
}
if err := os.WriteFile(filename, data, 0644); err != nil {
if err := os.WriteFile(filename, data, 0600); err != nil { //nolint:gosec // 0600 is appropriate for diagnostic output files
return fmt.Errorf("failed to write file: %w", err)
}
return nil
}
//nolint:unparam // args parameter is kept for printf-style consistency, even though currently unused
func logStepf(format string, args ...interface{}) {
fmt.Printf("→ "+format+"\n", args...)
if len(args) > 0 {
fmt.Printf("→ %s\n", fmt.Sprintf(format, args...))
} else {
fmt.Printf("→ " + format + "\n")
}
}
func logSuccessf(format string, args ...interface{}) {
@@ -1011,7 +1017,7 @@ func (t *LoggingTransport) saveCapture(capture *XMLCapture) {
return
}
if err := os.WriteFile(filename, data, 0644); err != nil {
if err := os.WriteFile(filename, data, 0600); err != nil { //nolint:gosec // 0600 is appropriate for diagnostic output files
log.Printf("Failed to write capture: %v", err)
}
@@ -1134,7 +1140,7 @@ func createTarGz(sourceDir, archivePath string) error {
// If it's a file, write its content
if !info.IsDir() {
file, err := os.Open(path)
file, err := os.Open(path) //nolint:gosec // File path is from filepath.Walk, safe
if err != nil {
return fmt.Errorf("failed to open file: %w", err)
}