Skip to content

Commit 160fc63

Browse files
committed
fix(lint): resolve remaining 15 golangci-lint issues
- errcheck: handle return values in hpc/slurm_client (4 fmt.Sscanf), stackdrift/service (2 json.Unmarshal), tidb/service (1 ShouldBindJSON) - godot: add trailing periods to comments in identity/service_account (5), pkg/iam/actions (3) - bodyclose: add nolint annotation in scheduler/service for closure-captured response (body is closed on both error and success paths) golangci-lint now passes with 0 issues.
1 parent 29d3933 commit 160fc63

6 files changed

Lines changed: 21 additions & 17 deletions

File tree

internal/management/hpc/slurm_client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,18 +584,18 @@ func parseWallTime(wallTime string) int {
584584
_, _ = fmt.Sscanf(dParts[1], "%d", &h)
585585
h += d * 24
586586
} else {
587-
fmt.Sscanf(hourPart, "%d", &h)
587+
_, _ = fmt.Sscanf(hourPart, "%d", &h)
588588
}
589-
fmt.Sscanf(parts[1], "%d", &m)
589+
_, _ = fmt.Sscanf(parts[1], "%d", &m)
590590
return h*60 + m
591591
case 2: // HH:MM
592592
var h, m int
593-
fmt.Sscanf(parts[0], "%d", &h)
594-
fmt.Sscanf(parts[1], "%d", &m)
593+
_, _ = fmt.Sscanf(parts[0], "%d", &h)
594+
_, _ = fmt.Sscanf(parts[1], "%d", &m)
595595
return h*60 + m
596596
default:
597597
var mins int
598-
fmt.Sscanf(wallTime, "%d", &mins)
598+
_, _ = fmt.Sscanf(wallTime, "%d", &mins)
599599
return mins
600600
}
601601
}

