Skip to content

Commit dd4689b

Browse files
committed
make lint
1 parent 213e524 commit dd4689b

9 files changed

Lines changed: 54 additions & 54 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
go-version: '1.24'
3535

3636
- name: Install system dependencies
37-
run: sudo apt-get update && sudo apt-get install -y xz-utils unzip
37+
run: sudo apt-get update && sudo apt-get install -y xz-utils unzip shellcheck
3838

3939
- name: Install bingo
4040
run: go install github.com/bwplotka/bingo@latest

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ Usage of ./observatorium-api:
123123
The endpoint against which to send read requests for metrics.
124124
-metrics.rules.endpoint string
125125
The endpoint against which to make get requests for listing recording/alerting rules and put requests for creating/updating recording/alerting rules.
126+
-metrics.status.endpoint string
127+
The endpoint against which to make requests for status information about metrics (e.g. '/api/v1/status/tsdb').
126128
-metrics.tenant-header string
127129
The name of the HTTP header containing the tenant ID to forward to the metrics upstreams. (default "THANOS-TENANT")
128130
-metrics.tenant-label string

authentication/authentication_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,46 +120,46 @@ func TestTokenExpiredErrorHandling(t *testing.T) {
120120
expiredErr := &oidc.TokenExpiredError{
121121
Expiry: time.Now().Add(-time.Hour), // Expired an hour ago
122122
}
123-
123+
124124
// Test direct error
125125
var tokenExpiredErr *oidc.TokenExpiredError
126126
if !errors.As(expiredErr, &tokenExpiredErr) {
127127
t.Error("errors.As should identify TokenExpiredError")
128128
}
129-
129+
130130
// Test wrapped error
131131
wrappedErr := &wrappedError{
132132
msg: "verification failed",
133133
err: expiredErr,
134134
}
135-
135+
136136
if !errors.As(wrappedErr, &tokenExpiredErr) {
137137
t.Error("errors.As should identify wrapped TokenExpiredError")
138138
}
139139
})
140-
140+
141141
t.Run("Other errors are not identified as TokenExpiredError", func(t *testing.T) {
142142
// Test with a generic error
143143
genericErr := errors.New("generic verification error")
144-
144+
145145
var tokenExpiredErr *oidc.TokenExpiredError
146146
if errors.As(genericErr, &tokenExpiredErr) {
147147
t.Error("errors.As should not identify generic error as TokenExpiredError")
148148
}
149-
149+
150150
// Test with wrapped generic error
151151
wrappedGenericErr := &wrappedError{
152152
msg: "verification failed",
153153
err: genericErr,
154154
}
155-
155+
156156
if errors.As(wrappedGenericErr, &tokenExpiredErr) {
157157
t.Error("errors.As should not identify wrapped generic error as TokenExpiredError")
158158
}
159159
})
160160
}
161161

