Refactor NewCliSession for improved keyring configuration - #32
Conversation
…d improve configuration handling
WalkthroughReorders option application in NewCliSession: defines a defaultOpts slice and applies it before user-provided opts, ensuring user options override defaults. No exported signatures change; session assembly (config build, keyring open, session return) remains otherwise unchanged. Changes
Sequence Diagram(s)sequenceDiagram
participant C as Caller
participant CS as NewCliSession
participant Cfg as Config Builder
participant KR as Keyring
Note over CS: Order change: defaults → user opts
C->>CS: NewCliSession(opts...)
CS->>CS: Prepare defaultOpts (backends, trust, names, pw funcs, config dir)
CS->>Cfg: Apply defaultOpts
CS->>Cfg: Apply user opts (override defaults)
Cfg-->>CS: Built config
CS->>KR: Open keyring per config
KR-->>CS: Keyring handle
CS-->>C: CliSession
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
✨ Finishing Touches
🧪 Generate unit tests
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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
frameworks/cli/cliSession.go (4)
84-91: Compile error: ranging over an int.
chunksis an int;for i := range chunksdoesn’t compile. Iterate by index.- for i := range chunks { + for i := 0; i < chunks; i++ {
110-116: Same compile error in both cleanup loops.Replace
range chunkswith an indexed loop in both places.- for i := range chunks { + for i := 0; i < chunks; i++ {- for i := range chunks { + for i := 0; i < chunks; i++ {Also applies to: 132-138
141-151: Save-chunks loop: range over int and undefined min().
- Use indexed loop.
minisn’t a Go builtin; compute end explicitly.- for i := range chunks { - start := i * chunkSize - end := min(start+chunkSize, len(t)) + for i := 0; i < chunks; i++ { + start := i * chunkSize + end := start + chunkSize + if end > len(t) { + end = len(t) + }
16-18: Namespace keyring keys by service to avoid collisions across sessions.Keys like "kinde_code_verifier" and "kinde_token" aren’t scoped to serviceName; multiple sessions for different services can overwrite each other. Consider storing serviceName (normalized) in cliSession and prefixing keys with it (e.g., "kinde//token").
Happy to propose a small refactor that adds a service-scoped prefix field to cliSession and updates the Get/Set methods accordingly. Want me to draft it?
🧹 Nitpick comments (1)
frameworks/cli/cliSession.go (1)
155-161: fmt.Appendf portability.
fmt.Appendfrequires newer Go; if your module’s go version < 1.20/1.21, prefer strconv for portability.- countData := fmt.Appendf(nil, "%d", chunks) + countData := []byte(strconv.Itoa(chunks))Outside this hunk, add:
import "strconv"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
frameworks/cli/cliSession.go(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
frameworks/cli/cliSession.go (1)
frameworks/cli/options.go (8)
Option(5-5)WithAllowedBackends(8-12)WithKeychainTrustApplication(50-54)WithServiceName(22-26)WithKeychainName(29-33)WithKeychainPasswordFunc(36-40)WithFilePasswordFunc(43-47)WithFileDir(15-19)
🔇 Additional comments (1)
frameworks/cli/cliSession.go (1)
229-229: Option precedence LGTM.Prepending defaults then appending user opts makes user-provided options win. Good.
Enhance the NewCliSession function to utilize default options for keyring backends, streamlining configuration handling.