Skip to content

Commit f27870a

Browse files
committed
Address PR Comments
1 parent 50c96e7 commit f27870a

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

internal/config/config.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,8 @@ func GetEnvOrDefault(key, defaultValue string) string {
178178

179179
// mergeUniqueStrings merges two string slices and removes duplicates
180180
func mergeUniqueStrings(a, b []string) []string {
181-
if len(a) == 0 {
182-
return append([]string(nil), b...)
183-
}
184-
seen := make(map[string]struct{})
185-
var result []string
181+
seen := make(map[string]struct{}, len(a)+len(b))
182+
result := make([]string, 0, len(a)+len(b))
186183

187184
for _, s := range a {
188185
if _, ok := seen[s]; !ok {

pkg/audit/interface.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ import (
55
"crypto"
66
)
77

8-
// Auditor is the primary interface for audit logging operations
8+
// Auditor is the primary interface for audit logging operations.
9+
// This interface provides a clean abstraction for audit capabilities,
10+
// making it easy to swap implementations and integrate audit logging into any service.
11+
//
12+
// Implementations should handle:
13+
// - Asynchronous logging (fire-and-forget)
14+
// - Graceful degradation when the audit service is unavailable
15+
// - Thread-safe operations
916
type Auditor interface {
1017
// LogEvent logs a standard audit event asynchronously
1118
LogEvent(ctx context.Context, event *AuditLogRequest)
@@ -23,6 +30,6 @@ type Auditor interface {
2330
IsEnabled() bool
2431
}
2532

26-
// AuditClient is an alias for Auditor to maintain backward compatibility
33+
// AuditClient is an alias for Auditor to maintain backward compatibility.
2734
// Deprecated: Use Auditor instead. This will be removed in a future version.
2835
type AuditClient = Auditor

pkg/audit/security_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,21 @@ func TestSignAndVerify_Ed25519(t *testing.T) {
9393
}
9494

9595
func TestVerifyPayload_Mismatch(t *testing.T) {
96-
privateKey, _ := rsa.GenerateKey(rand.Reader, 2048)
96+
privateKey, err := rsa.GenerateKey(rand.Reader, 2048)
97+
if err != nil {
98+
t.Fatalf("failed to generate RSA key: %v", err)
99+
}
97100
payload := []byte(`{"event":"test"}`)
98-
sigBase64, alg, _ := SignPayload(payload, privateKey)
101+
sigBase64, alg, err := SignPayload(payload, privateKey)
102+
if err != nil {
103+
t.Fatalf("signing failed: %v", err)
104+
}
99105

100-
privateKey2, _ := rsa.GenerateKey(rand.Reader, 2048)
101-
err := VerifyPayload(payload, sigBase64, alg, &privateKey2.PublicKey)
106+
privateKey2, err := rsa.GenerateKey(rand.Reader, 2048)
107+
if err != nil {
108+
t.Fatalf("failed to generate second RSA key: %v", err)
109+
}
110+
err = VerifyPayload(payload, sigBase64, alg, &privateKey2.PublicKey)
102111
if err == nil {
103112
t.Errorf("expected verification to fail with wrong key")
104113
}

0 commit comments

Comments
 (0)