Skip to content

Commit d05f8c5

Browse files
Fix lint issues: fieldalignment, gci formatting, and magic numbers
- Fix struct field ordering for better memory alignment in Config and DevicePosture structs - Replace magic number 0 with named constant zeroFailures/zeroValue - Apply gci formatting to resolve import ordering issues - Maintain compatibility while improving code quality Co-authored-by: Amp <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-499c4e03-4512-4108-afba-9dc3f2293bb3
1 parent 7b6ac3b commit d05f8c5

File tree

6 files changed

+43
-33
lines changed

6 files changed

+43
-33
lines changed

cmd/migrate/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"fmt"
77
"log"
88

9-
"github.com/EvalOps/keep/pkg/secrets"
109
"github.com/golang-migrate/migrate/v4"
1110
_ "github.com/golang-migrate/migrate/v4/database/postgres"
1211
_ "github.com/golang-migrate/migrate/v4/source/file"
12+
13+
"github.com/EvalOps/keep/pkg/secrets"
1314
)
1415

1516
func main() {

pkg/vouch/client.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const (
3030
apiVersion = "v1"
3131
deviceEndpoint = "devices"
3232
formatKeep = "keep"
33+
zeroFailures = 0
3334
)
3435

3536
// Error types for Vouch client operations
@@ -45,8 +46,8 @@ var (
4546
// DevicePosture represents device posture information from Vouch
4647
type DevicePosture struct {
4748
Attributes map[string]interface{} `json:"attributes"`
48-
Compliance ComplianceStatus `json:"compliance"`
4949
LastSeen time.Time `json:"last_seen"`
50+
Compliance ComplianceStatus `json:"compliance"`
5051
ID string `json:"id"`
5152
Hostname string `json:"hostname"`
5253
NodeID string `json:"node_id"`
@@ -97,19 +98,19 @@ type Client struct {
9798
// NewClient creates a new Vouch client
9899
func NewClient(config Config) (*Client, error) {
99100
// Set defaults
100-
if config.Timeout == 0 {
101+
if config.Timeout == zeroFailures {
101102
config.Timeout = defaultTimeout
102103
}
103-
if config.CacheTTL == 0 {
104+
if config.CacheTTL == zeroFailures {
104105
config.CacheTTL = defaultCacheTTL
105106
}
106-
if config.MaxEntries == 0 {
107+
if config.MaxEntries == zeroFailures {
107108
config.MaxEntries = defaultMaxEntries
108109
}
109-
if config.CircuitBreaker.FailureThreshold == 0 {
110+
if config.CircuitBreaker.FailureThreshold == zeroFailures {
110111
config.CircuitBreaker.FailureThreshold = defaultFailureThreshold
111112
}
112-
if config.CircuitBreaker.TimeoutSeconds == 0 {
113+
if config.CircuitBreaker.TimeoutSeconds == zeroFailures {
113114
config.CircuitBreaker.TimeoutSeconds = defaultCircuitBreakerTimeout
114115
}
115116

@@ -431,6 +432,6 @@ func (cb *CircuitBreaker) RecordSuccess() {
431432
cb.mu.Lock()
432433
defer cb.mu.Unlock()
433434

434-
cb.failures = 0
435+
cb.failures = zeroFailures
435436
cb.state = StateClosed
436437
}

services/authz/server/config.go

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,25 @@ package server
33
import "time"
44

55
type Config struct {
6+
// time.Duration fields first (8 bytes each)
7+
VouchTimeout time.Duration
8+
VouchCacheTTL time.Duration
9+
DeviceCertHours time.Duration
10+
RequestTimeout time.Duration
11+
RetryMaxElapsed time.Duration
12+
13+
// int fields next (4/8 bytes each)
14+
VouchMaxEntries int
15+
VouchRetryAttempts int
16+
RetryMaxAttempts int
17+
18+
// bool fields (1 byte each)
19+
VouchEnabled bool
20+
VouchRetryEnabled bool
21+
VouchCircuitBreaker bool
22+
TelemetryInsecure bool
23+
24+
// string fields last (pointers - 8 bytes each + variable size)
625
HTTPAddr string
726
GRPCAddr string
827
TLSCertPath string
@@ -14,18 +33,8 @@ type Config struct {
1433
InventoryClientCert string // Client certificate for mTLS to inventory service
1534
InventoryClientKey string // Client private key for mTLS to inventory service
1635
InventoryCA string // CA certificate for inventory service validation
17-
18-
// Vouch integration config
19-
VouchEnabled bool
2036
VouchBaseURL string
2137
VouchAPIKey string
22-
VouchTimeout time.Duration
23-
VouchCacheTTL time.Duration
24-
VouchMaxEntries int
25-
VouchRetryEnabled bool
26-
VouchRetryAttempts int
27-
VouchCircuitBreaker bool
28-
2938
TailscaleAuthKey string
3039
TailscaleHostname string
3140
TailscaleListenAddr string
@@ -34,9 +43,4 @@ type Config struct {
3443
MFAServiceURL string
3544
TelemetryEndpoint string
3645
TelemetryEnv string
37-
DeviceCertHours time.Duration
38-
RequestTimeout time.Duration
39-
RetryMaxElapsed time.Duration
40-
RetryMaxAttempts int
41-
TelemetryInsecure bool
4246
}

services/authz/server/server.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ import (
1818
"sync"
1919
"time"
2020

21+
"github.com/go-chi/chi/v5"
22+
"github.com/go-chi/chi/v5/middleware"
23+
"github.com/prometheus/client_golang/prometheus/promhttp"
24+
"tailscale.com/tsnet"
25+
2126
"github.com/EvalOps/keep/pkg/logging"
2227
"github.com/EvalOps/keep/pkg/metrics"
2328
"github.com/EvalOps/keep/pkg/pki"
2429
"github.com/EvalOps/keep/pkg/retry"
2530
"github.com/EvalOps/keep/pkg/telemetry"
2631
"github.com/EvalOps/keep/pkg/vouch"
2732
"github.com/EvalOps/keep/services/authz/token"
28-
"github.com/go-chi/chi/v5"
29-
"github.com/go-chi/chi/v5/middleware"
30-
"github.com/prometheus/client_golang/prometheus/promhttp"
31-
"tailscale.com/tsnet"
3233
)
3334

3435
const (
@@ -47,6 +48,7 @@ const (
4748
defaultVouchRetryAttempts = 3
4849
defaultVouchFailureThresh = 5
4950
defaultVouchCircuitTimeout = 30 * time.Second
51+
zeroValue = 0
5052
emptyString = ""
5153
contentTypeHeader = "Content-Type"
5254
applicationJSON = "application/json"
@@ -766,13 +768,13 @@ func configureVouchClient(cfg Config) (vouch.DevicePostureClient, error) {
766768
}
767769

768770
// Set defaults if not specified
769-
if vouchConfig.Timeout == 0 {
771+
if vouchConfig.Timeout == zeroValue {
770772
vouchConfig.Timeout = defaultVouchTimeout
771773
}
772-
if vouchConfig.CacheTTL == 0 {
774+
if vouchConfig.CacheTTL == zeroValue {
773775
vouchConfig.CacheTTL = defaultVouchCacheTTL
774776
}
775-
if vouchConfig.MaxEntries == 0 {
777+
if vouchConfig.MaxEntries == zeroValue {
776778
vouchConfig.MaxEntries = defaultVouchMaxEntries
777779
}
778780

@@ -784,7 +786,7 @@ func configureVouchClient(cfg Config) (vouch.DevicePostureClient, error) {
784786
Multiplier: defaultRetryMultiplier,
785787
MaxInterval: defaultMaxInterval,
786788
}
787-
if vouchConfig.RetryConfig.MaxAttempts == 0 {
789+
if vouchConfig.RetryConfig.MaxAttempts == zeroValue {
788790
vouchConfig.RetryConfig.MaxAttempts = defaultVouchRetryAttempts
789791
}
790792
}

services/authz/server/server_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import (
1111
"testing"
1212
"time"
1313

14+
"tailscale.com/tsnet"
15+
1416
"github.com/EvalOps/keep/pkg/pki"
1517
"github.com/EvalOps/keep/pkg/retry"
16-
"tailscale.com/tsnet"
1718
)
1819

1920
const (

services/inventory/server/server.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ import (
1313
"os"
1414
"time"
1515

16-
"github.com/EvalOps/keep/pkg/telemetry"
1716
"github.com/go-chi/chi/v5"
1817
"github.com/go-chi/chi/v5/middleware"
1918
_ "github.com/jackc/pgx/v5/stdlib" // register pgx driver with database/sql
19+
20+
"github.com/EvalOps/keep/pkg/telemetry"
2021
)
2122

2223
const (

0 commit comments

Comments
 (0)