Skip to content

Commit 79a33d1

Browse files
authored
Merge pull request #8 from linuxfoundation/slog
Switch from logrus to log/slog
2 parents 6e9bca9 + b73f5ac commit 79a33d1

File tree

12 files changed

+216
-238
lines changed

12 files changed

+216
-238
lines changed

.cspell.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"jaegertracing",
1616
"pprof",
1717
"zpages",
18-
"fluentbit",
1918
"chainguard",
2019
"hadolint",
2120
"GOARCH",

.github/workflows/image-scan.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
go-version-file: go.mod
2626
- uses: ko-build/[email protected]
2727
with:
28-
version: v0.17.1
28+
version: v0.18.0
2929
- run: |
3030
ko build . --push=false --tarball "${RUNNER_TEMP}/image.tar" \
3131
--bare \
@@ -37,5 +37,7 @@ jobs:
3737
| sh -s -- -b /usr/local/bin
3838
- name: Run trufflehog on image.tar
3939
run: |
40-
trufflehog --fail --no-update --github-actions \
40+
trufflehog --github-actions \
41+
--fail --no-update \
42+
--results=verified,unknown \
4143
filesystem "${RUNNER_TEMP}/image.tar"

.github/workflows/publish.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
go-version-file: go.mod
2727
- uses: ko-build/[email protected]
2828
with:
29-
version: v0.17.1
29+
version: v0.18.0
3030
- run: |
3131
ko build . \
3232
--bare \

0_config.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ package main
77
// spell-checker:disable
88
import (
99
"fmt"
10+
"log/slog"
1011
"os"
1112
"strings"
1213

1314
"github.com/joho/godotenv"
14-
"github.com/sirupsen/logrus"
1515
)
1616

1717
// spell-checker:enable
@@ -38,29 +38,34 @@ func init() {
3838

3939
cfg.Auth0Tenant = os.Getenv("AUTH0_TENANT")
4040
if cfg.Auth0Tenant == "" {
41-
logrus.Fatalln("AUTH0_TENANT not set")
41+
slog.Error("AUTH0_TENANT not set")
42+
os.Exit(1)
4243
}
4344
if strings.ContainsAny(strings.TrimSuffix(cfg.Auth0Tenant, ".us"), "./:") {
4445
// .us is allowed, but otherwise AUTH0_TENANT cannot contain anything
4546
// looking like a domain name or URL.
46-
logrus.Fatalln("invalid AUTH0_TENANT")
47+
slog.Error("invalid AUTH0_TENANT")
48+
os.Exit(1)
4749
}
4850
cfg.Auth0Domain = os.Getenv("AUTH0_DOMAIN")
4951
if cfg.Auth0Domain == "" {
5052
cfg.Auth0Domain = fmt.Sprintf("%s.auth0.com", cfg.Auth0Tenant)
5153
}
5254
cfg.ClientID = os.Getenv("CLIENT_ID")
5355
if cfg.ClientID == "" {
54-
logrus.Fatalln("CLIENT_ID not set")
56+
slog.Error("CLIENT_ID not set")
57+
os.Exit(1)
5558
}
5659
cfg.ClientSecret = os.Getenv("CLIENT_SECRET")
5760
if cfg.ClientSecret == "" {
58-
logrus.Fatalln("CLIENT_SECRET not set")
61+
slog.Error("CLIENT_SECRET not set")
62+
os.Exit(1)
5963
}
6064

6165
cfg.CookieSecret = os.Getenv("COOKIE_SECRET")
6266
if cfg.CookieSecret == "" {
63-
logrus.Fatalln("COOKIE_SECRET not set")
67+
slog.Error("COOKIE_SECRET not set")
68+
os.Exit(1)
6469
}
6570

6671
insecureCookie := os.Getenv("INSECURE_COOKIE")

AGENTS.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# AGENTS.md
2+
3+
## Build/Test Commands
4+
- `make` or `make bin/auth0-cas-server-go` - Build binary
5+
- `make all` - Build binary and Docker container
6+
- `make lint` - Run mega-linter with Go linting rules
7+
- `make docker-build` - Build Docker container
8+
- `go run .` - Run directly with Go
9+
10+
## Code Style Guidelines
11+
- **License Header**: All files must start with Linux Foundation MIT license header
12+
- **Package**: Single `main` package for this service
13+
- **Imports**: Standard library first, then third-party, separated by blank lines
14+
- **Naming**: Use camelCase for private, PascalCase for public; descriptive variable names
15+
- **Error Handling**: Use slog for logging with structured fields; fatal errors use `slog.Error` with `os.Exit(1)`
16+
- **Comments**: Spell-checker disable/enable blocks around imports; function comments for public APIs
17+
- **Global Variables**: Minimal use (cfg for config, store for sessions)
18+
- **Context**: Pass context through request handlers for logging and tracing
19+
- **Types**: Define custom types for constants (e.g., `contextID int`)
20+
- **Environment**: Use godotenv for optional .env file loading in init()
21+
- **Linting**: Uses mega-linter with revive (not golangci-lint), excludes spell/link checkers
22+
23+
## Key Patterns
24+
- Global config in `cfg` variable populated via init()
25+
- Request-scoped logging with context injection
26+
- OpenTelemetry instrumentation throughout
27+
- Gorilla sessions for cookie management

auth0_clients.go

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
"github.com/bmatcuk/doublestar/v4"
2121
"github.com/patrickmn/go-cache"
22-
"github.com/sirupsen/logrus"
2322
"golang.org/x/oauth2/clientcredentials"
2423
)
2524

@@ -111,10 +110,9 @@ func getAuth0Clients(ctx context.Context) ([]auth0ClientStub, error) {
111110
}
112111

113112
if resp.StatusCode != http.StatusOK {
114-
appLogger(ctx).WithFields(logrus.Fields{
115-
"status": resp.StatusCode,
116-
"body": string(bodyBytes),
117-
}).Error("Auth0 get_users error")
113+
appLogger(ctx).Error("Auth0 get_users error",
114+
"status", resp.StatusCode,
115+
"body", string(bodyBytes))
118116
return nil, errors.New("Auth0 get_clients error")
119117
}
120118

@@ -163,18 +161,17 @@ func getAuth0ClientByService(ctx context.Context, serviceURL string) (*auth0Clie
163161
var match bool
164162
match, err = doublestar.Match(glob, serviceURL)
165163
if err != nil {
166-
appLogger(ctx).WithFields(logrus.Fields{
167-
"pattern": glob,
168-
logrus.ErrorKey: err,
169-
}).Warning("unexpected bad cas_service glob in cache")
164+
appLogger(ctx).Warn("unexpected bad cas_service glob in cache",
165+
"pattern", glob,
166+
"error", err)
170167
continue
171168
}
172169
if !match {
173170
continue
174171
}
175172

176173
// There is a match
177-
appLogger(ctx).WithFields(logrus.Fields{"service": serviceURL, "glob": glob, "auth0_client": client.Name}).Debug("matched service in glob cache")
174+
appLogger(ctx).Debug("matched service in glob cache", "service", serviceURL, "glob", glob, "auth0_client", client.Name)
178175
auth0Cache.Set("cas-service-url/"+url.PathEscape(serviceURL), client, cache.NoExpiration)
179176
return &client, nil
180177
}
@@ -198,10 +195,9 @@ func getAuth0ClientByService(ctx context.Context, serviceURL string) (*auth0Clie
198195
}
199196

200197
if client.TokenEndpointAuthMethod != "client_secret_post" && client.TokenEndpointAuthMethod != "client_secret_basic" {
201-
appLogger(ctx).WithFields(logrus.Fields{
202-
"token_endpoint_auth_method": client.TokenEndpointAuthMethod,
203-
"auth0_client": client.Name,
204-
}).Warning("client with cas_service has unsupported token_endpoint_auth_method")
198+
appLogger(ctx).Warn("client with cas_service has unsupported token_endpoint_auth_method",
199+
"token_endpoint_auth_method", client.TokenEndpointAuthMethod,
200+
"auth0_client", client.Name)
205201
continue
206202
}
207203

@@ -212,10 +208,9 @@ func getAuth0ClientByService(ctx context.Context, serviceURL string) (*auth0Clie
212208
for _, glob := range serviceGlobs {
213209
match, err := doublestar.Match(glob, serviceURL)
214210
if err != nil {
215-
appLogger(ctx).WithFields(logrus.Fields{
216-
"pattern": glob,
217-
logrus.ErrorKey: err,
218-
}).Warning("ignoring bad cas_service glob")
211+
appLogger(ctx).Warn("ignoring bad cas_service glob",
212+
"pattern", glob,
213+
"error", err)
219214
continue
220215
}
221216
// Store the glob-to-client lookup (for cache).
@@ -225,7 +220,7 @@ func getAuth0ClientByService(ctx context.Context, serviceURL string) (*auth0Clie
225220
continue
226221
}
227222

228-
appLogger(ctx).WithFields(logrus.Fields{"service": serviceURL, "glob": glob, "auth0_client": client.Name}).Debug("matched service")
223+
appLogger(ctx).Debug("matched service", "service", serviceURL, "glob", glob, "auth0_client", client.Name)
229224
// If the glob matches, save the match, but keep processing remaining
230225
// comma-delimited globs AND clients to complete the glob-to-client cache
231226
// update.

0 commit comments

Comments
 (0)