From b9b8c65e798891ea7343740260824975fdfb5a34 Mon Sep 17 00:00:00 2001 From: Julian Sommer <115516918+juliansommer@users.noreply.github.com> Date: Tue, 6 Jan 2026 14:20:56 +1100 Subject: [PATCH] (fix) Linter fixes * Fix go vet mutex copy issues and remove report files from git * remove redundant nil checks (len of nil slice is 0) * handle error * add missing error handling * run modernize to change interface{} to any * run other modernise commands * use crypto instead of rand.Intn --- .github/workflows/hive.yml | 3 +- .gitignore | 1 + Makefile | 5 +- TESTING_COMPLETE.md | 509 ----- cmd/hive/cmd/admin.go | 6 +- hive/admin/admin.go | 2 +- hive/awsec2query/parser.go | 2 +- hive/daemon/daemon.go | 20 +- hive/daemon/daemon_test.go | 3 +- hive/gateway/ec2/image/CreateImage_test.go | 2 +- .../gateway/ec2/instance/RunInstances_test.go | 2 +- hive/gateway/ec2/instance/StartInstances.go | 4 +- hive/gateway/ec2/instance/StopInstances.go | 4 +- .../ec2/instance/TerminateInstances.go | 4 +- hive/gateway/ec2/key/CreateKeyPair_test.go | 2 +- hive/gateway/ec2/key/ImportKeyPair.go | 2 +- hive/gateway/gateway.go | 6 +- hive/handlers/ec2/instance/service_impl.go | 12 +- .../ec2/instance/service_nats_test.go | 4 +- hive/handlers/ec2/key/service_impl.go | 12 +- hive/handlers/ec2/key/service_impl_test.go | 80 +- hive/qmp/qmp.go | 6 +- hive/s3client/s3client.go | 2 +- hive/service/service.go | 2 +- hive/services/awsgw/awsgw.go | 2 +- hive/services/hive/hive.go | 2 +- hive/services/nats/nats.go | 2 +- hive/services/predastore/predastore.go | 2 +- .../predastore/predastore_integration_test.go | 10 +- hive/services/viperblockd/viperblockd.go | 4 +- .../viperblockd_integration_test.go | 2 +- hive/services/viperblockd/viperblockd_test.go | 4 +- hive/utils/utils.go | 24 +- hive/utils/utils_test.go | 2 +- hive/vm/vm.go | 2 +- tests/gosec-report.txt | 1749 ----------------- tests/govulncheck-report.txt | 9 - 37 files changed, 135 insertions(+), 2374 deletions(-) delete mode 100644 TESTING_COMPLETE.md delete mode 100644 tests/gosec-report.txt delete mode 100644 tests/govulncheck-report.txt diff --git a/.github/workflows/hive.yml b/.github/workflows/hive.yml index d13707e19..fae6261ff 100644 --- a/.github/workflows/hive.yml +++ b/.github/workflows/hive.yml @@ -2,8 +2,9 @@ name: Build and Test Hive on: push: - branches: ["main"] + branches: [ main ] paths: ["hive/**", ".github/workflows/**"] + pull_request: workflow_dispatch: jobs: diff --git a/.gitignore b/.gitignore index 027f02547..a957e3a41 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ bin/hive tmp/ config/dev.yaml .DS_Store +tests/*.txt diff --git a/Makefile b/Makefile index 38f246c7a..5440fb6b1 100644 --- a/Makefile +++ b/Makefile @@ -79,9 +79,10 @@ security: $(GOVULNCHECK) $(GOSECCHECK) $(GOSTATICCHECK) $(GOSECCHECK) ./... > tests/gosec-report.txt || true @echo "Gosec report saved to tests/gosec-report.txt" - $(GOSTATICCHECK) ./... > tests/staticcheck-report.txt || true + # default config + disable dep warning since we are using aws sdk v1 + $(GOSTATICCHECK) -checks="all,-ST1000,-ST1003,-ST1016,-ST1020,-ST1021,-ST1022,-SA1019,-SA9005" ./... > tests/staticcheck-report.txt || true @echo "Staticcheck report saved to tests/staticcheck-report.txt" - + go vet ./... 2>&1 | tee tests/govet-report.txt || true @echo "Go vet report saved to tests/govet-report.txt" diff --git a/TESTING_COMPLETE.md b/TESTING_COMPLETE.md deleted file mode 100644 index 744865c3c..000000000 --- a/TESTING_COMPLETE.md +++ /dev/null @@ -1,509 +0,0 @@ -# Testing Implementation Summary - -## ✅ Completed Work - -### 1. Daemon Test Suite (`hive/daemon/daemon_test.go`) - -Created comprehensive unit tests for the daemon's EC2 launch functionality: - -**Test Components:** -- `startTestNATSServer()` - Embedded NATS server with auto port allocation -- `createTestDaemon()` - Test daemon factory with automatic cleanup -- `createValidRunInstancesInput()` - Test fixture for valid EC2 requests - -**Test Suites:** -- ✅ `TestHandleEC2Launch_MessageParsing` - NATS message handling (5 test cases) -- ⏸️ `TestHandleEC2Launch_ResourceManagement` - Skipped (requires full infrastructure) -- ✅ `TestDaemon_Initialization` - Daemon creation and configuration -- ✅ `TestResourceManager` - Resource allocation logic - -**Test Results:** -```bash -$ go test -v ./hive/daemon/ -PASS: TestHandleEC2Launch_MessageParsing (0.17s) - ✓ Valid_RunInstancesInput - ✓ Invalid_Instance_Type - ✓ Missing_Required_ImageId - ✓ Invalid_MinCount_(zero) - ✓ Malformed_JSON -SKIP: TestHandleEC2Launch_ResourceManagement -PASS: TestDaemon_Initialization (0.00s) -PASS: TestResourceManager (0.00s) -ok github.com/mulgadc/hive/hive/daemon 0.592s -``` - -### 2. Utils Test Suite (`hive/utils/utils_test.go`) - -Added comprehensive tests for previously untested utility functions: - -**New Tests:** -- ✅ `TestUnmarshalJsonPayload` - JSON unmarshaling (4 test cases) -- ✅ `TestMarshalJsonPayload` - JSON marshaling (2 test cases) -- ✅ `TestGenerateErrorPayload` - Error generation (3 test cases) -- ✅ `TestValidateErrorPayload` - Error validation (4 test cases) -- ✅ `TestMarshalToXML` - XML marshaling (3 test cases) -- ✅ `TestKillProcess` - Process termination -- ✅ `TestStopProcess` - Service stop with PID cleanup - -**Test Results:** -```bash -$ go test -v ./hive/utils/ -PASS: TestGeneratePidFile (0.00s) -PASS: TestGenerateSocketFile (0.00s) -PASS: TestExecProcessAndKill (1.71s) -PASS: TestUnmarshalJsonPayload (0.00s) -PASS: TestMarshalJsonPayload (0.00s) -PASS: TestGenerateErrorPayload (0.00s) -PASS: TestValidateErrorPayload (0.00s) -PASS: TestMarshalToXML (0.00s) -PASS: TestKillProcess (4.51s) -PASS: TestStopProcess (4.01s) -ok github.com/mulgadc/hive/hive/utils 10.844s -``` - -### 3. Bug Fixes - -Fixed critical bugs that prevented tests from passing: - -#### Bug 1: Pointer-to-Pointer in UnmarshalJsonPayload -**Location:** `hive/utils/utils.go:283` - -**Before:** -```go -err := decoder.Decode(&input) // input already a pointer, creates **Type -``` - -**After:** -```go -err := decoder.Decode(input) // Correct: input is already a pointer -``` - -#### Bug 2: Nil Pointer in handleEC2Launch -**Location:** `hive/daemon/daemon.go:638-645` - -**Before:** -```go -var runInstancesInput *ec2.RunInstancesInput // nil pointer -errResp = utils.UnmarshalJsonPayload(runInstancesInput, msg.Data) // crashes -``` - -**After:** -```go -runInstancesInput := &ec2.RunInstancesInput{} // Initialize before use -errResp = utils.UnmarshalJsonPayload(runInstancesInput, msg.Data) -``` - -#### Bug 3: Uninitialized Slice Elements in launchEC2Instance -**Location:** `hive/daemon/daemon.go:852-856` - -**Before:** -```go -reservation.Instances = make([]*ec2.Instance, 1) -reservation.Instances[0].SetInstanceId(instance.ID) // nil pointer dereference -``` - -**After:** -```go -reservation.Instances = make([]*ec2.Instance, 1) -reservation.Instances[0] = &ec2.Instance{ - State: &ec2.InstanceState{}, -} -reservation.Instances[0].SetInstanceId(instance.ID) -``` - -#### Bug 4: Same Issue in MarshalJsonPayload -**Location:** `hive/utils/utils.go:299` - -**Before:** -```go -err := decoder.Decode(&input) -``` - -**After:** -```go -err := decoder.Decode(input) -``` - -### 4. Documentation - -Created comprehensive testing documentation: - -**Files Created:** -1. `hive/daemon/TESTING.md` (423 lines) - - Test structure and components - - macOS limitations and workarounds - - Test execution instructions - - Mock service strategies - - Debugging guide - -2. `hive/daemon/TEST_SUMMARY.md` (467 lines) - - Test architecture highlights - - Known issues and limitations - - Recommendations for different platforms - - Next steps and roadmap - - Current test results - -3. `TESTING_COMPLETE.md` (this file) - - Summary of all completed work - - Bug fixes - - Test results - - Future enhancements - -## 📊 Test Coverage - -### Overall Test Results - -```bash -$ make test - -✓ hive/awsec2query - All tests passing -✓ hive/awserrors - All tests passing -✓ hive/daemon - 3 passing, 1 skipped (infrastructure required) -✓ hive/gateway/ec2/instance - All tests passing -✓ hive/service - All tests passing -✓ hive/services/predastore - All tests passing (integration skipped) -✓ hive/services/viperblockd - All tests passing -✓ hive/utils - All tests passing (10 tests, 26 cases) -✓ hive/vm - All tests passing - -OVERALL: PASS -``` - -### Code Coverage by Package - -| Package | Tests | Coverage | Notes | -|---------|-------|----------|-------| -| daemon | 4 | ~60% | Message handling, resource mgmt, initialization | -| utils | 10 | ~85% | All major functions tested | -| gateway/ec2/instance | 2 | ~75% | RunInstances validation | -| vm | 2 | ~40% | Config generation, ID creation | -| services/* | 8 | ~70% | Service lifecycle, NATS integration | - -## 🎯 Test Framework Features - -### Daemon Tests - -**Strengths:** -- ✅ Isolated NATS server per test -- ✅ Automatic resource cleanup -- ✅ Table-driven test design -- ✅ Comprehensive error scenarios -- ✅ AWS SDK integration testing - -**Limitations:** -- ⚠️ Requires mocks for viperblock/nbdkit on macOS -- ⚠️ Full VM launch needs Linux + infrastructure -- ⚠️ Cloud-init volume creation not tested - -### Utils Tests - -**Strengths:** -- ✅ Comprehensive coverage of JSON/XML marshaling -- ✅ Process management testing -- ✅ Error handling validation -- ✅ Platform-aware (macOS vs Linux) - -**Coverage:** -- ✅ PID file operations -- ✅ Socket file generation -- ✅ Process lifecycle (start/stop/kill) -- ✅ JSON payload marshaling/unmarshaling -- ✅ XML marshaling -- ✅ Error payload generation/validation - -## 🐛 Bugs Fixed - -### Critical (Blocking Tests) - -1. **Pointer-to-pointer bugs** (2 instances) - - Impact: Caused all JSON unmarshaling to fail - - Fix: Remove unnecessary `&` operator - - Files: `utils.go:283, 299` - -2. **Nil pointer dereference in handleEC2Launch** - - Impact: All EC2 launch requests crashed - - Fix: Initialize struct before passing to unmarshal - - File: `daemon.go:638` - -3. **Uninitialized slice elements** - - Impact: Crash when setting instance fields - - Fix: Initialize slice elements before use - - File: `daemon.go:852-856` - -### Total Lines Changed -- **Modified:** ~15 lines across 3 files -- **Added:** ~550 lines of tests -- **Documentation:** ~1,200 lines - -## 📝 Test Scenarios Covered - -### Daemon Tests - -**Message Parsing:** -- ✅ Valid RunInstancesInput with all fields -- ✅ Invalid instance type rejection -- ✅ Missing required ImageId -- ✅ Invalid MinCount (zero) -- ✅ Malformed JSON handling - -**Resource Management:** -- ✅ Instance type lookup -- ✅ Resource allocation/deallocation -- ✅ Capacity checking -- ✅ System resource detection - -### Utils Tests - -**JSON Operations:** -- ✅ Valid JSON unmarshaling -- ✅ Malformed JSON error handling -- ✅ Unknown field rejection (DisallowUnknownFields) -- ✅ Empty JSON handling - -**Error Handling:** -- ✅ Error payload generation -- ✅ Error payload validation -- ✅ Success vs error discrimination - -**XML Operations:** -- ✅ Struct marshaling -- ✅ Pointer marshaling -- ✅ Invalid type error handling - -**Process Management:** -- ✅ Process creation and termination -- ✅ PID file read/write/remove -- ✅ Signal handling -- ✅ Non-existent process error handling - -## 🚀 Running Tests - -### Quick Test - -```bash -# Run all tests -make test - -# Run specific package -go test -v ./hive/daemon/ -go test -v ./hive/utils/ - -# Run with race detection -go test -race ./... - -# Run with coverage -go test -cover ./... -``` - -### Platform-Specific - -**macOS (Unit Tests Only):** -```bash -# All passing unit tests -go test -v ./hive/daemon/ -go test -v ./hive/utils/ -``` - -**Linux (Full Integration):** -```bash -# Requires: predastore, viperblock, nbdkit, QEMU -# Remove SKIP_INTEGRATION flag -unset SKIP_INTEGRATION -go test -v ./hive/daemon/ -``` - -**Docker (Recommended for Full Tests):** -```bash -docker-compose up test-env -docker exec -it hive-test go test -v ./... -``` - -## 🔍 What's Tested vs Not Tested - -### ✅ Fully Tested - -- NATS message parsing and routing -- JSON marshaling/unmarshaling -- Error generation and validation -- Resource manager logic -- PID file operations -- Process lifecycle management -- XML marshaling -- Input validation -- Instance type lookup - -### ⏸️ Partially Tested (Mocks Needed for macOS) - -- EC2 launch flow (stops at viperblock creation) -- Volume mounting (requires nbdkit) -- Cloud-init generation (requires S3 backend) - -### ❌ Not Yet Tested (Requires Full Infrastructure) - -- Complete VM launch -- QEMU process management -- QMP socket communication -- NBD volume attachment -- EBS volume lifecycle -- VM state transitions -- Concurrent instance launches -- Resource exhaustion scenarios - -## 🎯 Future Enhancements - -### Short Term (Next Sprint) - -1. **Mock Services** - ```go - // Mock EBS mount service for macOS - func startMockEBSService(t *testing.T, nc *nats.Conn) { - nc.Subscribe("ebs.mount", func(msg *nats.Msg) { - // Return mock NBD URI - }) - } - ``` - -2. **Integration Tests** - - Add `//go:build linux` tags - - Full VM launch tests - - Volume lifecycle tests - -3. **Benchmark Tests** - ```go - func BenchmarkEC2Launch(b *testing.B) { - // Measure launch performance - } - ``` - -### Medium Term - -1. **CI/CD Integration** - - GitHub Actions workflow - - Docker-based test environment - - Coverage reporting (codecov.io) - -2. **Load Testing** - - Concurrent launch stress tests - - Resource exhaustion tests - - NATS throughput tests - -3. **Mock Framework** - - Reusable mock services - - Test helpers package - - Platform-aware test skipping - -### Long Term - -1. **E2E Test Suite** - - Complete AWS SDK compatibility tests - - Multi-instance orchestration - - Failure recovery scenarios - -2. **Performance Suite** - - Latency measurements - - Throughput benchmarks - - Resource utilization profiling - -3. **Chaos Engineering** - - Network partition tests - - Service failure simulation - - Recovery time validation - -## 📚 Documentation Structure - -``` -hive/ -├── hive/daemon/ -│ ├── daemon.go [FIXED: 3 bugs] -│ ├── daemon_test.go [NEW: 4 test suites] -│ ├── TESTING.md [NEW: 423 lines] -│ └── TEST_SUMMARY.md [NEW: 467 lines] -├── hive/utils/ -│ ├── utils.go [FIXED: 2 bugs] -│ └── utils_test.go [ENHANCED: +10 tests] -└── TESTING_COMPLETE.md [NEW: This file] -``` - -## 🎉 Success Metrics - -### Before -- ❌ daemon tests: 0 tests, crashes on startup -- ❌ utils tests: 3 tests, missing coverage for 13+ functions -- ❌ Critical bugs: 4 blocking issues -- ❌ Documentation: None - -### After -- ✅ daemon tests: 4 test suites, 5 test cases passing -- ✅ utils tests: 10 test suites, 26 test cases passing -- ✅ Critical bugs: All fixed -- ✅ Documentation: 1,200+ lines -- ✅ Total test cases: 50+ across all packages -- ✅ Overall: `make test` passes 100% - -## 💡 Key Learnings - -### Test Design - -1. **Embedded NATS server is ideal for testing** - - No external dependencies - - Port auto-allocation prevents conflicts - - Fast startup/teardown - -2. **Table-driven tests scale well** - - Easy to add new cases - - Clear test structure - - Minimal code duplication - -3. **Platform differences matter** - - macOS vs Linux signal handling - - Process cleanup timing - - File system behavior - -### Bug Patterns - -1. **Pointer confusion is common** - - Double-check `&` usage - - Verify struct initialization - - Test nil pointer paths - -2. **AWS SDK requires explicit initialization** - - Can't use SetX() on nil pointers - - Must initialize nested structs - - Slice make() != slice element initialization - -3. **JSON unmarshaling needs initialized target** - - Can't unmarshal into nil pointer - - DisallowUnknownFields is strict - - Empty {} is valid but may be treated as error - -## 🔗 Related Files - -- `CLAUDE.md` - Project overview and development guide -- `HIVE_DEVELOPMENT_PLAN.md` - Roadmap and feature planning -- `hive/daemon/TESTING.md` - Detailed testing guide -- `hive/daemon/TEST_SUMMARY.md` - Test architecture and status -- `hive/utils/utils_test.go` - Utils test implementation -- `hive/daemon/daemon_test.go` - Daemon test implementation - -## ✅ Acceptance Criteria Met - -- [x] Created `daemon_test.go` with NATS server setup -- [x] Implemented `handleEC2Launch` message tests -- [x] Created sample RunInstancesInput test cases -- [x] Validated expected arguments and error handling -- [x] Documented macOS limitations (viperblock, nbdkit) -- [x] Provided suggestions for scaffolding -- [x] Fixed existing bugs (pointer-to-pointer issues) -- [x] Created comprehensive utils tests -- [x] All tests passing with `make test` -- [x] Detailed documentation created - -## 🏁 Conclusion - -The test framework is now production-ready for unit testing on both macOS and Linux. The daemon EC2 launch functionality has comprehensive message handling tests, and the utils package is thoroughly tested. All critical bugs have been fixed, and the codebase is ready for further development. - -**Next Steps:** -1. Implement mock services for full macOS testing -2. Add Linux-specific integration tests -3. Set up CI/CD pipeline with Docker -4. Expand coverage to volume lifecycle operations diff --git a/cmd/hive/cmd/admin.go b/cmd/hive/cmd/admin.go index 470d07884..adb8922a2 100644 --- a/cmd/hive/cmd/admin.go +++ b/cmd/hive/cmd/admin.go @@ -724,7 +724,11 @@ func runAdminJoin(cmd *cobra.Command, args []string) { } defer resp.Body.Close() - body, _ := io.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) + if err != nil { + fmt.Fprintf(os.Stderr, "❌ Error reading response body: %v\n", err) + os.Exit(1) + } if resp.StatusCode != 200 { var errResp config.NodeJoinResponse diff --git a/hive/admin/admin.go b/hive/admin/admin.go index 6d46f357d..5294a820b 100644 --- a/hive/admin/admin.go +++ b/hive/admin/admin.go @@ -47,7 +47,7 @@ func GenerateConfigFiles(configs []ConfigFile, configSettings ConfigSettings) er for _, cfg := range configs { if err := GenerateConfigFile(cfg.Path, cfg.Template, configSettings); err != nil { - return fmt.Errorf("Error creating %s: %v\n", cfg.Name, err) + return fmt.Errorf("error creating %s: %v", cfg.Name, err) } fmt.Printf("✅ Created: %s\n", cfg.Name) } diff --git a/hive/awsec2query/parser.go b/hive/awsec2query/parser.go index b386afde2..d66df5cc4 100644 --- a/hive/awsec2query/parser.go +++ b/hive/awsec2query/parser.go @@ -29,7 +29,7 @@ args["TagSpecification.2.Tag.1.Value"] = "Production" */ -func QueryParamsToStruct(params map[string]string, out interface{}) error { +func QueryParamsToStruct(params map[string]string, out any) error { v := reflect.ValueOf(out) // Must be a pointer to a struct diff --git a/hive/daemon/daemon.go b/hive/daemon/daemon.go index 5f0cb5c1c..5dd2dfe41 100644 --- a/hive/daemon/daemon.go +++ b/hive/daemon/daemon.go @@ -596,8 +596,15 @@ func (d *Daemon) WriteState() error { d.Instances.Mu.Lock() defer d.Instances.Mu.Unlock() + // Create a struct without the mutex to avoid copying the lock + state := struct { + VMS map[string]*vm.VM `json:"vms"` + }{ + VMS: d.Instances.VMS, + } + // Pretty print JSON with indent - jsonData, err := json.MarshalIndent(d.Instances, "", " ") + jsonData, err := json.MarshalIndent(state, "", " ") if err != nil { return err @@ -753,7 +760,7 @@ func (d *Daemon) SendQMPCommand(q *qmp.QMPClient, cmd qmp.QMPCommand, instanceId // Optional: handle events here continue } - if errObj, ok := msg["error"].(map[string]interface{}); ok { + if errObj, ok := msg["error"].(map[string]any); ok { return nil, fmt.Errorf("QMP error: %s: %s", errObj["class"], errObj["desc"]) } if _, ok := msg["return"]; ok { @@ -809,7 +816,7 @@ func (d *Daemon) handleEC2Events(msg *nats.Msg) { slog.Info("handleEC2RunInstances launched", "instanceId", instance.ID) resp = &qmp.QMPResponse{ - Return: []byte(fmt.Sprintf(`{"status":"running","instanceId":"%s"}`, instance.ID)), + Return: fmt.Appendf(nil, `{"status":"running","instanceId":"%s"}`, instance.ID), } } else { @@ -1080,7 +1087,6 @@ func (d *Daemon) stopInstance(instances map[string]*vm.VM, deleteVolume bool) er // Run asynchronously within a worker group for _, instance := range instances { - instance := instance // capture loop variable wg.Add(1) @@ -1451,6 +1457,10 @@ func (d *Daemon) StartInstance(instance *vm.VM) error { // TODO: Toggle SSH local port forwarding based on config (debugging use) sshDebugPort, err := viperblock.FindFreePort() + if err != nil { + slog.Error("Failed to find free port", "err", err) + return err + } // Just the ipv4 port required sshDebugPort = strings.Replace(sshDebugPort, "[::]:", "", 1) @@ -1865,7 +1875,7 @@ func (d *Daemon) handleEC2DescribeInstances(msg *nats.Msg) { // Filter instances if specific instance IDs were requested instanceIDFilter := make(map[string]bool) - if describeInstancesInput.InstanceIds != nil && len(describeInstancesInput.InstanceIds) > 0 { + if len(describeInstancesInput.InstanceIds) > 0 { for _, id := range describeInstancesInput.InstanceIds { if id != nil { instanceIDFilter[*id] = true diff --git a/hive/daemon/daemon_test.go b/hive/daemon/daemon_test.go index b965fe3ae..2610207ce 100644 --- a/hive/daemon/daemon_test.go +++ b/hive/daemon/daemon_test.go @@ -138,7 +138,7 @@ func TestHandleEC2RunInstances_MessageParsing(t *testing.T) { tests := []struct { name string - input interface{} + input any expectError bool errorInPayload bool validate func(t *testing.T, reply *nats.Msg) @@ -382,7 +382,6 @@ func TestDaemon_Initialization(t *testing.T) { assert.NotNil(t, daemon) assert.NotNil(t, daemon.resourceMgr) - assert.NotNil(t, daemon.Instances) assert.NotNil(t, daemon.Instances.VMS) assert.Equal(t, cfg, daemon.config) } diff --git a/hive/gateway/ec2/image/CreateImage_test.go b/hive/gateway/ec2/image/CreateImage_test.go index 76056940d..1135ff05c 100644 --- a/hive/gateway/ec2/image/CreateImage_test.go +++ b/hive/gateway/ec2/image/CreateImage_test.go @@ -73,7 +73,7 @@ func TestValidateCreateImageInput(t *testing.T) { func TestEC2ProcessCreateImage(t *testing.T) { tests := []struct { name string - payload interface{} + payload any rawJSON []byte wantValidationErr bool wantErrCode string diff --git a/hive/gateway/ec2/instance/RunInstances_test.go b/hive/gateway/ec2/instance/RunInstances_test.go index 7312b3d97..95a985141 100644 --- a/hive/gateway/ec2/instance/RunInstances_test.go +++ b/hive/gateway/ec2/instance/RunInstances_test.go @@ -202,7 +202,7 @@ func TestEC2ProcessRunInstances(t *testing.T) { tests := []struct { name string - payload interface{} + payload any rawJSON []byte wantValidationErr bool wantErrCode string diff --git a/hive/gateway/ec2/instance/StartInstances.go b/hive/gateway/ec2/instance/StartInstances.go index 714994040..f5e6423cd 100644 --- a/hive/gateway/ec2/instance/StartInstances.go +++ b/hive/gateway/ec2/instance/StartInstances.go @@ -13,7 +13,7 @@ import ( // StartInstances sends start commands to specified instances via NATS func StartInstances(input *ec2.StartInstancesInput, natsConn *nats.Conn) (*ec2.StartInstancesOutput, error) { - if input.InstanceIds == nil || len(input.InstanceIds) == 0 { + if len(input.InstanceIds) == 0 { return nil, fmt.Errorf("no instance IDs provided") } @@ -33,7 +33,7 @@ func StartInstances(input *ec2.StartInstancesInput, natsConn *nats.Conn) (*ec2.S ID: instanceID, QMPCommand: qmp.QMPCommand{ Execute: "cont", - Arguments: map[string]interface{}{}, + Arguments: map[string]any{}, }, Attributes: qmp.Attributes{ StopInstance: false, diff --git a/hive/gateway/ec2/instance/StopInstances.go b/hive/gateway/ec2/instance/StopInstances.go index 496f079df..bac5669ec 100644 --- a/hive/gateway/ec2/instance/StopInstances.go +++ b/hive/gateway/ec2/instance/StopInstances.go @@ -14,7 +14,7 @@ import ( // StopInstances sends stop commands to specified instances via NATS // Uses system_powerdown without stop_instance attribute to allow restart func StopInstances(input *ec2.StopInstancesInput, natsConn *nats.Conn) (*ec2.StopInstancesOutput, error) { - if input.InstanceIds == nil || len(input.InstanceIds) == 0 { + if len(input.InstanceIds) == 0 { return nil, fmt.Errorf("no instance IDs provided") } @@ -35,7 +35,7 @@ func StopInstances(input *ec2.StopInstancesInput, natsConn *nats.Conn) (*ec2.Sto ID: instanceID, QMPCommand: qmp.QMPCommand{ Execute: "system_powerdown", - Arguments: map[string]interface{}{}, + Arguments: map[string]any{}, }, Attributes: qmp.Attributes{ StopInstance: false, // Allow restart on daemon/node restart diff --git a/hive/gateway/ec2/instance/TerminateInstances.go b/hive/gateway/ec2/instance/TerminateInstances.go index fd8595208..fc7871274 100644 --- a/hive/gateway/ec2/instance/TerminateInstances.go +++ b/hive/gateway/ec2/instance/TerminateInstances.go @@ -14,7 +14,7 @@ import ( // TerminateInstances sends terminate commands to specified instances via NATS // Uses system_powerdown with stop_instance attribute to prevent restart func TerminateInstances(input *ec2.TerminateInstancesInput, natsConn *nats.Conn) (*ec2.TerminateInstancesOutput, error) { - if input.InstanceIds == nil || len(input.InstanceIds) == 0 { + if len(input.InstanceIds) == 0 { return nil, fmt.Errorf("no instance IDs provided") } @@ -35,7 +35,7 @@ func TerminateInstances(input *ec2.TerminateInstancesInput, natsConn *nats.Conn) ID: instanceID, QMPCommand: qmp.QMPCommand{ Execute: "system_powerdown", - Arguments: map[string]interface{}{}, + Arguments: map[string]any{}, }, Attributes: qmp.Attributes{ StopInstance: true, // Prevent restart on daemon/node restart diff --git a/hive/gateway/ec2/key/CreateKeyPair_test.go b/hive/gateway/ec2/key/CreateKeyPair_test.go index d5bae93c1..c547bee89 100644 --- a/hive/gateway/ec2/key/CreateKeyPair_test.go +++ b/hive/gateway/ec2/key/CreateKeyPair_test.go @@ -59,7 +59,7 @@ func TestValidateCreateKeyPairInput(t *testing.T) { func TestEC2ProcessCreateKeyPair(t *testing.T) { tests := []struct { name string - payload interface{} + payload any rawJSON []byte wantValidationErr bool wantErrCode string diff --git a/hive/gateway/ec2/key/ImportKeyPair.go b/hive/gateway/ec2/key/ImportKeyPair.go index a729acdde..36bece2a2 100644 --- a/hive/gateway/ec2/key/ImportKeyPair.go +++ b/hive/gateway/ec2/key/ImportKeyPair.go @@ -64,7 +64,7 @@ func ValidateImportKeyPairInput(input *ec2.ImportKeyPairInput) (err error) { return errors.New("MissingParameter") } - if input.PublicKeyMaterial == nil || len(input.PublicKeyMaterial) == 0 { + if len(input.PublicKeyMaterial) == 0 { return errors.New("MissingParameter") } diff --git a/hive/gateway/gateway.go b/hive/gateway/gateway.go index 6dcb30fbc..62dd9648a 100644 --- a/hive/gateway/gateway.go +++ b/hive/gateway/gateway.go @@ -224,8 +224,8 @@ func (gw *GatewayConfig) ErrorHandler(ctx *fiber.Ctx, err error) error { // Parse AWS query arguments (used by some services like EC2/S3) func ParseAWSQueryArgs(query string) map[string]string { params := make(map[string]string) - pairs := strings.Split(query, "&") - for _, pair := range pairs { + pairs := strings.SplitSeq(query, "&") + for pair := range pairs { kv := strings.SplitN(pair, "=", 2) if len(kv) == 2 { params[kv[0]] = kv[1] @@ -261,7 +261,7 @@ func GenerateEC2ErrorResponse(code, message, requestID string) (output []byte) { return output } -func ParseArgsToStruct(input *interface{}, args map[string]string) (err error) { +func ParseArgsToStruct(input *any, args map[string]string) (err error) { // Generated from input shape: RunInstancesRequest err = awsec2query.QueryParamsToStruct(args, input) diff --git a/hive/handlers/ec2/instance/service_impl.go b/hive/handlers/ec2/instance/service_impl.go index eb4ddb226..48ca66cc2 100644 --- a/hive/handlers/ec2/instance/service_impl.go +++ b/hive/handlers/ec2/instance/service_impl.go @@ -2,10 +2,11 @@ package handlers_ec2_instance import ( "bytes" + "crypto/rand" "errors" "fmt" "log/slog" - "math/rand" + "math/big" "os" "strings" "text/template" @@ -163,7 +164,7 @@ func (s *InstanceServiceImpl) GenerateVolumes(input *ec2.RunInstancesInput, inst var snapshotId string // Handle block device mappings - if input.BlockDeviceMappings != nil && len(input.BlockDeviceMappings) > 0 { + if len(input.BlockDeviceMappings) > 0 { size = int(*input.BlockDeviceMappings[0].Ebs.VolumeSize) deviceName = *input.BlockDeviceMappings[0].DeviceName volumeType = *input.BlockDeviceMappings[0].Ebs.VolumeType @@ -172,7 +173,10 @@ func (s *InstanceServiceImpl) GenerateVolumes(input *ec2.RunInstancesInput, inst // Determine image ID and snapshot ID if strings.HasPrefix(*input.ImageId, "ami-") { - randomNumber := rand.Intn(100_000_000) + randomNumber, err := rand.Int(rand.Reader, big.NewInt(100_000_000)) + if err != nil { + return err + } imageId = viperblock.GenerateVolumeID("vol", fmt.Sprintf("%d-%s", randomNumber, *input.ImageId), "predastore", time.Now().Unix()) snapshotId = *input.ImageId } else { @@ -357,7 +361,7 @@ func (s *InstanceServiceImpl) cloneAMIToVolume(input *ec2.RunInstancesInput, siz numBlocks := len(data) / int(destVb.BlockSize) // Write individual blocks to the new volume - for i := 0; i < numBlocks; i++ { + for i := range numBlocks { // Check if the input is a Zero block if bytes.Equal(data[i*int(destVb.BlockSize):(i+1)*int(destVb.BlockSize)], nullBlock) { block++ diff --git a/hive/handlers/ec2/instance/service_nats_test.go b/hive/handlers/ec2/instance/service_nats_test.go index 4f37066f2..a2d777f2e 100644 --- a/hive/handlers/ec2/instance/service_nats_test.go +++ b/hive/handlers/ec2/instance/service_nats_test.go @@ -333,7 +333,7 @@ func TestNATSInstanceService_RunInstances_MultipleInstances(t *testing.T) { // Create reservation with count matching MinCount count := int(*input.MinCount) instances := make([]*ec2.Instance, count) - for i := 0; i < count; i++ { + for i := range count { instanceId := aws.String(aws.StringValue(aws.String(fmt.Sprintf("i-%d", i)))) instances[i] = &ec2.Instance{ InstanceId: instanceId, @@ -409,7 +409,7 @@ func TestNATSInstanceService_RunInstances_QueueGroup(t *testing.T) { // Send multiple requests requestCount := 10 - for i := 0; i < requestCount; i++ { + for range requestCount { reservation, err := service.RunInstances(input) require.NoError(t, err) require.NotNil(t, reservation) diff --git a/hive/handlers/ec2/key/service_impl.go b/hive/handlers/ec2/key/service_impl.go index 59487c975..0bc84dd7f 100644 --- a/hive/handlers/ec2/key/service_impl.go +++ b/hive/handlers/ec2/key/service_impl.go @@ -2,8 +2,8 @@ package handlers_ec2_key import ( "bytes" - "crypto/md5" - "crypto/sha1" + "crypto/md5" //#nosec G501 - need md5 for AWS compatibility + "crypto/sha1" //#nosec G505 - need sha256 for AWS compatibility "crypto/sha256" "crypto/tls" "encoding/base64" @@ -222,7 +222,7 @@ func (s *KeyServiceImpl) calculateFingerprint(publicKeyData []byte, keyType stri } else { // RSA uses SHA-1 or MD5 fingerprint // AWS uses MD5 for RSA keys for backward compatibility - hash := md5.Sum(keyData) + hash := md5.Sum(keyData) //#nosec G401 - need md5 for AWS compatibility return formatFingerprint(hash[:], "MD5"), nil } } @@ -240,8 +240,8 @@ func formatFingerprint(hash []byte, algorithm string) string { // generateKeyPairID generates a unique key pair ID (similar to AWS key-xxxxx format) func generateKeyPairID() string { - hash := sha1.New() - hash.Write([]byte(fmt.Sprintf("%d", os.Getpid()))) + hash := sha1.New() //#nosec G401 - need sha1 for AWS compatibility + hash.Write(fmt.Appendf(nil, "%d", os.Getpid())) return fmt.Sprintf("%x", hash.Sum(nil))[:16] } @@ -567,7 +567,7 @@ func (s *KeyServiceImpl) ImportKeyPair(input *ec2.ImportKeyPairInput) (*ec2.Impo return nil, errors.New(awserrors.ErrorMissingParameter) } - if input.PublicKeyMaterial == nil || len(input.PublicKeyMaterial) == 0 { + if len(input.PublicKeyMaterial) == 0 { return nil, errors.New(awserrors.ErrorMissingParameter) } diff --git a/hive/handlers/ec2/key/service_impl_test.go b/hive/handlers/ec2/key/service_impl_test.go index a449f70ea..f350256eb 100644 --- a/hive/handlers/ec2/key/service_impl_test.go +++ b/hive/handlers/ec2/key/service_impl_test.go @@ -226,7 +226,7 @@ func TestKeyPairFiltering(t *testing.T) { // Simulate filtering logic from DescribeKeyPairs var filtered []*ec2.KeyPairInfo - if tt.input.KeyNames != nil && len(tt.input.KeyNames) > 0 { + if len(tt.input.KeyNames) > 0 { // Filter by KeyName nameSet := make(map[string]bool) for _, name := range tt.input.KeyNames { @@ -237,7 +237,7 @@ func TestKeyPairFiltering(t *testing.T) { filtered = append(filtered, kp) } } - } else if tt.input.KeyPairIds != nil && len(tt.input.KeyPairIds) > 0 { + } else if len(tt.input.KeyPairIds) > 0 { // Filter by KeyPairId idSet := make(map[string]bool) for _, id := range tt.input.KeyPairIds { @@ -279,19 +279,19 @@ func TestKeyPairMetadataPath(t *testing.T) { accountID := "123456789" tests := []struct { - name string - keyPairId string - expected string + name string + keyPairId string + expected string }{ { - name: "Standard key pair ID", - keyPairId: "key-abcdef123456", - expected: "keys/123456789/key-abcdef123456.json", + name: "Standard key pair ID", + keyPairId: "key-abcdef123456", + expected: "keys/123456789/key-abcdef123456.json", }, { - name: "Short key pair ID", - keyPairId: "key-12345", - expected: "keys/123456789/key-12345.json", + name: "Short key pair ID", + keyPairId: "key-12345", + expected: "keys/123456789/key-12345.json", }, } @@ -310,46 +310,46 @@ func TestKeyPairMetadataPath(t *testing.T) { // TestImportKeyPairKeyTypeDetection tests key type detection from public key material func TestImportKeyPairKeyTypeDetection(t *testing.T) { tests := []struct { - name string - publicKeyData string - expectedType string - expectError bool + name string + publicKeyData string + expectedType string + expectError bool }{ { - name: "ED25519 key", - publicKeyData: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl", - expectedType: "ed25519", - expectError: false, + name: "ED25519 key", + publicKeyData: "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl", + expectedType: "ed25519", + expectError: false, }, { - name: "RSA key", - publicKeyData: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCz...", - expectedType: "rsa", - expectError: false, + name: "RSA key", + publicKeyData: "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCz...", + expectedType: "rsa", + expectError: false, }, { - name: "ECDSA key", - publicKeyData: "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTY...", - expectedType: "ecdsa", - expectError: false, + name: "ECDSA key", + publicKeyData: "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTY...", + expectedType: "ecdsa", + expectError: false, }, { - name: "Invalid format - no key data", - publicKeyData: "ssh-rsa", - expectedType: "", - expectError: true, + name: "Invalid format - no key data", + publicKeyData: "ssh-rsa", + expectedType: "", + expectError: true, }, { - name: "Empty key material", - publicKeyData: "", - expectedType: "", - expectError: true, + name: "Empty key material", + publicKeyData: "", + expectedType: "", + expectError: true, }, { - name: "Unsupported key type", - publicKeyData: "ssh-dss AAAAB3NzaC1kc3MAAACB...", - expectedType: "", - expectError: true, + name: "Unsupported key type", + publicKeyData: "ssh-dss AAAAB3NzaC1kc3MAAACB...", + expectedType: "", + expectError: true, }, } @@ -440,7 +440,7 @@ func TestImportKeyPairInputValidation(t *testing.T) { if tt.input == nil || tt.input.KeyName == nil { hasError = true - } else if tt.input.PublicKeyMaterial == nil || len(tt.input.PublicKeyMaterial) == 0 { + } else if len(tt.input.PublicKeyMaterial) == 0 { hasError = true } diff --git a/hive/qmp/qmp.go b/hive/qmp/qmp.go index c9daa472a..f56227682 100644 --- a/hive/qmp/qmp.go +++ b/hive/qmp/qmp.go @@ -6,7 +6,7 @@ import ( "sync" ) -type unmarshalTarget interface{} +type unmarshalTarget any var CommandResponseTypes = map[string]unmarshalTarget{ "stop": &json.RawMessage{}, @@ -122,8 +122,8 @@ type QMPGreeting struct { } type QMPCommand struct { - Execute string `json:"execute"` - Arguments map[string]interface{} `json:"arguments,omitempty"` + Execute string `json:"execute"` + Arguments map[string]any `json:"arguments,omitempty"` } type QMPResponse struct { diff --git a/hive/s3client/s3client.go b/hive/s3client/s3client.go index c8bbd8be1..6896b9f41 100644 --- a/hive/s3client/s3client.go +++ b/hive/s3client/s3client.go @@ -41,7 +41,7 @@ type Backend struct { Config S3Config } -func New(config interface{}) (backend *Backend) { +func New(config any) (backend *Backend) { return &Backend{S3Backend: S3Backend{config: config.(S3Config)}} } diff --git a/hive/service/service.go b/hive/service/service.go index 298234bd2..2525dc2b8 100644 --- a/hive/service/service.go +++ b/hive/service/service.go @@ -18,7 +18,7 @@ type Service interface { Reload() error } -func New(btype string, config interface{}) (Service, error) { +func New(btype string, config any) (Service, error) { switch btype { case "nats": diff --git a/hive/services/awsgw/awsgw.go b/hive/services/awsgw/awsgw.go index d657ad7b6..222844784 100644 --- a/hive/services/awsgw/awsgw.go +++ b/hive/services/awsgw/awsgw.go @@ -20,7 +20,7 @@ type Service struct { Config *config.ClusterConfig } -func New(cfg interface{}) (svc *Service, err error) { +func New(cfg any) (svc *Service, err error) { svc = &Service{ Config: cfg.(*config.ClusterConfig), } diff --git a/hive/services/hive/hive.go b/hive/services/hive/hive.go index d4f2a5027..94e19e6c5 100644 --- a/hive/services/hive/hive.go +++ b/hive/services/hive/hive.go @@ -16,7 +16,7 @@ type Service struct { ConfigPath string } -func New(cfg interface{}) (svc *Service, err error) { +func New(cfg any) (svc *Service, err error) { svc = &Service{ Config: cfg.(*config.ClusterConfig), } diff --git a/hive/services/nats/nats.go b/hive/services/nats/nats.go index 254ba9878..eb2dac5ed 100644 --- a/hive/services/nats/nats.go +++ b/hive/services/nats/nats.go @@ -26,7 +26,7 @@ type Service struct { Config *Config } -func New(config interface{}) (svc *Service, err error) { +func New(config any) (svc *Service, err error) { svc = &Service{ Config: config.(*Config), } diff --git a/hive/services/predastore/predastore.go b/hive/services/predastore/predastore.go index a69f21ea8..b057e87d3 100644 --- a/hive/services/predastore/predastore.go +++ b/hive/services/predastore/predastore.go @@ -31,7 +31,7 @@ type Service struct { Config *Config } -func New(config interface{}) (svc *Service, err error) { +func New(config any) (svc *Service, err error) { svc = &Service{ Config: config.(*Config), } diff --git a/hive/services/predastore/predastore_integration_test.go b/hive/services/predastore/predastore_integration_test.go index 3f8e536db..4dc12677f 100644 --- a/hive/services/predastore/predastore_integration_test.go +++ b/hive/services/predastore/predastore_integration_test.go @@ -21,6 +21,7 @@ import ( "net/http" "os" "path/filepath" + "slices" "strings" "sync" "testing" @@ -591,7 +592,7 @@ func TestIntegration_MultipleFiles(t *testing.T) { fileCount := 5 keys := make([]string, fileCount) - for i := 0; i < fileCount; i++ { + for i := range fileCount { keys[i] = fmt.Sprintf("multi-test-%d.txt", i) content := fmt.Sprintf("content-file-%d", i) @@ -611,11 +612,8 @@ func TestIntegration_MultipleFiles(t *testing.T) { foundCount := 0 for _, obj := range listResult.Contents { - for _, key := range keys { - if *obj.Key == key { - foundCount++ - break - } + if slices.Contains(keys, *obj.Key) { + foundCount++ } } assert.Equal(t, fileCount, foundCount, "All uploaded files should be listed") diff --git a/hive/services/viperblockd/viperblockd.go b/hive/services/viperblockd/viperblockd.go index 1a9ac2944..c2efb3238 100644 --- a/hive/services/viperblockd/viperblockd.go +++ b/hive/services/viperblockd/viperblockd.go @@ -52,7 +52,7 @@ type Service struct { // nbdkit -p 10812 --pidfile /tmp/vb-vol-1.pid ./lib/nbdkit-viperblock-plugin.so -v -f size=67108864 volume=vol-2 bucket=predastore region=ap-southeast-2 access_key="X" secret_key="Y" base_dir="/tmp/vb/" host="https://127.0.0.1:8443" cache_size=0 -func New(config interface{}) (svc *Service, err error) { +func New(config any) (svc *Service, err error) { svc = &Service{ Config: config.(*Config), } @@ -117,7 +117,7 @@ func launchService(cfg *Config) (err error) { } // TODO: Improve - nc.Publish("ebs.delete.response", []byte(fmt.Sprintf(`{"volume":"%s","deleted":true}`, ebsRequest.Volume))) + nc.Publish("ebs.delete.response", fmt.Appendf(nil, `{"volume":"%s","deleted":true}`, ebsRequest.Volume)) }) diff --git a/hive/services/viperblockd/viperblockd_integration_test.go b/hive/services/viperblockd/viperblockd_integration_test.go index db15d324f..ea6a228e8 100644 --- a/hive/services/viperblockd/viperblockd_integration_test.go +++ b/hive/services/viperblockd/viperblockd_integration_test.go @@ -69,7 +69,7 @@ func createMockVolumeState(t *testing.T, baseDir, volumeName string) { // Create a mock state file stateFile := filepath.Join(volumeDir, "state.json") - mockState := map[string]interface{}{ + mockState := map[string]any{ "volume_name": volumeName, "volume_size": 1073741824, // 1GB "created_at": time.Now().Unix(), diff --git a/hive/services/viperblockd/viperblockd_test.go b/hive/services/viperblockd/viperblockd_test.go index b8bde32e5..e161e3965 100644 --- a/hive/services/viperblockd/viperblockd_test.go +++ b/hive/services/viperblockd/viperblockd_test.go @@ -124,7 +124,7 @@ func TestConfigMutexThreadSafety(t *testing.T) { iterations := 100 // Spawn multiple goroutines to append volumes concurrently - for i := 0; i < iterations; i++ { + for i := range iterations { wg.Add(1) go func(id int) { defer wg.Done() @@ -353,7 +353,7 @@ func TestConfigConcurrentRead(t *testing.T) { iterations := 50 // Spawn multiple goroutines to read volumes concurrently - for i := 0; i < iterations; i++ { + for range iterations { wg.Add(1) go func() { defer wg.Done() diff --git a/hive/utils/utils.go b/hive/utils/utils.go index c9057f916..e0fc9284f 100644 --- a/hive/utils/utils.go +++ b/hive/utils/utils.go @@ -243,7 +243,10 @@ func RemovePidFile(serviceName string) error { pidPath := pidPath() - os.Remove(filepath.Join(pidPath, fmt.Sprintf("%s.pid", serviceName))) + err := os.Remove(filepath.Join(pidPath, fmt.Sprintf("%s.pid", serviceName))) + if err != nil { + return err + } return nil } @@ -276,7 +279,10 @@ func StopProcess(serviceName string) error { } // Remove PID file - RemovePidFile(serviceName) + err = RemovePidFile(serviceName) + if err != nil { + return err + } return nil } @@ -362,7 +368,7 @@ func dirExists(path string) bool { } // Convert interface to XML -func MarshalToXML(payload interface{}) ([]byte, error) { +func MarshalToXML(payload any) ([]byte, error) { var buf bytes.Buffer enc := xml.NewEncoder(&buf) @@ -372,14 +378,18 @@ func MarshalToXML(payload interface{}) ([]byte, error) { slog.Error("BuildXML failed", "err", err) return nil, err } - enc.Flush() + + if err := enc.Flush(); err != nil { + slog.Error("Flush failed", "err", err) + return nil, err + } return buf.Bytes(), nil } // wrapWithLocation decorates payload with the requested locationName tag. -func GenerateXMLPayload(locationName string, payload interface{}) interface{} { +func GenerateXMLPayload(locationName string, payload any) any { t := reflect.StructOf([]reflect.StructField{ { Name: "Value", @@ -431,7 +441,7 @@ func ValidateErrorPayload(payload []byte) (responseError ec2.ResponseError, err // Unmarshal payload -func UnmarshalJsonPayload(input interface{}, jsonData []byte) []byte { +func UnmarshalJsonPayload(input any, jsonData []byte) []byte { decoder := json.NewDecoder(bytes.NewReader(jsonData)) decoder.DisallowUnknownFields() @@ -447,7 +457,7 @@ func UnmarshalJsonPayload(input interface{}, jsonData []byte) []byte { } -func MarshalJsonPayload(input interface{}, jsonData []byte) []byte { +func MarshalJsonPayload(input any, jsonData []byte) []byte { decoder := json.NewDecoder(bytes.NewReader(jsonData)) decoder.DisallowUnknownFields() diff --git a/hive/utils/utils_test.go b/hive/utils/utils_test.go index 8a6a41c0b..bb717345b 100644 --- a/hive/utils/utils_test.go +++ b/hive/utils/utils_test.go @@ -323,7 +323,7 @@ func TestMarshalToXML(t *testing.T) { tests := []struct { name string - input interface{} + input any expectError bool validate func(t *testing.T, xmlData []byte) }{ diff --git a/hive/vm/vm.go b/hive/vm/vm.go index 4f75be53c..4d4b982a2 100644 --- a/hive/vm/vm.go +++ b/hive/vm/vm.go @@ -208,7 +208,7 @@ func (cfg *Config) Execute() (*exec.Cmd, error) { qemuArchitecture = "qemu-system-x86_64" } else { - return nil, fmt.Errorf("Architecture missing") + return nil, fmt.Errorf("architecture missing") } // Note, require `-M` machine type for ARM (virt) if set to q35 (incompatible) diff --git a/tests/gosec-report.txt b/tests/gosec-report.txt deleted file mode 100644 index 032a5e54b..000000000 --- a/tests/gosec-report.txt +++ /dev/null @@ -1,1749 +0,0 @@ -Results: - - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:299] - G115 (CWE-190): integer overflow conversion uint64 -> int64 (Confidence: MEDIUM, Severity: HIGH) - 298: Verbose: true, - > 299: Size: int64(vb.GetVolumeSize()), - 300: Volume: ebsRequest.Name, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/image/service_impl.go:187] - G115 (CWE-190): integer overflow conversion uint64 -> int64 (Confidence: MEDIUM, Severity: HIGH) - 186: Ebs: &ec2.EbsBlockDevice{ - > 187: VolumeSize: aws.Int64(int64(amiMeta.VolumeSizeGiB)), - 188: VolumeType: aws.String("gp3"), - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:790] - G115 (CWE-190): integer overflow conversion int64 -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 789: - > 790: pterm.Printf("Saved %s (%s)\n", filename, humanBytes(uint64(written))) - 791: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:781] - G115 (CWE-190): integer overflow conversion int64 -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 780: written += int64(n) - > 781: spin.UpdateText(fmt.Sprintf("Downloading %s (%s) ...", name, humanBytes(uint64(written)))) - 782: })) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:767] - G115 (CWE-190): integer overflow conversion int64 -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 766: - > 767: pterm.Printf("Saved %s (%s)\n", filename, humanBytes(uint64(written))) - 768: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/admin.go:402] - G115 (CWE-190): integer overflow conversion int64 -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 401: VolumeName: volumeId, - > 402: VolumeSize: uint64(imageStat.Size()), - 403: BaseDir: tmpDir, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/admin.go:392] - G115 (CWE-190): integer overflow conversion int64 -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 391: VolumeName: volumeId, - > 392: VolumeSize: uint64(imageStat.Size()), - 393: Bucket: appConfig.Nodes[appConfig.Node].Predastore.Bucket, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/admin.go:352] - G115 (CWE-190): integer overflow conversion int64 -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 351: manifest.AMIMetadata.ImageOwnerAlias = "system" - > 352: manifest.AMIMetadata.VolumeSizeGiB = uint64(imageStat.Size() / 1024 / 1024 / 1024) - 353: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:501] - G115 (CWE-190): integer overflow conversion int -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 500: VolumeName: cloudInitVolumeName, - > 501: VolumeSize: uint64(cloudInitSize), - 502: BaseDir: s.config.WalDir, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:491] - G115 (CWE-190): integer overflow conversion int -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 490: VolumeName: cloudInitVolumeName, - > 491: VolumeSize: uint64(cloudInitSize), - 492: Bucket: s.config.Predastore.Bucket, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:410] - G115 (CWE-190): integer overflow conversion int -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 409: VolumeName: efiVolumeName, - > 410: VolumeSize: uint64(efiSize), - 411: BaseDir: s.config.WalDir, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:400] - G115 (CWE-190): integer overflow conversion int -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 399: VolumeName: efiVolumeName, - > 400: VolumeSize: uint64(efiSize), - 401: Bucket: s.config.Predastore.Bucket, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:305] - G115 (CWE-190): integer overflow conversion int -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 304: VolumeName: *input.ImageId, - > 305: VolumeSize: uint64(size), - 306: BaseDir: s.config.WalDir, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:295] - G115 (CWE-190): integer overflow conversion int -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 294: VolumeName: *input.ImageId, - > 295: VolumeSize: uint64(size), - 296: Bucket: s.config.Predastore.Bucket, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:232] - G115 (CWE-190): integer overflow conversion int -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 231: VolumeName: imageId, - > 232: VolumeSize: uint64(size), - 233: BaseDir: s.config.WalDir, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:222] - G115 (CWE-190): integer overflow conversion int -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 221: VolumeName: imageId, - > 222: VolumeSize: uint64(size), - 223: Bucket: s.config.Predastore.Bucket, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:185] - G115 (CWE-190): integer overflow conversion int -> uint64 (Confidence: MEDIUM, Severity: HIGH) - 184: VolumeID: imageId, - > 185: SizeGiB: uint64(size / 1024 / 1024 / 1024), - 186: CreatedAt: time.Now(), - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:175] - G404 (CWE-338): Use of weak random number generator (math/rand or math/rand/v2 instead of crypto/rand) (Confidence: MEDIUM, Severity: HIGH) - 174: if strings.HasPrefix(*input.ImageId, "ami-") { - > 175: randomNumber := rand.Intn(100_000_000) - 176: imageId = viperblock.GenerateVolumeID("vol", fmt.Sprintf("%d-%s", randomNumber, *input.ImageId), "predastore", time.Now().Unix()) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:691] - G402 (CWE-295): TLS InsecureSkipVerify set true. (Confidence: HIGH, Severity: HIGH) - 690: tr := &http.Transport{ - > 691: TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - 692: } - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/s3client/s3client.go:55] - G402 (CWE-295): TLS InsecureSkipVerify set true. (Confidence: HIGH, Severity: HIGH) - 54: - > 55: tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}} - 56: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:46] - G402 (CWE-295): TLS InsecureSkipVerify set true. (Confidence: HIGH, Severity: HIGH) - 45: TLSClientConfig: &tls.Config{ - > 46: InsecureSkipVerify: true, // Skip TLS verification for self-signed certs - 47: }, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/image/service_impl.go:36] - G402 (CWE-295): TLS InsecureSkipVerify set true. (Confidence: HIGH, Severity: HIGH) - 35: TLSClientConfig: &tls.Config{ - > 36: InsecureSkipVerify: true, // Skip TLS verification for self-signed certs - 37: }, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/admin.go:714] - G402 (CWE-295): TLS InsecureSkipVerify set true. (Confidence: HIGH, Severity: HIGH) - 713: Transport: &http.Transport{ - > 714: TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // Skip TLS verification for self-signed certs - 715: }, - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:243] - G401 (CWE-328): Use of weak cryptographic primitive (Confidence: HIGH, Severity: MEDIUM) - 242: func generateKeyPairID() string { - > 243: hash := sha1.New() - 244: hash.Write([]byte(fmt.Sprintf("%d", os.Getpid()))) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:225] - G401 (CWE-328): Use of weak cryptographic primitive (Confidence: HIGH, Severity: MEDIUM) - 224: // AWS uses MD5 for RSA keys for backward compatibility - > 225: hash := md5.Sum(keyData) - 226: return formatFingerprint(hash[:], "MD5"), nil - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/vm/vm.go:236] - G204 (CWE-78): Subprocess launched with variable (Confidence: HIGH, Severity: MEDIUM) - 235: - > 236: cmd := exec.Command(qemuArchitecture, args...) - 237: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:669] - G204 (CWE-78): Subprocess launched with variable (Confidence: HIGH, Severity: MEDIUM) - 668: - > 669: cmd := exec.Command("file", args...) - 670: output, _ := cmd.CombinedOutput() - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:617] - G204 (CWE-78): Subprocess launched with variable (Confidence: HIGH, Severity: MEDIUM) - 616: - > 617: cmd := exec.Command(execCmd, args...) - 618: output, err := cmd.CombinedOutput() - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:557] - G204 (CWE-78): Subprocess launched with variable (Confidence: HIGH, Severity: MEDIUM) - 556: - > 557: cmd := exec.Command(execCmd, args...) - 558: _, err = cmd.Output() - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/nbd/nbd.go:54] - G204 (CWE-78): Subprocess launched with variable (Confidence: HIGH, Severity: MEDIUM) - 53: - > 54: cmd := exec.Command("nbdkit", args...) - 55: cmd.Stdout = os.Stdout - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:128] - G204 (CWE-78): Subprocess launched with variable (Confidence: HIGH, Severity: MEDIUM) - 127: // RSA 2048-bit key - > 128: cmd = exec.Command("ssh-keygen", "-t", "rsa", "-b", "2048", "-f", privateKeyPath, "-N", "", "-C", "") - 129: } - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:125] - G204 (CWE-78): Subprocess launched with variable (Confidence: HIGH, Severity: MEDIUM) - 124: // ED25519 key (modern, recommended) - > 125: cmd = exec.Command("ssh-keygen", "-t", "ed25519", "-f", privateKeyPath, "-N", "", "-C", "") - 126: } else { - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:739] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) - 738: - > 739: f, err := os.Create(filename) - 740: if err != nil { - -Autofix: Consider using os.Root to scope file access under a fixed root (Go >=1.24). Prefer root.Open/root.Stat over os.Open/os.Stat to prevent directory traversal. - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:230] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) - 229: - > 230: pidFile, err := os.Create(pidFilename) - 231: - -Autofix: Consider using os.Root to scope file access under a fixed root (Go >=1.24). Prefer root.Open/root.Stat over os.Open/os.Stat to prevent directory traversal. - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:179] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) - 178: - > 179: pidFile, err := os.ReadFile(filepath.Join(pidPath, fmt.Sprintf("%s.pid", name))) - 180: - -Autofix: Consider using os.Root to scope file access under a fixed root (Go >=1.24). Prefer root.Open/root.Stat over os.Open/os.Stat to prevent directory traversal. - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:147] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) - 146: // Read public key - > 147: publicKeyData, err := os.ReadFile(publicKeyPath) - 148: if err != nil { - -Autofix: Consider using os.Root to scope file access under a fixed root (Go >=1.24). Prefer root.Open/root.Stat over os.Open/os.Stat to prevent directory traversal. - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:140] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) - 139: // Read private key - > 140: privateKeyData, err := os.ReadFile(privateKeyPath) - 141: if err != nil { - -Autofix: Consider using os.Root to scope file access under a fixed root (Go >=1.24). Prefer root.Open/root.Stat over os.Open/os.Stat to prevent directory traversal. - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:645] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) - 644: configPath := fmt.Sprintf("%s/%s", d.config.BaseDir, "instances.json") - > 645: jsonData, err := os.ReadFile(configPath) - 646: if err != nil { - -Autofix: Consider using os.Root to scope file access under a fixed root (Go >=1.24). Prefer root.Open/root.Stat over os.Open/os.Stat to prevent directory traversal. - -[/Users/benduncan/Development/mulga/hive/hive/admin/admin.go:266] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) - 265: // Write private key to file - > 266: keyOut, err := os.OpenFile(keyPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - 267: if err != nil { - -Autofix: Consider using os.Root to scope file access under a fixed root (Go >=1.24). Prefer root.Open/root.Stat over os.Open/os.Stat to prevent directory traversal. - -[/Users/benduncan/Development/mulga/hive/hive/admin/admin.go:255] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) - 254: // Write certificate to file - > 255: certOut, err := os.Create(certPath) - 256: if err != nil { - -Autofix: Consider using os.Root to scope file access under a fixed root (Go >=1.24). Prefer root.Open/root.Stat over os.Open/os.Stat to prevent directory traversal. - -[/Users/benduncan/Development/mulga/hive/hive/admin/admin.go:67] - G304 (CWE-22): Potential file inclusion via variable (Confidence: HIGH, Severity: MEDIUM) - 66: // Create file with secure permissions - > 67: f, err := os.OpenFile(configPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) - 68: if err != nil { - -Autofix: Consider using os.Root to scope file access under a fixed root (Go >=1.24). Prefer root.Open/root.Stat over os.Open/os.Stat to prevent directory traversal. - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:661] - G302 (CWE-276): Expect file permissions to be 0600 or less (Confidence: HIGH, Severity: MEDIUM) - 660: - > 661: outputFile, err := os.OpenFile(tempFile.Name(), os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) - 662: if err != nil { - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/admin/admin.go:123] - G301 (CWE-276): Expect directory permissions to be 0750 or less (Confidence: HIGH, Severity: MEDIUM) - 122: if _, err := os.Stat(dir); os.IsNotExist(err) { - > 123: if err := os.MkdirAll(dir, 0755); err != nil { - 124: fmt.Fprintf(os.Stderr, "Warning: Could not create %s: %v\n", dir, err) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:608] - G306 (CWE-276): Expect WriteFile permissions to be 0600 or less (Confidence: HIGH, Severity: MEDIUM) - 607: configPath := fmt.Sprintf("%s/%s", d.config.BaseDir, "instances.json") - > 608: err = os.WriteFile(configPath, jsonData, 0644) - 609: if err != nil { - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/admin.go:375] - G306 (CWE-276): Expect WriteFile permissions to be 0600 or less (Confidence: HIGH, Severity: MEDIUM) - 374: // Write to file - > 375: err = os.WriteFile(manifestFilename, jsonData, 0644) - 376: if err != nil { - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:6] - G505 (CWE-327): Blocklisted import crypto/sha1: weak cryptographic primitive (Confidence: HIGH, Severity: MEDIUM) - 5: "crypto/md5" - > 6: "crypto/sha1" - 7: "crypto/sha256" - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:5] - G501 (CWE-327): Blocklisted import crypto/md5: weak cryptographic primitive (Confidence: HIGH, Severity: MEDIUM) - 4: "bytes" - > 5: "crypto/md5" - 6: "crypto/sha1" - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:784] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 783: _, err = io.Copy(f, reader) - > 784: spin.Stop() - 785: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:762] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 761: _, err = io.Copy(f, reader) - > 762: bar.Stop() - 763: if err != nil { - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:375] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 374: } - > 375: enc.Flush() - 376: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:279] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 278: // Remove PID file - > 279: RemovePidFile(serviceName) - 280: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:246] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 245: - > 246: os.Remove(filepath.Join(pidPath, fmt.Sprintf("%s.pid", serviceName))) - 247: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/utils/utils.go:237] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 236: defer pidFile.Close() - > 237: pidFile.WriteString(fmt.Sprintf("%d", pid)) - 238: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:412] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 411: slog.Info("Killing nbdkit process", "pid", volume.PID) - > 412: utils.KillProcess(volume.PID) - 413: } - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:393] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 392: - > 393: nc.Publish("ebs.mount.response", response) - 394: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:391] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 390: - > 391: msg.Respond(response) - 392: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:365] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 364: msg.Respond(response) - > 365: nc.Publish("ebs.mount.response", response) - 366: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:364] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 363: response, _ := json.Marshal(ebsResponse) - > 364: msg.Respond(response) - 365: nc.Publish("ebs.mount.response", response) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:351] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 350: msg.Respond(response) - > 351: nc.Publish("ebs.mount.response", response) - 352: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:350] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 349: response, _ := json.Marshal(ebsResponse) - > 350: msg.Respond(response) - 351: nc.Publish("ebs.mount.response", response) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:268] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 267: msg.Respond(response) - > 268: nc.Publish("ebs.mount.response", response) - 269: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:267] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 266: response, _ := json.Marshal(ebsResponse) - > 267: msg.Respond(response) - 268: nc.Publish("ebs.mount.response", response) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:254] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 253: msg.Respond(response) - > 254: nc.Publish("ebs.mount.response", response) - 255: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:253] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 252: response, _ := json.Marshal(ebsResponse) - > 253: msg.Respond(response) - 254: nc.Publish("ebs.mount.response", response) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:241] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 240: msg.Respond(response) - > 241: nc.Publish("ebs.mount.response", response) - 242: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:240] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 239: response, _ := json.Marshal(ebsResponse) - > 240: msg.Respond(response) - 241: nc.Publish("ebs.mount.response", response) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:225] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 224: msg.Respond(response) - > 225: nc.Publish("ebs.mount.response", response) - 226: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:224] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 223: response, _ := json.Marshal(ebsResponse) - > 224: msg.Respond(response) - 225: nc.Publish("ebs.mount.response", response) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:217] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 216: slog.Info("Setting cache size to 5% of system memory for volume", "volume", ebsRequest.Name) - > 217: vb.SetCacheSystemMemory(5) - 218: } - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:173-396] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 172: - > 173: nc.QueueSubscribe("ebs.mount", "hive-workers", func(msg *nats.Msg) { - > 174: slog.Info("Received message:", "data", string(msg.Data)) - > 175: - > 176: // Parse the message - > 177: var ebsRequest config.EBSRequest - > 178: err := json.Unmarshal(msg.Data, &ebsRequest) - > 179: if err != nil { - > 180: slog.Error("Failed to unmarshal message", "err", err) - > 181: return - > 182: } - > 183: - > 184: slog.Info("ebs.mount", "request", ebsRequest) - > 185: - > 186: var ebsResponse config.EBSMountResponse - > 187: ebsResponse.Mounted = false - > 188: - > 189: s3cfg := s3.S3Config{ - > 190: VolumeName: ebsRequest.Name, - > 191: Bucket: cfg.Bucket, - > 192: Region: cfg.Region, - > 193: AccessKey: cfg.AccessKey, - > 194: SecretKey: cfg.SecretKey, - > 195: Host: cfg.S3Host, - > 196: } - > 197: - > 198: vbconfig := viperblock.VB{ - > 199: VolumeName: ebsRequest.Name, - > 200: VolumeSize: 1, // Workaround, calculated on LoadState() - > 201: BaseDir: cfg.BaseDir, - > 202: Cache: viperblock.Cache{ - > 203: Config: viperblock.CacheConfig{ - > 204: // TODO: Improve, based on system memory - > 205: Size: 0, - > 206: }, - > 207: }, - > 208: VolumeConfig: viperblock.VolumeConfig{}, - > 209: } - > 210: - > 211: vb, err := viperblock.New(vbconfig, "s3", s3cfg) - > 212: - > 213: // TODO: Improve - > 214: // 5% of system memory for cache for master volumes - > 215: if !strings.HasSuffix("-cloudinit", ebsRequest.Name) && !strings.HasSuffix("-efi", ebsRequest.Name) { - > 216: slog.Info("Setting cache size to 5% of system memory for volume", "volume", ebsRequest.Name) - > 217: vb.SetCacheSystemMemory(5) - > 218: } - > 219: - > 220: if err != nil { - > 221: ebsResponse.Error = fmt.Sprintf("Failed to connect to Viperblock store: %v", err) - > 222: // Marshal and send error response immediately - > 223: response, _ := json.Marshal(ebsResponse) - > 224: msg.Respond(response) - > 225: nc.Publish("ebs.mount.response", response) - > 226: return - > 227: } - > 228: - > 229: if cfg.Debug { - > 230: vb.SetDebug(true) - > 231: } - > 232: - > 233: // Initialize the backend - > 234: err = vb.Backend.Init() - > 235: - > 236: if err != nil { - > 237: ebsResponse.Error = err.Error() - > 238: // Marshal and send error response immediately - > 239: response, _ := json.Marshal(ebsResponse) - > 240: msg.Respond(response) - > 241: nc.Publish("ebs.mount.response", response) - > 242: return - > 243: } - > 244: - > 245: // Next, connect to the volume and confirm the state - > 246: // First, fetch the state from the remote backend - > 247: err = vb.LoadState() - > 248: - > 249: if err != nil { - > 250: ebsResponse.Error = err.Error() - > 251: // Marshal and send error response immediately - > 252: response, _ := json.Marshal(ebsResponse) - > 253: msg.Respond(response) - > 254: nc.Publish("ebs.mount.response", response) - > 255: return - > 256: } - > 257: - > 258: // Next, mount the volume using nbdkit - > 259: - > 260: // Step 1: Find a free port - > 261: nbdUri, err := viperblock.FindFreePort() - > 262: - > 263: if err != nil { - > 264: ebsResponse.Error = err.Error() - > 265: // Marshal and send error response immediately - > 266: response, _ := json.Marshal(ebsResponse) - > 267: msg.Respond(response) - > 268: nc.Publish("ebs.mount.response", response) - > 269: return - > 270: } - > 271: - > 272: // Mount the volume - > 273: nbdPort := strings.Split(nbdUri, ":") - > 274: - > 275: // Port is the last - > 276: port, err := strconv.Atoi(nbdPort[len(nbdPort)-1]) - > 277: if err != nil { - > 278: slog.Error("Failed to convert port to int", "err", err) - > 279: return - > 280: } - > 281: - > 282: slog.Info("Mounting volume", "name", ebsRequest.Name, "port", port, "uri", nbdUri) - > 283: - > 284: // Execute nbdkit - > 285: - > 286: nbdPidFile, err := utils.GeneratePidFile(fmt.Sprintf("nbdkit-vol-%s", ebsRequest.Name)) - > 287: if err != nil { - > 288: slog.Error("Failed to generate nbdkit pid file:", "err", err) - > 289: return - > 290: } - > 291: - > 292: nbdConfig := nbd.NBDKitConfig{ - > 293: Port: port, - > 294: PidFile: nbdPidFile, - > 295: PluginPath: cfg.PluginPath, - > 296: BaseDir: cfg.BaseDir, - > 297: Host: cfg.S3Host, - > 298: Verbose: true, - > 299: Size: int64(vb.GetVolumeSize()), - > 300: Volume: ebsRequest.Name, - > 301: Bucket: cfg.Bucket, - > 302: Region: cfg.Region, - > 303: AccessKey: cfg.AccessKey, - > 304: SecretKey: cfg.SecretKey, - > 305: } - > 306: - > 307: // Create a unique error channel for this specific mount request - > 308: processChan := make(chan int, 1) - > 309: exitChan := make(chan int, 1) - > 310: - > 311: // TODO: Improve, use a process manager to track the (multiple) nbdkit process - > 312: go func() { - > 313: fmt.Println("Executing nbdkit") - > 314: - > 315: cmd, err := nbdConfig.Execute() - > 316: pid := cmd.Process.Pid - > 317: - > 318: if err != nil { - > 319: slog.Error("Failed to execute nbdkit", "err", err) - > 320: // Signal error (no PID) to parent goroutine - > 321: processChan <- 0 - > 322: return - > 323: } - > 324: - > 325: // Signal successful startup w/ PID - > 326: processChan <- pid - > 327: - > 328: err = cmd.Wait() - > 329: - > 330: if err != nil { - > 331: slog.Error("Failed to wait for nbdkit", "err", err) - > 332: exitChan <- 1 - > 333: return - > 334: } - > 335: - > 336: exitCode := cmd.ProcessState.ExitCode() - > 337: - > 338: exitChan <- exitCode - > 339: - > 340: slog.Error("NBDKit exited", "code", exitCode) - > 341: }() - > 342: - > 343: // Wait for startup result - > 344: pid := <-processChan - > 345: - > 346: if pid == 0 { - > 347: ebsResponse.Error = "Failed to start nbdkit" - > 348: // Marshal and send error response immediately - > 349: response, _ := json.Marshal(ebsResponse) - > 350: msg.Respond(response) - > 351: nc.Publish("ebs.mount.response", response) - > 352: return - > 353: } - > 354: - > 355: // Wait for 1 second to confirm nbdkit is running - > 356: time.Sleep(1 * time.Second) - > 357: - > 358: // Check if nbdkit exited immediately with an error - > 359: select { - > 360: case exitErr := <-exitChan: - > 361: if exitErr != 0 { - > 362: ebsResponse.Error = fmt.Sprintf("nbdkit failed: %v", exitErr) - > 363: response, _ := json.Marshal(ebsResponse) - > 364: msg.Respond(response) - > 365: nc.Publish("ebs.mount.response", response) - > 366: return - > 367: } - > 368: default: - > 369: // nbdkit is still running after 1 second, which means it started successfully - > 370: slog.Info("NBDKit started successfully and is running") - > 371: } - > 372: - > 373: ebsResponse.Mounted = true - > 374: ebsResponse.URI = nbdUri - > 375: - > 376: cfg.mu.Lock() - > 377: cfg.MountedVolumes = append(cfg.MountedVolumes, MountedVolume{ - > 378: Name: ebsRequest.Name, - > 379: Port: port, - > 380: PID: pid, - > 381: }) - > 382: cfg.mu.Unlock() - > 383: - > 384: // Marshal the response - > 385: response, err := json.Marshal(ebsResponse) - > 386: if err != nil { - > 387: slog.Error("Failed to marshal response", "err", err) - > 388: return - > 389: } - > 390: - > 391: msg.Respond(response) - > 392: - > 393: nc.Publish("ebs.mount.response", response) - > 394: - > 395: slog.Debug("Sent ebs.mount response", "response", string(response)) - > 396: }) - 397: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:170] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 169: msg.Respond(response) - > 170: nc.Publish("ebs.unmount.response", response) - 171: }) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:169] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 168: - > 169: msg.Respond(response) - 170: nc.Publish("ebs.unmount.response", response) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:148] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 147: - > 148: utils.KillProcess(volume.PID) - 149: match = true - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:124-171] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 123: - > 124: nc.QueueSubscribe("ebs.unmount", "hive-workers", func(msg *nats.Msg) { - > 125: slog.Info("Received message", "data", string(msg.Data)) - > 126: - > 127: // Parse the message - > 128: var ebsRequest config.EBSRequest - > 129: err := json.Unmarshal(msg.Data, &ebsRequest) - > 130: if err != nil { - > 131: slog.Error("Failed to unmarshal message", "err", err) - > 132: return - > 133: } - > 134: - > 135: // Find the volume in the mounted volumes - > 136: var ebsResponse config.EBSUnMountResponse - > 137: var match bool - > 138: cfg.mu.Lock() - > 139: for _, volume := range cfg.MountedVolumes { - > 140: - > 141: // TODO: Confirm KVM/QEMU is not using the volume first. - > 142: if volume.Name == ebsRequest.Name { - > 143: ebsResponse = config.EBSUnMountResponse{ - > 144: Volume: volume.Name, - > 145: Mounted: false, - > 146: } - > 147: - > 148: utils.KillProcess(volume.PID) - > 149: match = true - > 150: } - > 151: } - > 152: - > 153: cfg.mu.Unlock() - > 154: - > 155: if !match { - > 156: ebsResponse = config.EBSUnMountResponse{ - > 157: Volume: ebsRequest.Name, - > 158: Error: fmt.Sprintf("Volume %s not found", ebsRequest.Name), - > 159: } - > 160: } - > 161: - > 162: // Marshal the response - > 163: response, err := json.Marshal(ebsResponse) - > 164: if err != nil { - > 165: slog.Error("Failed to marshal response", "err", err) - > 166: return - > 167: } - > 168: - > 169: msg.Respond(response) - > 170: nc.Publish("ebs.unmount.response", response) - > 171: }) - 172: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:120] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 119: // TODO: Improve - > 120: nc.Publish("ebs.delete.response", []byte(fmt.Sprintf(`{"volume":"%s","deleted":true}`, ebsRequest.Volume))) - 121: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:108-122] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 107: // TODO: Support volume delete and predastore delete bucket - > 108: nc.QueueSubscribe("ebs.delete", "hive-workers", func(msg *nats.Msg) { - > 109: slog.Info("Received message", "data", string(msg.Data)) - > 110: - > 111: // Parse the message - > 112: var ebsRequest config.EBSDeleteRequest - > 113: err := json.Unmarshal(msg.Data, &ebsRequest) - > 114: if err != nil { - > 115: slog.Error("Failed to unmarshal message", "err", err) - > 116: return - > 117: } - > 118: - > 119: // TODO: Improve - > 120: nc.Publish("ebs.delete.response", []byte(fmt.Sprintf(`{"volume":"%s","deleted":true}`, ebsRequest.Volume))) - > 121: - > 122: }) - 123: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/viperblockd/viperblockd.go:65] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 64: - > 65: utils.WritePidFile(serviceName, os.Getpid()) - 66: err := launchService(svc.Config) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/predastore/predastore.go:44] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 43: - > 44: utils.WritePidFile(serviceName, os.Getpid()) - 45: launchService(svc.Config) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/nats/nats.go:38] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 37: utils.WritePidFile(serviceName, os.Getpid()) - > 38: launchService(svc.Config) - 39: return os.Getpid(), nil - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/nats/nats.go:37] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 36: func (svc *Service) Start() (int, error) { - > 37: utils.WritePidFile(serviceName, os.Getpid()) - 38: launchService(svc.Config) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/hive/hive.go:31] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 30: func (svc *Service) Start() (int, error) { - > 31: utils.WritePidFile(serviceName, os.Getpid()) - 32: err := launchService(svc.Config, svc.ConfigPath) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/services/awsgw/awsgw.go:31] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 30: func (svc *Service) Start() (int, error) { - > 31: utils.WritePidFile(serviceName, os.Getpid()) - 32: err := launchService(svc.Config) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/qmp/qmp.go:158] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 157: if err := client.Decoder.Decode(&greeting); err != nil { - > 158: conn.Close() - 159: return nil, err - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:663-666] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 662: // Try to cleanup the public key we just uploaded - > 663: s.s3Client.DeleteObject(&s3.DeleteObjectInput{ - > 664: Bucket: aws.String(s.config.Predastore.Bucket), - > 665: Key: aws.String(keyPath), - > 666: }) - 667: return nil, errors.New(awserrors.ErrorServerInternal) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:491] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 490: body, err := io.ReadAll(getResult.Body) - > 491: getResult.Body.Close() - 492: if err != nil { - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:348] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 347: body, err := io.ReadAll(getResult.Body) - > 348: getResult.Body.Close() - 349: if err != nil { - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/key/service_impl.go:189-192] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 188: // Try to cleanup the public key we just uploaded - > 189: s.s3Client.DeleteObject(&s3.DeleteObjectInput{ - > 190: Bucket: aws.String(s.config.Predastore.Bucket), - > 191: Key: aws.String(keyPath), - > 192: }) - 193: return nil, errors.New(awserrors.ErrorServerInternal) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:700] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 699: cloudInitVb.Flush() - > 700: cloudInitVb.WriteWALToChunk(true) - 701: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:699] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 698: // Flush - > 699: cloudInitVb.Flush() - 700: cloudInitVb.WriteWALToChunk(true) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:456] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 455: efiVb.WriteAt(0, make([]byte, efiVb.BlockSize)) - > 456: efiVb.Flush() - 457: } - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:455] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 454: // Write an empty block to the EFI volume - > 455: efiVb.WriteAt(0, make([]byte, efiVb.BlockSize)) - 456: efiVb.Flush() - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:374] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 373: destVb.Flush() - > 374: destVb.WriteWALToChunk(true) - 375: } - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:373] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 372: slog.Debug("Flush", "block", block) - > 373: destVb.Flush() - 374: destVb.WriteWALToChunk(true) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/instance/service_impl.go:367] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 366: - > 367: destVb.WriteAt(block*uint64(destVb.BlockSize), data[i*int(destVb.BlockSize):(i+1)*int(destVb.BlockSize)]) - 368: block++ - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/handlers/ec2/image/service_impl.go:112] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 111: body, err := io.ReadAll(getResult.Body) - > 112: getResult.Body.Close() - 113: if err != nil { - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/gateway/ec2.go:270] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 269: - > 270: ctx.Status(fiber.StatusOK).Type("text/xml").Send(xmlOutput) - 271: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1956] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1955: - > 1956: msg.Respond(jsonResponse) - 1957: slog.Debug("Health check responded", "node", d.node, "epoch", d.clusterConfig.Epoch) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1929] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1928: } - > 1929: msg.Respond(jsonResponse) - 1930: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1926] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1925: errResp = utils.GenerateErrorPayload(awserrors.ErrorServerInternal) - > 1926: msg.Respond(errResp) - 1927: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1853] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1852: if errResp != nil { - > 1853: msg.Respond(errResp) - 1854: slog.Error("Request does not match DescribeInstancesInput") - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1835] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1834: } - > 1835: msg.Respond(jsonResponse) - 1836: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1832] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1831: errResp = utils.GenerateErrorPayload(awserrors.ErrorServerInternal) - > 1832: msg.Respond(errResp) - 1833: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1823] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1822: errResp = utils.GenerateErrorPayload(err.Error()) - > 1823: msg.Respond(errResp) - 1824: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1810] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1809: if errResp != nil { - > 1810: msg.Respond(errResp) - 1811: slog.Error("Request does not match DescribeImagesInput") - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1793] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1792: } - > 1793: msg.Respond(jsonResponse) - 1794: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1790] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1789: errResp = utils.GenerateErrorPayload(awserrors.ErrorServerInternal) - > 1790: msg.Respond(errResp) - 1791: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1781] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1780: errResp = utils.GenerateErrorPayload(err.Error()) - > 1781: msg.Respond(errResp) - 1782: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1765] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1764: if errResp != nil { - > 1765: msg.Respond(errResp) - 1766: slog.Error("Request does not match ImportKeyPairInput") - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1748] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1747: } - > 1748: msg.Respond(jsonResponse) - 1749: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1745] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1744: errResp = utils.GenerateErrorPayload(awserrors.ErrorServerInternal) - > 1745: msg.Respond(errResp) - 1746: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1736] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1735: errResp = utils.GenerateErrorPayload(err.Error()) - > 1736: msg.Respond(errResp) - 1737: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1723] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1722: if errResp != nil { - > 1723: msg.Respond(errResp) - 1724: slog.Error("Request does not match DescribeKeyPairsInput") - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1266] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1265: slog.Info("Closing QMP client connection", "instance", instance.ID) - > 1266: instance.QMPClient.Conn.Close() - 1267: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1261] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1260: slog.Info("Unsubscribing from NATS subject", "instance", instance.ID) - > 1261: d.natsSubscriptions[fmt.Sprintf("ec2.cmd.%s", instance.ID)].Unsubscribe() - 1262: //d.natsSubscriptions[fmt.Sprintf("ec2.describe.%s", instance.ID)].Unsubscribe() - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1190] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1189: // Pass instances to terminate - > 1190: d.stopInstance(d.Instances.VMS, false) - 1191: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1167] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1166: slog.Info("Unsubscribing from NATS subject", "instance", instance.ID) - > 1167: d.natsSubscriptions[fmt.Sprintf("ec2.cmd.%s", instance.ID)].Unsubscribe() - 1168: // TODO: Remove redundant subscription if not used - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1111] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1110: // Send SIG directly if QMP fails - > 1111: utils.KillProcess(pid) - 1112: } - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1071] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1070: } - > 1071: msg.Respond(jsonResponse) - 1072: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1068] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1067: errResp = utils.GenerateErrorPayload(awserrors.ErrorServerInternal) - > 1068: msg.Respond(errResp) - 1069: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1059] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1058: errResp = utils.GenerateErrorPayload(err.Error()) - > 1059: msg.Respond(errResp) - 1060: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1041] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1040: if errResp != nil { - > 1041: msg.Respond(errResp) - 1042: slog.Error("Request does not match DeleteKeyPairInput") - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1024] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1023: } - > 1024: msg.Respond(jsonResponse) - 1025: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1021] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1020: errResp = utils.GenerateErrorPayload(awserrors.ErrorServerInternal) - > 1021: msg.Respond(errResp) - 1022: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:1012] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 1011: errResp = utils.GenerateErrorPayload(err.Error()) - > 1012: msg.Respond(errResp) - 1013: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:999] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 998: if errResp != nil { - > 999: msg.Respond(errResp) - 1000: slog.Error("Request does not match CreateKeyPairInput") - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:964] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 963: } - > 964: msg.Respond(jsonResponse) - 965: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:960] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 959: errResp = utils.GenerateErrorPayload(awserrors.ErrorServerInternal) - > 960: msg.Respond(errResp) - 961: d.resourceMgr.deallocate(instanceType) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:950] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 949: errResp = utils.GenerateErrorPayload(awserrors.ErrorServerInternal) - > 950: msg.Respond(errResp) - 951: d.resourceMgr.deallocate(instanceType) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:938] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 937: errResp = utils.GenerateErrorPayload(awserrors.ErrorInsufficientInstanceCapacity) - > 938: msg.Respond(errResp) - 939: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:930] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 929: errResp = utils.GenerateErrorPayload(awserrors.ErrorInsufficientInstanceCapacity) - > 930: msg.Respond(errResp) - 931: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:922] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 921: errResp = utils.GenerateErrorPayload(awserrors.ErrorInvalidInstanceType) - > 922: msg.Respond(errResp) - 923: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:910] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 909: errResp = utils.GenerateErrorPayload(awserrors.ErrorValidationError) - > 910: msg.Respond(errResp) - 911: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:899] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 898: if errResp != nil { - > 899: msg.Respond(errResp) - 900: slog.Error("Request does not match RunInstancesInput") - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:883] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 882: // Respond to NATS - > 883: msg.Respond(resp.Return) - 884: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/daemon/daemon.go:790] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 789: slog.Warn("Instance is not running on this node", "id", command.ID) - > 790: msg.Respond(nil) - 791: return - -Autofix: - -[/Users/benduncan/Development/mulga/hive/hive/config/config.go:142] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 141: - > 142: msg.Respond(response) - 143: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:669] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 668: viper.BindEnv("debug", "HIVE_AWSGW_DEBUG") - > 669: viper.BindPFlag("debug", awsgwCmd.PersistentFlags().Lookup("debug")) - 670: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:668] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 667: awsgwCmd.PersistentFlags().Bool("debug", false, "AWS Gateway Debug") - > 668: viper.BindEnv("debug", "HIVE_AWSGW_DEBUG") - 669: viper.BindPFlag("debug", awsgwCmd.PersistentFlags().Lookup("debug")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:665] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 664: viper.BindEnv("tls-key", "HIVE_AWSGW_TLS_KEY") - > 665: viper.BindPFlag("tls-key", awsgwCmd.PersistentFlags().Lookup("tls-key")) - 666: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:664] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 663: awsgwCmd.PersistentFlags().String("tls-key", "", "AWS Gateway TLS key") - > 664: viper.BindEnv("tls-key", "HIVE_AWSGW_TLS_KEY") - 665: viper.BindPFlag("tls-key", awsgwCmd.PersistentFlags().Lookup("tls-key")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:660] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 659: viper.BindEnv("tls-cert", "HIVE_AWSGW_TLS_CERT") - > 660: viper.BindPFlag("tls-cert", awsgwCmd.PersistentFlags().Lookup("tls-cert")) - 661: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:659] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 658: awsgwCmd.PersistentFlags().String("tls-cert", "", "AWS Gateway TLS certificate") - > 659: viper.BindEnv("tls-cert", "HIVE_AWSGW_TLS_CERT") - 660: viper.BindPFlag("tls-cert", awsgwCmd.PersistentFlags().Lookup("tls-cert")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:655] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 654: viper.BindEnv("host", "HIVE_AWSGW_HOST") - > 655: viper.BindPFlag("host", awsgwCmd.PersistentFlags().Lookup("host")) - 656: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:654] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 653: awsgwCmd.PersistentFlags().String("host", "0.0.0.0:9999", "AWS Gateway server host") - > 654: viper.BindEnv("host", "HIVE_AWSGW_HOST") - 655: viper.BindPFlag("host", awsgwCmd.PersistentFlags().Lookup("host")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:648] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 647: viper.BindEnv("wal-dir", "HIVE_WAL_DIR") - > 648: viper.BindPFlag("wal-dir", hiveCmd.PersistentFlags().Lookup("wal-dir")) - 649: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:647] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 646: hiveCmd.PersistentFlags().String("wal-dir", "", "Write-ahead log (WAL) directory. Place on high-speed NVMe disk, or tmpfs for development.") - > 647: viper.BindEnv("wal-dir", "HIVE_WAL_DIR") - 648: viper.BindPFlag("wal-dir", hiveCmd.PersistentFlags().Lookup("wal-dir")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:637] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 636: viper.BindEnv("jetstream", "HIVE_NATS_JETSTREAM") - > 637: viper.BindPFlag("jetstream", natsCmd.PersistentFlags().Lookup("jetstream")) - 638: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:636] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 635: natsCmd.PersistentFlags().Bool("jetstream", false, "Enable JetStream") - > 636: viper.BindEnv("jetstream", "HIVE_NATS_JETSTREAM") - 637: viper.BindPFlag("jetstream", natsCmd.PersistentFlags().Lookup("jetstream")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:633] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 632: viper.BindEnv("data-dir", "HIVE_NATS_DATA_DIR") - > 633: viper.BindPFlag("data-dir", natsCmd.PersistentFlags().Lookup("data-dir")) - 634: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:632] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 631: natsCmd.PersistentFlags().String("data-dir", "", "NATS data directory") - > 632: viper.BindEnv("data-dir", "HIVE_NATS_DATA_DIR") - 633: viper.BindPFlag("data-dir", natsCmd.PersistentFlags().Lookup("data-dir")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:629] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 628: viper.BindEnv("debug", "HIVE_NATS_DEBUG") - > 629: viper.BindPFlag("debug", natsCmd.PersistentFlags().Lookup("debug")) - 630: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:628] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 627: natsCmd.PersistentFlags().Bool("debug", false, "Enable debug logging") - > 628: viper.BindEnv("debug", "HIVE_NATS_DEBUG") - 629: viper.BindPFlag("debug", natsCmd.PersistentFlags().Lookup("debug")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:625] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 624: viper.BindEnv("host", "HIVE_NATS_HOST") - > 625: viper.BindPFlag("host", natsCmd.PersistentFlags().Lookup("host")) - 626: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:624] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 623: natsCmd.PersistentFlags().String("host", "0.0.0.0", "NATS server host") - > 624: viper.BindEnv("host", "HIVE_NATS_HOST") - 625: viper.BindPFlag("host", natsCmd.PersistentFlags().Lookup("host")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:621] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 620: viper.BindEnv("port", "HIVE_NATS_PORT") - > 621: viper.BindPFlag("port", natsCmd.PersistentFlags().Lookup("port")) - 622: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:620] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 619: natsCmd.PersistentFlags().Int("port", 4222, "NATS server port") - > 620: viper.BindEnv("port", "HIVE_NATS_PORT") - 621: viper.BindPFlag("port", natsCmd.PersistentFlags().Lookup("port")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:605] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 604: viper.BindEnv("plugin-path", "HIVE_VIPERBLOCK_PLUGIN_PATH") - > 605: viper.BindPFlag("plugin-path", predastoreCmd.PersistentFlags().Lookup("plugin-path")) - 606: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:604] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 603: viperblockCmd.PersistentFlags().String("plugin-path", "/opt/hive/lib/nbdkit-viperblock-plugin.so", "Pathname to the nbdkit viperblockplugin") - > 604: viper.BindEnv("plugin-path", "HIVE_VIPERBLOCK_PLUGIN_PATH") - 605: viper.BindPFlag("plugin-path", predastoreCmd.PersistentFlags().Lookup("plugin-path")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:601] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 600: viper.BindEnv("s3-region", "HIVE_VIPERBLOCK_S3_REGION") - > 601: viper.BindPFlag("s3-region", predastoreCmd.PersistentFlags().Lookup("s3-region")) - 602: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:600] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 599: viperblockCmd.PersistentFlags().String("s3-region", "ap-southeast-2", "Predastore (S3) region") - > 600: viper.BindEnv("s3-region", "HIVE_VIPERBLOCK_S3_REGION") - 601: viper.BindPFlag("s3-region", predastoreCmd.PersistentFlags().Lookup("s3-region")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:597] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 596: viper.BindEnv("s3-bucket", "HIVE_VIPERBLOCK_S3_BUCKET") - > 597: viper.BindPFlag("s3-bucket", predastoreCmd.PersistentFlags().Lookup("s3-bucket")) - 598: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:596] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 595: viperblockCmd.PersistentFlags().String("s3-bucket", "predastore", "Predastore (S3) bucket") - > 596: viper.BindEnv("s3-bucket", "HIVE_VIPERBLOCK_S3_BUCKET") - 597: viper.BindPFlag("s3-bucket", predastoreCmd.PersistentFlags().Lookup("s3-bucket")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:593] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 592: viper.BindEnv("s3-host", "HIVE_VIPERBLOCK_S3_HOST") - > 593: viper.BindPFlag("s3-host", predastoreCmd.PersistentFlags().Lookup("s3-host")) - 594: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:592] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 591: viperblockCmd.PersistentFlags().String("s3-host", "0.0.0.0:8443", "Predastore (S3) host URI") - > 592: viper.BindEnv("s3-host", "HIVE_VIPERBLOCK_S3_HOST") - 593: viper.BindPFlag("s3-host", predastoreCmd.PersistentFlags().Lookup("s3-host")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:583] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 582: viper.BindEnv("tls-key", "HIVE_PREDASTORE_TLS_KEY") - > 583: viper.BindPFlag("tls-key", predastoreCmd.PersistentFlags().Lookup("tls-key")) - 584: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:582] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 581: predastoreCmd.PersistentFlags().String("tls-key", "", "Predastore (S3) TLS key") - > 582: viper.BindEnv("tls-key", "HIVE_PREDASTORE_TLS_KEY") - 583: viper.BindPFlag("tls-key", predastoreCmd.PersistentFlags().Lookup("tls-key")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:578] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 577: viper.BindEnv("tls-cert", "HIVE_PREDASTORE_TLS_CERT") - > 578: viper.BindPFlag("tls-cert", predastoreCmd.PersistentFlags().Lookup("tls-cert")) - 579: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:577] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 576: predastoreCmd.PersistentFlags().String("tls-cert", "", "Predastore (S3) TLS certificate") - > 577: viper.BindEnv("tls-cert", "HIVE_PREDASTORE_TLS_CERT") - 578: viper.BindPFlag("tls-cert", predastoreCmd.PersistentFlags().Lookup("tls-cert")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:573] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 572: viper.BindEnv("debug", "HIVE_PREDASTORE_DEBUG") - > 573: viper.BindPFlag("debug", predastoreCmd.PersistentFlags().Lookup("debug")) - 574: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:572] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 571: predastoreCmd.PersistentFlags().Bool("debug", false, "Predastore (S3) debug") - > 572: viper.BindEnv("debug", "HIVE_PREDASTORE_DEBUG") - 573: viper.BindPFlag("debug", predastoreCmd.PersistentFlags().Lookup("debug")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:568] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 567: viper.BindEnv("config-path", "HIVE_PREDASTORE_CONFIG_PATH") - > 568: viper.BindPFlag("config-path", predastoreCmd.PersistentFlags().Lookup("config-path")) - 569: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:567] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 566: predastoreCmd.PersistentFlags().String("config-path", "", "Predastore (S3) config path") - > 567: viper.BindEnv("config-path", "HIVE_PREDASTORE_CONFIG_PATH") - 568: viper.BindPFlag("config-path", predastoreCmd.PersistentFlags().Lookup("config-path")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:563] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 562: viper.BindEnv("base-path", "HIVE_PREDASTORE_BASE_PATH") - > 563: viper.BindPFlag("base-path", predastoreCmd.PersistentFlags().Lookup("base-path")) - 564: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:562] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 561: predastoreCmd.PersistentFlags().String("base-path", "", "Predastore (S3) base path") - > 562: viper.BindEnv("base-path", "HIVE_PREDASTORE_BASE_PATH") - 563: viper.BindPFlag("base-path", predastoreCmd.PersistentFlags().Lookup("base-path")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:558] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 557: viper.BindEnv("host", "HIVE_PREDASTORE_HOST") - > 558: viper.BindPFlag("host", predastoreCmd.PersistentFlags().Lookup("host")) - 559: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:557] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 556: predastoreCmd.PersistentFlags().String("host", "0.0.0.0", "Predastore (S3) host") - > 557: viper.BindEnv("host", "HIVE_PREDASTORE_HOST") - 558: viper.BindPFlag("host", predastoreCmd.PersistentFlags().Lookup("host")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:553] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 552: viper.BindEnv("port", "HIVE_PREDASTORE_PORT") - > 553: viper.BindPFlag("port", predastoreCmd.PersistentFlags().Lookup("port")) - 554: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:552] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 551: predastoreCmd.PersistentFlags().Int("port", 8443, "Predastore (S3) port") - > 552: viper.BindEnv("port", "HIVE_PREDASTORE_PORT") - 553: viper.BindPFlag("port", predastoreCmd.PersistentFlags().Lookup("port")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:525] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 524: - > 525: service.Stop() - 526: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:507] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 506: - > 507: service.Start() - 508: fmt.Println("AWSGW service started") - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:430] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 429: - > 430: service.Stop() - 431: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:412] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 411: - > 412: svc.Start() - 413: fmt.Println("HIVE service started") - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:344] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 343: - > 344: service.Stop() - 345: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:326] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 325: - > 326: service.Start() - 327: fmt.Println("NATS service started") - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:282] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 281: - > 282: service.Stop() - 283: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:137] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 136: - > 137: service.Stop() - 138: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/service.go:118] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 117: - > 118: service.Start() - 119: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:101] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 100: viper.BindEnv("nats-subject", "HIVE_NATS_SUBJECT") - > 101: viper.BindPFlag("nats-subject", rootCmd.PersistentFlags().Lookup("nats-subject")) - 102: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:100] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 99: rootCmd.PersistentFlags().String("nats-subject", "", "NATS subscription subject (overrides config file and env)") - > 100: viper.BindEnv("nats-subject", "HIVE_NATS_SUBJECT") - 101: viper.BindPFlag("nats-subject", rootCmd.PersistentFlags().Lookup("nats-subject")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:97] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 96: viper.BindEnv("nats-token", "HIVE_NATS_TOKEN") - > 97: viper.BindPFlag("nats-token", rootCmd.PersistentFlags().Lookup("nats-token")) - 98: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:96] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 95: rootCmd.PersistentFlags().String("nats-token", "", "NATS authentication token (overrides config file and env)") - > 96: viper.BindEnv("nats-token", "HIVE_NATS_TOKEN") - 97: viper.BindPFlag("nats-token", rootCmd.PersistentFlags().Lookup("nats-token")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:93] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 92: viper.BindEnv("nats-host", "HIVE_NATS_HOST") - > 93: viper.BindPFlag("nats-host", rootCmd.PersistentFlags().Lookup("nats-host")) - 94: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:92] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 91: rootCmd.PersistentFlags().String("nats-host", "", "NATS server host (overrides config file and env)") - > 92: viper.BindEnv("nats-host", "HIVE_NATS_HOST") - 93: viper.BindPFlag("nats-host", rootCmd.PersistentFlags().Lookup("nats-host")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:88] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 87: viper.BindEnv("base-dir", "HIVE_BASE_DIR") - > 88: viper.BindPFlag("base-dir", rootCmd.PersistentFlags().Lookup("base-dir")) - 89: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:87] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 86: rootCmd.PersistentFlags().String("base-dir", "", "Viperblock base directory (overrides config file and env)") - > 87: viper.BindEnv("base-dir", "HIVE_BASE_DIR") - 88: viper.BindPFlag("base-dir", rootCmd.PersistentFlags().Lookup("base-dir")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:83] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 82: viper.BindEnv("host", "HIVE_HOST") - > 83: viper.BindPFlag("host", rootCmd.PersistentFlags().Lookup("host")) - 84: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:82] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 81: rootCmd.PersistentFlags().String("host", "", "AWS Endpoint (overrides config file and env)") - > 82: viper.BindEnv("host", "HIVE_HOST") - 83: viper.BindPFlag("host", rootCmd.PersistentFlags().Lookup("host")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:79] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 78: viper.BindEnv("secret-key", "HIVE_SECRET_KEY") - > 79: viper.BindPFlag("secret-key", rootCmd.PersistentFlags().Lookup("secret-key")) - 80: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:78] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 77: rootCmd.PersistentFlags().String("secret-key", "", "AWS secret key (overrides config file and env)") - > 78: viper.BindEnv("secret-key", "HIVE_SECRET_KEY") - 79: viper.BindPFlag("secret-key", rootCmd.PersistentFlags().Lookup("secret-key")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:75] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 74: viper.BindEnv("access-key", "HIVE_ACCESS_KEY") - > 75: viper.BindPFlag("access-key", rootCmd.PersistentFlags().Lookup("access-key")) - 76: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:74] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 73: rootCmd.PersistentFlags().String("access-key", "", "AWS access key (overrides config file and env)") - > 74: viper.BindEnv("access-key", "HIVE_ACCESS_KEY") - 75: viper.BindPFlag("access-key", rootCmd.PersistentFlags().Lookup("access-key")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:70] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 69: viper.BindEnv("config", "HIVE_CONFIG_PATH") - > 70: viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config")) - 71: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/root.go:69] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 68: rootCmd.PersistentFlags().String("config", "", "config file (required)") - > 69: viper.BindEnv("config", "HIVE_CONFIG_PATH") - 70: viper.BindPFlag("config", rootCmd.PersistentFlags().Lookup("config")) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/admin.go:731] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 730: var errResp config.NodeJoinResponse - > 731: json.Unmarshal(body, &errResp) - 732: fmt.Fprintf(os.Stderr, "❌ Failed to join cluster: %s\n", errResp.Message) - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/admin.go:456] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 455: // The Render() method is used to print the table to the console. - > 456: pterm.DefaultTable.WithHasHeader().WithLeftAlignment().WithData(tableData).Render() - 457: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/admin.go:171] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 170: adminJoinCmd.MarkFlagRequired("node") - > 171: adminJoinCmd.MarkFlagRequired("host") - 172: - -Autofix: - -[/Users/benduncan/Development/mulga/hive/cmd/hive/cmd/admin.go:170] - G104 (CWE-703): Errors unhandled (Confidence: HIGH, Severity: LOW) - 169: adminJoinCmd.Flags().String("cluster-routes", "", "NATS cluster hosts for routing specify multiple with comma (e.g., 10.11.12.1:4248,10.11.12.2:4248 for multi-node)") - > 170: adminJoinCmd.MarkFlagRequired("node") - 171: adminJoinCmd.MarkFlagRequired("host") - -Autofix: - -Summary: - Gosec : dev - Files : 69 - Lines : 13210 - Nosec : 0 - Issues : 207 - diff --git a/tests/govulncheck-report.txt b/tests/govulncheck-report.txt deleted file mode 100644 index 01756446b..000000000 --- a/tests/govulncheck-report.txt +++ /dev/null @@ -1,9 +0,0 @@ -=== Symbol Results === - -No vulnerabilities found. - -Your code is affected by 0 vulnerabilities. -This scan also found 0 vulnerabilities in packages you import and 5 -vulnerabilities in modules you require, but your code doesn't appear to call -these vulnerabilities. -Use '-show verbose' for more details.