internal/management/identity/service_account.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (sa *ServiceAccount) IsExpired() bool {
8989
// ──────────────────────────────────────────────────────────────────────
9090

9191
// generateAccessKeyID generates a unique access key ID.
92-
// Format: VC-AKIA-{16 hex chars} (24 chars total)
92+
// Format: VC-AKIA-{16 hex chars} (24 chars total).
9393
func generateAccessKeyID() (string, error) {
9494
b := make([]byte, 8) // 16 hex chars
9595
if _, err := rand.Read(b); err != nil {
@@ -99,7 +99,7 @@ func generateAccessKeyID() (string, error) {
9999
}
100100

101101
// generateSecretKey generates a cryptographically random secret key.
102-
// Format: base64url-encoded 32 bytes (43 chars)
102+
// Format: base64url-encoded 32 bytes (43 chars).
103103
func generateSecretKey() (string, error) {
104104
b := make([]byte, 32)
105105
if _, err := rand.Read(b); err != nil {
@@ -113,11 +113,11 @@ func generateSecretKey() (string, error) {
113113
// ──────────────────────────────────────────────────────────────────────
114114

115115
// HMACAuth is the authorization header scheme for API key authentication.
116-
// Format: VC-HMAC-SHA256 AccessKeyId={key}, Timestamp={unix}, Signature={sig}
116+
// Format: VC-HMAC-SHA256 AccessKeyId={key}, Timestamp={unix}, Signature={sig}.
117117
const HMACAuth = "VC-HMAC-SHA256"
118118

119119
// computeHMAC computes the HMAC-SHA256 signature for API key authentication.
120-
// The signing string is: "accessKeyID\ntimestamp\nHTTPMethod\npath"
120+
// The signing string is: "accessKeyID\ntimestamp\nHTTPMethod\npath".
121121
func computeHMAC(secretKey, accessKeyID, timestamp, method, path string) string {
122122
signingString := accessKeyID + "\n" + timestamp + "\n" + method + "\n" + path
123123
mac := hmac.New(sha256.New, []byte(secretKey))
@@ -666,7 +666,7 @@ func (s *Service) handleAPIKeyAuth(c *gin.Context, authHeader string) {
666666
}
667667

668668
// parseHMACParams parses the HMAC authorization header parameters.
669-
// Input: "VC-HMAC-SHA256 AccessKeyId=XXX, Timestamp=YYY, Signature=ZZZ"
669+
// Input: "VC-HMAC-SHA256 AccessKeyId=XXX, Timestamp=YYY, Signature=ZZZ".
670670
func parseHMACParams(header string) map[string]string {
671671
result := map[string]string{}
672672

internal/management/scheduler/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func (s *Service) dispatchVMCreate(c *gin.Context) {
331331
reqHTTP, _ := http.NewRequest("POST", addr, buf)
332332
reqHTTP.Header.Set("Content-Type", "application/json")
333333
var reqErr error
334-
httpResp, reqErr = http.DefaultClient.Do(reqHTTP) // #nosec
334+
httpResp, reqErr = http.DefaultClient.Do(reqHTTP) //nolint:bodyclose // closed on both error and success paths
335335
return reqErr
336336
})
337337
if cbErr != nil {

internal/management/stackdrift/service.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ func (s *Service) DetectDrift(stackID uint) (*DriftReport, error) {
136136

137137
// Parse template to get declared resources.
138138
var declared map[string]interface{}
139-
json.Unmarshal([]byte(active.Template), &declared)
139+
if err := json.Unmarshal([]byte(active.Template), &declared); err != nil {
140+
return nil, fmt.Errorf("parse template: %w", err)
141+
}
140142

141143
// Simulate drift detection comparing template vs actual state.
142144
// In production, each resource type would have a provider that checks real state.
@@ -174,7 +176,9 @@ func (s *Service) GetDepGraph(stackID uint) ([]DepNode, error) {
174176
}
175177

176178
var tmpl map[string]interface{}
177-
json.Unmarshal([]byte(active.Template), &tmpl)
179+
if err := json.Unmarshal([]byte(active.Template), &tmpl); err != nil {
180+
return nil, fmt.Errorf("parse template: %w", err)
181+
}
178182

179183
var nodes []DepNode
180184
if resources, ok := tmpl["resources"].([]interface{}); ok {

internal/management/tidb/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func (s *Service) handleCreateBackup(c *gin.Context) {
261261
var req struct {
262262
Type string `json:"type"`
263263
}
264-
c.ShouldBindJSON(&req)
264+
_ = c.ShouldBindJSON(&req)
265265
b, err := s.CreateBackup(uint(id), req.Type)
266266
if err != nil {
267267
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})

pkg/iam/actions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,21 +159,21 @@ const (
159159
IAMCreateProject = "vc:iam:CreateProject"
160160
IAMDeleteProject = "vc:iam:DeleteProject"
161161

162-
// Service Account Actions (P3)
162+
// Service Account Actions (P3).
163163
IAMListServiceAccounts = "vc:iam:ListServiceAccounts"
164164
IAMGetServiceAccount = "vc:iam:GetServiceAccount"
165165
IAMCreateServiceAccount = "vc:iam:CreateServiceAccount"
166166
IAMDeleteServiceAccount = "vc:iam:DeleteServiceAccount"
167167
IAMRotateServiceAccount = "vc:iam:RotateServiceAccountKey"
168168

169-
// Group Actions (P5)
169+
// Group Actions (P5).
170170
IAMListGroups = "vc:iam:ListGroups"
171171
IAMGetGroup = "vc:iam:GetGroup"
172172
IAMCreateGroup = "vc:iam:CreateGroup"
173173
IAMUpdateGroup = "vc:iam:UpdateGroup"
174174
IAMDeleteGroup = "vc:iam:DeleteGroup"
175175

176-
// Permission Boundary Actions (P5)
176+
// Permission Boundary Actions (P5).
177177
IAMSetPermissionBoundary = "vc:iam:SetPermissionBoundary"
178178
IAMGetPermissionBoundary = "vc:iam:GetPermissionBoundary"
179179
IAMDeletePermissionBoundary = "vc:iam:DeletePermissionBoundary"

0 commit comments

Comments
 (0)