Skip to content

Commit 3926f63

Browse files
acoshiftclaude
andauthored
update go and dependencies (#6)
## Summary - Go `1.24.5` → `1.26.3` (go.mod + .tool-versions) - `github.com/acoshift/pgsql` `v0.15.3` → `v0.16.0` - `github.com/lib/pq` `v1.10.9` → `v1.12.3` Also adds `CLAUDE.md` with codebase guidance for Claude Code. ## Test plan - [ ] `go build ./...` passes (verified locally) Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c941ece commit 3926f63

4 files changed

Lines changed: 66 additions & 8 deletions

File tree

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
golang 1.24.5
1+
golang 1.26.3

CLAUDE.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Build & Run
6+
7+
```bash
8+
go build -o auth ./cmd/auth # build binary
9+
go vet ./... # lint
10+
```
11+
12+
No test files exist in this codebase.
13+
14+
### Required environment variables
15+
16+
| Variable | Description |
17+
|---|---|
18+
| `SQL_URL` | PostgreSQL connection string |
19+
| `OAUTH2_CLIENT_ID` | Google OAuth app client ID |
20+
| `OAUTH2_CLIENT_SECRET` | Google OAuth app client secret |
21+
| `PORT` | Listen port (default: `8080`) |
22+
23+
## Architecture
24+
25+
This is a minimal OAuth2 authentication service for Deploys.app. It acts as an OAuth2 authorization server backed by Google as the identity provider.
26+
27+
### Entry point
28+
29+
`cmd/auth/main.go` reads env vars, opens a PostgreSQL connection, registers handlers on a `http.ServeMux`, wraps it with `pgctx.Middleware` (binds the DB to each request context), and calls `http.ListenAndServe`.
30+
31+
### HTTP endpoints
32+
33+
| Method | Path | Handler | Purpose |
34+
|---|---|---|---|
35+
| `GET` | `/` | `RedirectHandler` | Validates the OAuth2 client and redirects the user to Google |
36+
| `GET` | `/callback` | `CallbackHandler` | Receives Google's code, exchanges it for an ID token, issues an internal auth code |
37+
| `POST` | `/token` | `TokenHandler` | Exchanges client credentials + internal code for a long-lived user token |
38+
| `POST` | `/revoke` | `RevokePostHandler` | Deletes a user token by its hash |
39+
40+
### Database access pattern
41+
42+
`github.com/acoshift/pgsql` / `pgctx` is the only DB layer. Calling `pgctx.Middleware(db)` stores the `*sql.DB` in the request context; handlers then call `pgctx.Exec(ctx, ...)` or `pgctx.QueryRow(ctx, ...)` directly — there is no ORM or repository struct.
43+
44+
All DB logic lives in `oauth2.go` (session/code helpers) and `token.go` (token hashing and persistence).
45+
46+
### Session & token lifecycle
47+
48+
- **OAuth2 sessions** (`oauth2_sessions`) — created by `RedirectHandler`, deleted on first read by `CallbackHandler`. 1-hour TTL enforced in the WHERE clause.
49+
- **OAuth2 codes** (`oauth2_codes`) — created by `CallbackHandler`, consumed atomically (DELETE … RETURNING) by `TokenHandler`. 1-hour TTL.
50+
- **User tokens** (`user_tokens`) — 7-day TTL, stored as SHA-256 hashes. Revoked by `RevokePostHandler`.
51+
52+
### Key decisions
53+
54+
- No framework — plain `net/http` + `http.ServeMux`.
55+
- No test files; no graceful shutdown / signal handling.
56+
- Google is the only upstream identity provider (hardcoded endpoints in `handler.go`).
57+
- Docker image uses `gcr.io/distroless/static` for a minimal runtime.
58+
- CI builds and pushes to `registry.moonrhythm.io/deploys-app/auth:<git-sha>`.

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/deploys-app/auth
22

3-
go 1.24.5
3+
go 1.26.3
44

55
require (
6-
github.com/acoshift/pgsql v0.15.3
7-
github.com/lib/pq v1.10.9
6+
github.com/acoshift/pgsql v0.16.0
7+
github.com/lib/pq v1.12.3
88
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
22
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
3-
github.com/acoshift/pgsql v0.15.3 h1:iQjsvb4RXFWeinATQBjjGRZomkMD7B0fHxyq4bnkh0A=
4-
github.com/acoshift/pgsql v0.15.3/go.mod h1:HtdMa77CYeRb9pD6+cT/ZPjpudiUVQ2OIKv6QXjgEZw=
3+
github.com/acoshift/pgsql v0.16.0 h1:ak+fwy8Xnx0uZBhSmvFhGGk3a7EQNu8IiRLpnP99IT4=
4+
github.com/acoshift/pgsql v0.16.0/go.mod h1:HtdMa77CYeRb9pD6+cT/ZPjpudiUVQ2OIKv6QXjgEZw=
55
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
66
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
7-
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
8-
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
7+
github.com/lib/pq v1.12.3 h1:tTWxr2YLKwIvK90ZXEw8GP7UFHtcbTtty8zsI+YjrfQ=
8+
github.com/lib/pq v1.12.3/go.mod h1:/p+8NSbOcwzAEI7wiMXFlgydTwcgTr3OSKMsD2BitpA=
99
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1010
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1111
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=

0 commit comments

Comments
 (0)