fix: normalize API token format in client
Accept tokens both with and without PVEAPIToken= prefix, since token files may contain the full Authorization header value. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
56fe551700
commit
2bdb508672
1 changed files with 7 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
|
@ -40,6 +41,11 @@ func NewClient(hosts []string, token string, tlsInsecure bool, maxConcurrent int
|
|||
TLSHandshakeTimeout: 5 * time.Second,
|
||||
}
|
||||
|
||||
// Normalize token: ensure it has the PVEAPIToken= prefix
|
||||
if !strings.HasPrefix(token, "PVEAPIToken=") {
|
||||
token = "PVEAPIToken=" + token
|
||||
}
|
||||
|
||||
return &Client{
|
||||
hosts: hosts,
|
||||
token: token,
|
||||
|
|
@ -78,7 +84,7 @@ func (c *Client) Get(path string) ([]byte, error) {
|
|||
lastErr = fmt.Errorf("creating request for %s: %w", url, err)
|
||||
continue
|
||||
}
|
||||
req.Header.Set("Authorization", "PVEAPIToken="+c.token)
|
||||
req.Header.Set("Authorization", c.token)
|
||||
|
||||
resp, err := c.httpClient.Do(req)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue