feat(jwtinfo): allow reading JWT token from file#24
Conversation
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 2 minutes and 41 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📝 WalkthroughWalkthroughAdds a Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI
participant FS as FileSystem
participant HTTP as TokenEndpoint
participant JWT as JWT Parser
participant JWKS as JWKS (optional)
CLI->>CLI: parse flags (--token-file, --request-url, --jwks-url, ...)
alt token-file provided
CLI->>FS: Read token file
FS-->>CLI: token bytes
CLI->>JWT: ParseUnverified(token)
JWT-->>CLI: token claims
else token-file not provided
CLI->>HTTP: Request token (request-values)
HTTP-->>CLI: token response
CLI->>JWT: ParseUnverified(token)
JWT-->>CLI: token claims
end
alt jwks-url provided
CLI->>JWKS: Fetch/parse JWKS
JWKS-->>CLI: keys
CLI->>JWT: Parse/Validate with JWKS
JWT-->>CLI: validated token
end
CLI->>CLI: print token info
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
cmd/jwtinfo.go (1)
54-70: Address linter whitespace violations.Static analysis flags several whitespace issues in this block (wsl_v5 rules). Adding blank lines before declarations and returns improves readability and satisfies the linter.
Proposed formatting fix
Run: func(cmd *cobra.Command, args []string) { // TODO: display version and exit // TODO: remove global --config option - var err error + var tokenData jwtinfo.JwtTokenData if tokenFile != "" { tokenData, err = jwtinfo.ReadTokenFromFile(tokenFile) if err != nil { fmt.Printf( "error while reading token value from file: %s", err, ) + return } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@cmd/jwtinfo.go` around lines 54 - 70, The Run function's block has linter whitespace (wsl_v5) violations around declarations and the early return; in the Run func (the anonymous Run handler) add a blank line before the local declarations (var err error, var tokenData jwtinfo.JwtTokenData) and add a blank line before the return inside the tokenFile error branch (the branch that calls jwtinfo.ReadTokenFromFile), so spacing separates declarations and control flow for readability and to satisfy the linter.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/jwtinfo.go`:
- Around line 61-114: The code currently reads tokenData from
jwtinfo.ReadTokenFromFile when tokenFile is set and then always attempts
jwtinfo.RequestToken when requestURL is set, allowing the HTTP result to
overwrite the file result; change the control flow so the sources are mutually
exclusive (either return an error if both tokenFile and requestURL are provided,
or use an else-if to prioritize one source), updating the logic around the
tokenFile/requestURL checks and the tokenData assignment (symbols: tokenFile,
requestURL, tokenData, jwtinfo.ReadTokenFromFile, jwtinfo.RequestToken) and
ensure the CLI prints a clear error or usage message when both flags are
supplied.
In `@internal/jwtinfo/jwtinfo.go`:
- Around line 129-149: ReadTokenFromFile should trim whitespace from the file
contents before storing into JwtTokenData.AccessTokenRaw to avoid downstream
base64 decode failures (see DecodeBase64 which splits AccessTokenRaw on "."), so
call strings.TrimSpace on the read data when constructing td; also fix the error
message returned on read failure to say "unable to read token file" instead of
the copy-pasted text, and return the token with a nil error (return td, nil) on
success.
---
Nitpick comments:
In `@cmd/jwtinfo.go`:
- Around line 54-70: The Run function's block has linter whitespace (wsl_v5)
violations around declarations and the early return; in the Run func (the
anonymous Run handler) add a blank line before the local declarations (var err
error, var tokenData jwtinfo.JwtTokenData) and add a blank line before the
return inside the tokenFile error branch (the branch that calls
jwtinfo.ReadTokenFromFile), so spacing separates declarations and control flow
for readability and to satisfy the linter.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 77f12bd4-97dc-431d-9843-6ac37155771e
📒 Files selected for processing (2)
cmd/jwtinfo.gointernal/jwtinfo/jwtinfo.go
Summary by CodeRabbit
New Features
Improvements