refactor(envvars): consolidate agent env value access - #1757
Conversation
envvars.AgentName() reads LARKSUITE_CLI_AGENT_NAME so business code can identify the agent driving the CLI. Value is sanitised (trim, reject control chars, 128-byte cap) and returns "" when unset or invalid. Local-only; not sent to the server.
Move agent-trace reading from cmdutil.AgentTraceValue into envvars.AgentTrace(), symmetric with AgentName and sharing one sanitizeSingleLine. secheader.go now only assembles headers (BaseSecurityHeaders calls envvars.AgentTrace()); the duplicated sanitize and its os/unicode imports are gone. The X-Agent-Trace header and its behaviour are unchanged.
📝 WalkthroughWalkthroughThis PR relocates agent-trace sanitization logic from ChangesEnv var sanitization relocation
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant BaseSecurityHeaders
participant envvars
Caller->>BaseSecurityHeaders: build headers
BaseSecurityHeaders->>envvars: AgentTrace()
envvars-->>BaseSecurityHeaders: sanitized value or ""
BaseSecurityHeaders-->>Caller: headers with HeaderAgentTrace (if non-empty)
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1757 +/- ##
=======================================
Coverage 74.42% 74.42%
=======================================
Files 854 855 +1
Lines 88457 88481 +24
=======================================
+ Hits 65832 65856 +24
+ Misses 17556 17555 -1
- Partials 5069 5070 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@f2b4bedb7badceb15b142e267d18ca7ec4b85ef9🧩 Skill updatenpx skills add larksuite/cli#feat/agent-name-env -y -g |
Tidy up how agent-related env values are read: the read + sanitize now live in one place (
internal/envvars), shared byAgentTraceand a newAgentNameaccessor.