mirror of
https://github.com/larksuite/cli.git
synced 2026-09-14 18:42:53 +08:00
91d785f92f
* feat(envvars): add LARKSUITE_CLI_AGENT_NAME accessor 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. * refactor(envvars): consolidate agent env accessors, dedupe sanitize 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. --------- Co-authored-by: liangshuo-1 <266696938+liangshuo-1@users.noreply.github.com>
37 lines
616 B
Go
37 lines
616 B
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package envvars
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"unicode"
|
|
)
|
|
|
|
const (
|
|
agentNameMaxLen = 128
|
|
agentTraceMaxLen = 1024
|
|
)
|
|
|
|
func AgentName() string {
|
|
return sanitizeSingleLine(os.Getenv(CliAgentName), agentNameMaxLen)
|
|
}
|
|
|
|
func AgentTrace() string {
|
|
return sanitizeSingleLine(os.Getenv(CliAgentTrace), agentTraceMaxLen)
|
|
}
|
|
|
|
func sanitizeSingleLine(raw string, maxLen int) string {
|
|
v := strings.TrimSpace(raw)
|
|
if v == "" || len(v) > maxLen {
|
|
return ""
|
|
}
|
|
for _, r := range v {
|
|
if unicode.IsControl(r) {
|
|
return ""
|
|
}
|
|
}
|
|
return v
|
|
}
|