162-
// Helper type to wrap errors for testing
162+
// Helper type to wrap errors for testing.
163163
type wrappedError struct {
164164
msg string
165165
err error

authentication/mtls.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,3 @@ func (a MTLSAuthenticator) GRPCMiddleware() grpc.StreamServerInterceptor {
192192
func (a MTLSAuthenticator) Handler() (string, http.Handler) {
193193
return "", nil
194194
}
195-

authentication/mtls_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010
"testing"
1111

1212
"github.com/go-kit/log"
13+
1314
"github.com/observatorium/api/test/testtls"
1415
)
1516

16-
// Helper function to generate test certificates using the existing testtls package
17+
// Helper function to generate test certificates using the existing testtls package.
1718
func setupTestCertificatesWithFile(t testing.TB) (clientCert tls.Certificate, caPath string, cleanup func()) {
1819
t.Helper()
1920

@@ -26,10 +27,10 @@ func setupTestCertificatesWithFile(t testing.TB) (clientCert tls.Certificate, ca
2627
// Generate certificates using the testtls package
2728
err = testtls.GenerateCerts(
2829
tmpDir,
29-
"test-api", // API common name
30+
"test-api", // API common name
3031
[]string{"localhost", "127.0.0.1"}, // API SANs
31-
"test-dex", // Dex common name
32-
[]string{"localhost"}, // Dex SANs
32+
"test-dex", // Dex common name
33+
[]string{"localhost"}, // Dex SANs
3334
)
3435
if err != nil {
3536
os.RemoveAll(tmpDir)
@@ -70,12 +71,12 @@ func TestMTLSAuthenticator_PathBasedAuthentication(t *testing.T) {
7071
defer cleanup()
7172

7273
tests := []struct {
73-
name string
74-
pathPatterns []string
75-
requestPath string
76-
expectMTLS bool
77-
expectError bool
78-
description string
74+
name string
75+
pathPatterns []string
76+
requestPath string
77+
expectMTLS bool
78+
expectError bool
79+
description string
7980
}{
8081
{
8182
name: "no_patterns_enforces_all_paths",
@@ -139,7 +140,7 @@ func TestMTLSAuthenticator_PathBasedAuthentication(t *testing.T) {
139140
t.Run(tt.name, func(t *testing.T) {
140141
// Create mTLS config with path patterns using file-based CA
141142
config := map[string]interface{}{
142-
"caPath": caPath, // Use file-based CA as original code expects
143+
"caPath": caPath, // Use file-based CA as original code expects
143144
"pathPatterns": tt.pathPatterns,
144145
}
145146

@@ -319,7 +320,7 @@ func TestMTLSAuthenticator_InvalidPathPattern(t *testing.T) {
319320
}
320321
}
321322

322-
// Test path matching logic without requiring certificate validation
323+
// Test path matching logic without requiring certificate validation.
323324
func TestMTLSAuthenticator_PathMatchingLogic(t *testing.T) {
324325
tests := []struct {
325326
name string
@@ -338,7 +339,7 @@ func TestMTLSAuthenticator_PathMatchingLogic(t *testing.T) {
338339
{
339340
name: "pattern_matches_requires_mtls",
340341
pathPatterns: []string{"/api/.*/receive"},
341-
requestPath: "/api/metrics/v1/receive",
342+
requestPath: "/api/metrics/v1/receive",
342343
expectSkip: false,
343344
description: "Matching pattern requires mTLS",
344345
},
@@ -379,7 +380,7 @@ func TestMTLSAuthenticator_PathMatchingLogic(t *testing.T) {
379380
}
380381

381382
middleware := authenticator.Middleware()
382-
383+
383384
handlerCalled := false
384385
testHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
385386
handlerCalled = true
@@ -413,7 +414,7 @@ func TestMTLSAuthenticator_PathMatchingLogic(t *testing.T) {
413414
}
414415
}
415416

416-
// Test both CA configuration methods work correctly
417+
// Test both CA configuration methods work correctly.
417418
func TestMTLSAuthenticator_CAConfiguration(t *testing.T) {
418419
// Test file-based CA configuration
419420
t.Run("file_based_ca", func(t *testing.T) {
@@ -449,7 +450,7 @@ func TestMTLSAuthenticator_CAConfiguration(t *testing.T) {
449450
}
450451

451452
config := map[string]interface{}{
452-
"ca": caPEM, // Direct CA data
453+
"ca": caPEM, // Direct CA data
453454
}
454455

455456
logger := log.NewNopLogger()
@@ -465,4 +466,3 @@ func TestMTLSAuthenticator_CAConfiguration(t *testing.T) {
465466
}
466467
})
467468
}
468-

authentication/oidc.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ func init() {
4242

4343
// oidcConfig represents the oidc authenticator config.
4444
type oidcConfig struct {
45-
ClientID string `json:"clientID"`
46-
ClientSecret string `json:"clientSecret"`
47-
GroupClaim string `json:"groupClaim"`
48-
IssuerRawCA []byte `json:"issuerCA"`
49-
IssuerCAPath string `json:"issuerCAPath"`
45+
ClientID string `json:"clientID"`
46+
ClientSecret string `json:"clientSecret"`
47+
GroupClaim string `json:"groupClaim"`
48+
IssuerRawCA []byte `json:"issuerCA"`
49+
IssuerCAPath string `json:"issuerCAPath"`
5050
issuerCA *x509.Certificate
5151
IssuerURL string `json:"issuerURL"`
5252
RedirectURL string `json:"redirectURL"`
@@ -299,7 +299,7 @@ func (a oidcAuthenticator) Middleware() Middleware {
299299
break
300300
}
301301
}
302-
302+
303303
// If path doesn't match, skip OIDC enforcement
304304
if !pathMatches {
305305
next.ServeHTTP(w, r)

authentication/oidc_test.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func TestOIDCPathMatching(t *testing.T) {
8888
}
8989

9090
if shouldSkip != tt.expectSkip {
91-
t.Errorf("Expected skip=%v, got skip=%v for path %q with patterns %v",
91+
t.Errorf("Expected skip=%v, got skip=%v for path %q with patterns %v",
9292
tt.expectSkip, shouldSkip, tt.requestPath, tt.pathPatterns)
9393
}
9494
})
@@ -98,11 +98,11 @@ func TestOIDCPathMatching(t *testing.T) {
9898
func TestOIDCConfigPathPatternsIntegration(t *testing.T) {
9999
// Test that path patterns are correctly passed to the OIDC authenticator config
100100
tests := []struct {
101-
name string
102-
configData map[string]interface{}
103-
expectError bool
104-
expectPaths []string
105-
description string
101+
name string
102+
configData map[string]interface{}
103+
expectError bool
104+
expectPaths []string
105+
description string
106106
}{
107107
{
108108
name: "valid_path_patterns",
@@ -116,7 +116,7 @@ func TestOIDCConfigPathPatternsIntegration(t *testing.T) {
116116
description: "Valid path patterns should be accepted",
117117
},
118118
{
119-
name: "empty_path_patterns",
119+
name: "empty_path_patterns",
120120
configData: map[string]interface{}{
121121
"pathPatterns": []string{},
122122
"clientID": "test-client",
@@ -184,6 +184,9 @@ func TestOIDCConfigPathPatternsIntegration(t *testing.T) {
184184
if len(config.PathPatterns) != len(tt.expectPaths) {
185185
t.Errorf("Expected %d path patterns, got %d", len(tt.expectPaths), len(config.PathPatterns))
186186
}
187+
if len(pathMatchers) != len(tt.expectPaths) {
188+
t.Errorf("Expected %d compiled matchers, got %d", len(tt.expectPaths), len(pathMatchers))
189+
}
187190

188191
for i, expected := range tt.expectPaths {
189192
if i >= len(config.PathPatterns) {
@@ -214,7 +217,7 @@ func TestOIDCMiddlewareActual(t *testing.T) {
214217
expectSkipped: true,
215218
},
216219
{
217-
name: "matching_path_not_skipped",
220+
name: "matching_path_not_skipped",
218221
pathPatterns: []string{"/api/.*/query"},
219222
requestPath: "/api/metrics/v1/query",
220223
expectSkipped: false,
@@ -266,4 +269,3 @@ func TestOIDCMiddlewareActual(t *testing.T) {
266269
})
267270
}
268271
}
269-

main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,6 @@ func tenantAuthenticatorConfig(t *tenant) (map[string]interface{}, string, error
16051605
}
16061606
}
16071607

1608-
16091608
type otelErrorHandler struct {
16101609
logger log.Logger
16111610
}

main_test.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ tenants:
195195

196196
func TestPathMatchingBehavior(t *testing.T) {
197197
tests := []struct {
198-
name string
199-
oidcPaths []string
200-
mtlsPaths []string
201-
testPath string
202-
expectOIDC bool
203-
expectMTLS bool
204-
description string
198+
name string
199+
oidcPaths []string
200+
mtlsPaths []string
201+
testPath string
202+
expectOIDC bool
203+
expectMTLS bool
204+
description string
205205
}{
206206
{
207207
name: "read_path_oidc_only",
@@ -250,9 +250,9 @@ func TestPathMatchingBehavior(t *testing.T) {
250250
},
251251
{
252252
name: "case_sensitive_matching",
253-
oidcPaths: []string{"/api/.*/Query"}, // uppercase Q
253+
oidcPaths: []string{"/api/.*/Query"}, // uppercase Q
254254
mtlsPaths: []string{"/api/.*/receive"},
255-
testPath: "/api/metrics/v1/query", // lowercase q
255+
testPath: "/api/metrics/v1/query", // lowercase q
256256
expectOIDC: false,
257257
expectMTLS: false,
258258
description: "Pattern matching should be case sensitive",
@@ -310,5 +310,3 @@ func TestPathMatchingBehavior(t *testing.T) {
310310
})
311311
}
312312
}
313-
314-

0 commit comments

Comments
 (0)