mirror of
https://github.com/henrygd/beszel.git
synced 2026-09-21 08:57:48 +02:00
fix(agent): read TOKEN_FILE like KEY_FILE instead of sending the whole file (#2276)
This commit is contained in:
@@ -87,7 +87,27 @@ func getToken() (string, error) {
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return strings.TrimSpace(string(tokenBytes)), nil
|
||||
return parseTokenFile(string(tokenBytes), tokenFile)
|
||||
}
|
||||
|
||||
// parseTokenFile reads a single token from TOKEN_FILE.
|
||||
// Blank lines and comments are ignored. Multiple tokens are rejected because
|
||||
// the agent supports only one outbound hub connection.
|
||||
func parseTokenFile(contents, path string) (string, error) {
|
||||
var token string
|
||||
for line := range strings.Lines(contents) {
|
||||
line = strings.TrimSpace(line)
|
||||
if len(line) == 0 || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
if token != "" {
|
||||
return "", fmt.Errorf("%s must contain a single token", path)
|
||||
}
|
||||
token = line
|
||||
}
|
||||
// An empty file keeps returning an empty token, as before: the caller decides
|
||||
// what to do about it.
|
||||
return token, nil
|
||||
}
|
||||
|
||||
// getOptions returns the WebSocket client options, creating them if necessary.
|
||||
|
||||
Reference in New Issue
Block a user